嗨我在eclipse中为java启动phantomjs时遇到以下错误 PhantomJS正在推出GhostDriver ......
我已经完成了以下步骤将phantomjs添加到eclipse:
下载phantomjs.exe
解压缩phantomjs-1.8.x-windows.zip文件夹并将phantomjs.exe文件定位到C:/ folder
用“PhantomJSDriver”替换指定“FirefoxDriver”的对象“driver”。
替换代码, WebDriver驱动程序=新的FirefoxDriver
DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(真); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,“C:/phantomjs.exe”); WebDriver driver = new PhantomJSDriver(caps);
运行测试。
请帮助!!
答案 0 :(得分:1)
为了使GhostDriver按照以下步骤正常工作:
PREREQUISITES
先决条件步骤1:
在您需要的所有内容下载后,下一步 - 启动selenium hub(selenium服务器)和selenium节点,它将连接到已启动的集线器,并将基于phantomJs。
LAUNCHING HUB AND NODES
硒中心启动
java -jar selenium-server-standalone-2.41.0.jar -role hub
启动集线器后 - 在浏览器中键入http://localhost:4444/grid/console
并在浏览器中输入>
http://gyazo.com/9435772d76044cf273d6b567584c0532
GhostDriver节点启动
phantomjs --webdriver = 8080 --webdriver-selenium-grid-hub = http:// l o c a l h o s t:4444
再次检查localhost / grid / console => http://gyazo.com/06fd2fc6d740c18e3d0925e180de150f
完成后,请进行以下setUp。
CODE SETUP
接近一个
我的项目是基于maven的,所以我建议您遵循PhantomJs跨平台解决方案
在POM.XML中添加以下内容
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.41.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.41.0</version>
</dependency>
<!--substituting phanbedder with local Phanbedder implementation-->
<dependency>
<groupId>net.anthavio</groupId>
<artifactId>phanbedder-1.9.7</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.1.0</version>
</dependency>
添加这些依赖项后,切换到测试类(例如SeleniumTest.java)
private WebDriver driver;
@BeforeClass
public void seleniumGrridUponGhostDriver() throws MalformedURLException {
File phantomjs = Phanbedder.unpack(); // cross platform solution. Maven will provide //appropriate phantomJs instance
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability("takesScreenshot", true);
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
// NOTE: as we launched node locally, that is why we pass
// 127.0.0.1 IP as parameter
this.driver = new RemoteWebDriver(new URL("http://127.0.0.1:8080"), dcaps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
}
@Test
public void myTest(){
driver.get("http://www.google.com");
.....
}
接近两个
在POM.xml中添加以下依赖项
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.41.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.41.0</version>
</dependency>
适当的代码setUP:
private WebDriver driver;
@BeforeClass
public void seleniumGrridUponGhostDriver() throws MalformedURLException {
File phantomjs = new File("C:\\Selenium\\phantomjs.exe");
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability("takesScreenshot", true);
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
this.driver = new RemoteWebDriver(new URL("http://127.0.0.1:8080"), dcaps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
}
@Test
public void myTest(){
driver.get("http://www.google.com");
.....
}
希望这适合你