2

I'm using Selenium-serenity for my integration test. By default selenium integrate FirefoxDriver for the WebDriver, but now what I'm trying to do is use PhantomJS. I could not find so far how to set the driver properly after being initialized.

So far what I did is override the getDriver() method of pageObject and return the phantomJs webDriver

private static WebDriver webDriver;

@Override
public WebDriver getDriver() {
    if (webDriver == null) {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setJavascriptEnabled(true);
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/Users/pabloperezgarcia/Downloads/phantomjs");
        webDriver = new PhantomJSDriver(caps);
        setDriver(webDriver);
    }
    return webDriver;
}

But the problem is that every single action over webdriver is not propagate over the other pages because of course we are only returning the singleton webDriver, but not the super.getDriver().

My question is how can I set properly the webdriver on serenity to be share the state between multiple pages object, which are new instances.

With Firefox seems work perfectly.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
paul
  • 12,873
  • 23
  • 91
  • 153
  • How do you manage your properties? Have you tried passing phantomjs as the value for the webdriver.driver property? Do you run your tests locally or remotely? – user2272115 Nov 17 '15 at 19:03
  • Using Serenity with the default webDriver(Firefox) I did not create any property file, just annotation on my code and everything was working fine – paul Nov 17 '15 at 20:09

1 Answers1

3

You need to set the webdriver.driver property to phantomjs. With serenity this can be passed via command line, defined in a properties file, or annotated in the code. You may also need to specify the location of the phantomjs driver via a system property -Dphantomjs.binary.path=path/to/driver.

You mentioned you're using annotations, have you tried @Managed(driver="phantomjs")?

You could also pass via command line (in your IDE it would be in run configuration) -Dwebdriver.driver=phantomjs

Be aware if you are running your tests remotely you may also need to set the phantomjs.webdriver property to the port you want to run on.

You can also set properties via maven:

<properties>
    <webdriver.driver>phantomjs</webdriver.driver>
</properties>

and then in your failsafe plugin define the system property

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>                  
    <version>2.18</version>
    <configuration>
        <systemProperties>
            <webdriver.driver>${webdriver.driver}</webdriver.driver> 
        </systemProperties>
    </configuration>
</plugin>

If you want to define a custom driver provider, you need to make sure you implement DriverSource and define the following properties webdriver.driver, webdriver.provided.type, webdriver.provided.mydriver, thucydides.driver.capabilities

Serenity documentation: http://thucydides.info/docs/serenity-staging/

user2272115
  • 986
  • 1
  • 10
  • 22
  • Any reference where I can see how configure serenity to use the property file?. Right now I´m just running the test by failsafe of Maven and also through my IDE. Also where shall I put this annotation? @Managed(driver="phantomjs") in the Steps class? – paul Nov 17 '15 at 20:45
  • I updated my answer to address your questions. What IDE are you using? – user2272115 Nov 17 '15 at 21:20
  • Yeah if you go to Run > Edit Configurations and paste `-Dwebdriver.driver=phantomjs` into the field for VM options that should work also (leave the -ea there). – user2272115 Nov 17 '15 at 21:24
  • no working, still getting firefox webdriver, I dont see how you point to use phantomJSDriver, if you see my question I had to create the WebDriver of PhantomJS pointing to the phantomjs file that I download from the phantomjs page. – paul Nov 17 '15 at 21:30
  • @paul post an example test – user2272115 Nov 17 '15 at 21:44
  • It´s weird, I manage to make it works for command line. But I cannot make it works by Jenkins, I achieve to using phantomjs plugin to download the binaries, but I cannot force serenity to use phantomjs webdriver. Still using the default(firefox) – paul Nov 18 '15 at 10:44
  • @paul ask another question and provide information about how you use Jenkins – user2272115 Nov 18 '15 at 15:50
  • no worries finally I did specifying on the pom file – paul Nov 19 '15 at 14:41
  • In SerenityBDD `1.0.47` you can just specify `phantomjs.binary.path=/path/to/phantomjs/executable` in **serenity.properties** file. – flaz14 Mar 04 '18 at 12:09