PhantomJS Remote Driver in Junit

How to configure selenium with phantomjs remote drive in junit? I tried to find a tutorial for this, but no luck. My goal is to use this for testing in spring mvc for my one page application.

+1
source share
1 answer

After some trial and error, I reached the following solution. This configuration is used in the Junit test class.

private URI siteBase;
private static PhantomJSDriverService service;
private WebDriver driver;
protected static DesiredCapabilities dCaps;

@BeforeClass
public static void createAndStartService() throws IOException  {
    service = new PhantomJSDriverService.Builder().usingPhantomJSExecutable(new File("/path/to/phantom/driver"))
            .usingAnyFreePort()
            .build();
    service.start();
}
@AfterClass
public static void stopService() throws IOException  {
    service.stop();
}

@Before
public void setUp() throws Exception {
      siteBase = new URI("http://localhost:8080/");
      dCaps = new DesiredCapabilities();
      dCaps.setJavascriptEnabled(true);
      dCaps.setCapability("takesScreenshot", false);

      driver = new RemoteWebDriver(service.getUrl(),dCaps);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@After
public void tearDown() throws Exception {
    driver.quit();
}

If you need the following informative comment below.

+2
source

Source: https://habr.com/ru/post/1528233/


All Articles