Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Junit中的远程PhantomJS驱动程序_Java_Selenium_Junit_Phantomjs - Fatal编程技术网

Java Junit中的远程PhantomJS驱动程序

Java Junit中的远程PhantomJS驱动程序,java,selenium,junit,phantomjs,Java,Selenium,Junit,Phantomjs,如何在junit中使用远程phantomjs驱动器配置selenium?我一直试图找到一个教程,但没有运气。我的目标是使用它在SpringMVC中测试我的单页应用程序 经过反复试验,我得出了以下解决方案。此配置在Junit测试类中使用 private URI siteBase; private static PhantomJSDriverService service; private WebDriver driver; protected static DesiredCapabilities

如何在junit中使用远程phantomjs驱动器配置selenium?我一直试图找到一个教程,但没有运气。我的目标是使用它在SpringMVC中测试我的单页应用程序

经过反复试验,我得出了以下解决方案。此配置在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();
}

如果您需要更多信息,请在下面进行评论。

这在Spring MVC controller中是如何使用的?不确定您的确切意思。这使我能够调用外部(phantomjs)测试驱动程序,并对spring中的web应用程序进行功能测试。我认为使用Node.js或Ruby以及capybara等测试框架可以更好地实现这一点。在这个练习中,我了解到通过JUnit运行phantomjs是非常有效的。做测试需要更长的时间。你能看一下我做的这个问题吗?我想做我的网页截图,其中PhantomJS被Java激发到视图中。我同意,这样做需要更长的时间:(