0

actually I am struggling when trying to change default webdriver for serenity. actually I want to run my test on selenium grid. then I add the following code on class that extends PageObject :

    DesiredCapabilities cap = DesiredCapabilities.firefox();
    cap.setPlatform(Platform.WINDOWS);
    cap.setCapability("marionette",false);
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile ffprofile = profile.
            getProfile("JbehaveProfile");
    cap.setCapability(FirefoxDriver.PROFILE, ffprofile);
    //cap.setVersion("46.0.1");
    URL url = new URL("http://localhost:4444/wd/hub");
    WebDriver driver = new RemoteWebDriver(url,cap);
    Serenity.getWebdriverManager().registerDriver(driver);
    Serenity.getWebdriverManager().setCurrentDriver(driver);

but it is not working. it giving error null pointer exception. please someone give me advice how to set up selenium grid on Serenity? thanks.

java.lang.NullPointerException
at testSeleniumGrid.pages.DictionaryPage.setProfileFirefox(DictionaryPage.java:70)
at testSeleniumGrid.steps.serenity.EndUserSteps.is_the_home_page(EndUserSteps.java:35)
at testSeleniumGrid.steps.serenity.EndUserSteps$$EnhancerByCGLIB$$6d97ef9c.CGLIB$is_the_home_page$3(<generated>)
at testSeleniumGrid.steps.serenity.EndUserSteps$$EnhancerByCGLIB$$6d97ef9c$$FastClassByCGLIB$$53eb4f32.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:348)
at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:333)
at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:308)
at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:130)
at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:57)
at testSeleniumGrid.steps.serenity.EndUserSteps$$EnhancerByCGLIB$$6d97ef9c.is_the_home_page(<generated>)
at testSeleniumGrid.steps.DefinitionSteps.givenTheUserIsOnTheWikionaryHomePage(DefinitionSteps.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jbehave.core.steps.StepCreator$ParametrisedStep.perform(StepCreator.java:595)
at org.jbehave.core.embedder.StoryRunner$FineSoFar.run(StoryRunner.java:566)
at org.jbehave.core.embedder.StoryRunner.runStepsWhileKeepingState(StoryRunner.java:546)
at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:510)
at org.jbehave.core.embedder.StoryRunner.runStepsWithLifecycle(StoryRunner.java:476)
at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:336)
at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:239)
at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:182)
at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:266)
at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:233)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Hendrione
  • 225
  • 1
  • 5
  • 18
  • Can you please share the complete stack trace ? – Krishnan Mahadevan Nov 01 '16 at 02:47
  • done add stack trace – Hendrione Nov 01 '16 at 08:01
  • @KrishnanMahadevan – Hendrione Nov 01 '16 at 08:02
  • I think it would be good if you could please share all the involved code as well. The stack trace seems to indicate that the source of NPE is in your test code. – Krishnan Mahadevan Nov 01 '16 at 12:49
  • @KrishnanMahadevan. ok I will simplify my question. how to change default selenium driver on Serenity Jbehave? Actually I try to use this archetype : [link_maven_repo](https://mvnrepository.com/artifact/net.serenity-bdd/serenity-jbehave-archetype). then it will create a sample project. it have default browser firefox to run the test. how if I need to change it using **htmlUnitDriver** or **selenium grid** or **chrome**. how to change the default browser? – Hendrione Nov 02 '16 at 02:48
  • If all you want is to toggle between browser flavors.. have you looked at this link : http://thucydides.info/docs/thucydides/_running_thucydides_in_different_browsers.html In short, if you pass -Dwebdriver.driver=chrome your tests run in chrome. FWIW I ran mvn archetype:generate, Chose 774 (net.thucydides:thucydides-easyb-archetype) as archetype and then Chose 31 (0.9.268) to generate a sample project. Is that what u are doing ? – Krishnan Mahadevan Nov 02 '16 at 04:10
  • @KrishnanMahadevan : thank you. I already try it and it is working. I already try using chromedriver. but, how if I need to run serenity jbehave test on selenium grid. it used **RemoteWebDriver**. IDK how to set up that. for your question : yes true I do that thing. – Hendrione Nov 02 '16 at 07:11
  • I have consolidated all the information that you are looking for (now that your question is clear for me) as an answer. Please take a look and accept it if it answers your question. – Krishnan Mahadevan Nov 02 '16 at 09:06

1 Answers1

2

If you are working in a local mode i.e., not using the Grid, for you to be able to switch browsers you merely pass the browser flavor via the JVM argument -Dwebdriver.driver=chrome. Please make sure that you have corresponding driver binaries [IEDriverServer.exe (for Internet explorer), ChromeDriver.exe (for Chrome) and Geckodriver.exe (for newer versions of Firefox and if using Selenium 3.0.1 )

If you are making use of a Selenium Grid wherein the Grid Node (Not the Grid Hub) runs on a different machine i.e., lets say you are kicking off your Serenity tests from MachineA and your Grid node is running on MachineC, please ensure that you have added the location of the IEDriverServer/ChromeDriver/GeckoDriver binaries in to your PATH environment variable of MachineC (i.e., the machine on which your Selenium node is running).

More instructions with respect to setting up the binary and working with it.

In order for you to be able to use Serenity and point it to a Grid you would need to use the JVM argument -Dwebdriver.remote.url=http://GridIp:GridPort/wd/hub

If you are looking for some general instructions on how to setup the Selenium Grid and work with it please refer to the below links :

All the arguments for Serenity are found in ThucydidesSystemProperty.java. The translation logic seems to be change the enum to lower case, replace all - with a .

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66