Java Junit中的远程PhantomJS驱动程序
如何在junit中使用远程phantomjs驱动器配置selenium?我一直试图找到一个教程,但没有运气。我的目标是使用它在SpringMVC中测试我的单页应用程序 经过反复试验,我得出了以下解决方案。此配置在Junit测试类中使用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
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激发到视图中。我同意,这样做需要更长的时间:(