java - Junit 中的远程 PhantomJS 驱动程序

标签 java selenium junit phantomjs

如何在 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/

相关文章:

java - 按钮计数器未更新

Netcat 运行 Flink 示例的 Java 代码替代方案 SocketTextStreamWordCount

javascript - Protractor - 从 Bootstrap 下拉列表中选择

java - WebElement.clear() 触发 javascript 更改事件 - 替代方案?

c# - 如何在 Selenium 中查找页面上的多个元素?

java - Spring JUnit 测试未加载完整的应用程序上下文

java - 第一次写junit : Need suggestions

java - 关闭 HttpOnly Spring 启动

java - GWT 和身份验证

java - 如何让单元测试在 Maven Tycho 构建中运行?