Junit中的远程PhantomJS驱动程序 [英] Remote PhantomJS driver in Junit

查看:117
本文介绍了Junit中的远程PhantomJS驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在junit中使用远程phantomjs驱动器配置硒?我一直在尝试为此找到一个教程,但是没有运气.我的目标是在我的单页应用程序的spring mvc中使用它进行测试.

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.

推荐答案

经过反复试验,我得出了以下解决方案.此配置在Junit测试类中使用

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.

这篇关于Junit中的远程PhantomJS驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆