问题
How do i configure selenium with a remote phantomjs drive in junit? I have been trying to find a tutorial for this but had no luck. My goal is to use this for testing in spring mvc for my single page application.
回答1:
After some trial and error I have 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 further information comment below.
来源:https://stackoverflow.com/questions/16794721/remote-phantomjs-driver-in-junit