如何在 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();
}
如果您需要更多信息,请在下面评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)