1
如何在junit中將遠程phantomjs驅動器配置爲硒?我一直在試圖找到一個教程,但沒有運氣。我的目標是在我的單頁應用程序中使用它在spring mvc中進行測試。Junit中的遠程PhantomJS驅動程序
如何在junit中將遠程phantomjs驅動器配置爲硒?我一直在試圖找到一個教程,但沒有運氣。我的目標是在我的單頁應用程序中使用它在spring mvc中進行測試。Junit中的遠程PhantomJS驅動程序
經過一些試驗和錯誤,我已經達到了以下解決方案。此配置用於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控制器中使用的? –
不確定你的意思。這使我可以調用外部(phantomjs)測試驅動程序,並對我在春季製作的Web應用程序進行功能測試。我認爲,如何使用Node.js或Ruby與測試框架(如水豚)更好地實現這一點。在練習中我學到了通過JUnit運行phantomjs槽可以非常有效。做測試需要更長時間。 –
你能否看看我提出的這個問題:http://stackoverflow.com/questions/21949689/phantomjs-to-screenshot-website-div-for-spring-mvc-tomcat-and-itext-use?lq=1 ?我想做我的網頁的屏幕截圖,PhantomJS被Java視爲視圖。我同意,它需要更長的時間做:( –