为selenium webdriver测试集成Jenkins和phantomjs
我正在将jenkins与phantomjs集成以运行我的selenium测试脚本。Phantomjs安装在我的jenkins服务器中,ghost驱动程序在端口8090中运行。但是,我的测试仍然被跳过,它会抛出一个异常 驱动程序可执行文件的路径必须由 phantomjs.binary.path能力/系统属性/路径变量;对于 有关详细信息,请参阅。这个 最新版本可从 " 我的詹金斯在centos跑步 我的代码如下所示为selenium webdriver测试集成Jenkins和phantomjs,jenkins,selenium-webdriver,phantomjs,ghostdriver,Jenkins,Selenium Webdriver,Phantomjs,Ghostdriver,我正在将jenkins与phantomjs集成以运行我的selenium测试脚本。Phantomjs安装在我的jenkins服务器中,ghost驱动程序在端口8090中运行。但是,我的测试仍然被跳过,它会抛出一个异常 驱动程序可执行文件的路径必须由 phantomjs.binary.path能力/系统属性/路径变量;对于 有关详细信息,请参阅。这个 最新版本可从 " 我的詹金斯在centos跑步 我的代码如下所示 @BeforeClass public void setUp() throws
@BeforeClass
public void setUp() throws Exception {
dCaps = new DesiredCapabilities();
driver = new PhantomJSDriver(dCaps);
baseUrl = "";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
驱动程序可执行文件的路径必须由
phantomjs.binary.path能力/系统属性/路径变量
您应该明确指出您将phantomJm exe放置在应该执行测试的机器上的位置。因此,我找到了两种解决方法:
1) 可能性#1(在代码中明确指出)
2) 可能性#2,使用
pom.xml依赖项:
<!--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>
希望这对您有所帮助我也很难做到这一点,我已经在Linux上构建了Jenkins,并希望使用该安装。使用系统属性不起作用(对于服务,甚至Jenkins中的全局Maven属性) 我不喜欢上面的编程方法,因为这将解决方案与特定于平台的配置捆绑在一起 最后,把它放进POM中是有效的
org.apache.maven.plugins
那么设置PhantomJS二进制文件路径的代码在哪里呢?Tim,现在我在CI环境中添加了一个名为env inject的插件,并将PhantomJS二进制文件路径插入其中。现在它对我来说运行良好。谢谢你的关注Tim。。
<!--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>
import net.anthavio.phanbedder.Phanbedder;
@BeforeClass
public void seleniumGrridUponGhostDriver() throws MalformedURLException {
File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability("takesScreenshot", true);
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//page instances init()
loginPage = PageFactory.initElements(driver, LoginPage.class);
homePage = PageFactory.initElements(driver, FacebookUserPage.class);
}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<phantomjs.binary.path>/usr/local/phantomjs/bin/phantomjs</phantomjs.binary.path>
</systemProperties>
</configuration>
</plugin>