如何在 junit 中使用远程 phantomjs 驱动器配置 selenium?我一直在尝试寻找这方面的教程,但没有成功。我的目标是使用它在 spring mvc 中对我的单页应用程序进行测试。
最佳答案
经过一番尝试和错误,我得到了以下解决方案。该配置用于Junit测试类
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();
}
如果您需要更多信息,请在下面评论。
关于java - Junit 中的远程 PhantomJS 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16794721/