- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将通过 BitBucket 分享我在 Selenium/Cucumber 框架中编写的代码。我使用以下方法使代码在 Firefox 中可执行。
System.setProperty("webdriver.gecko.driver","/Users/firatkaymaz/eclipse-workspace/SeleniumTest/drivers/geckodriver/geckodriver");
driver = new FirefoxDriver();
如何在另一台 PC 或笔记本电脑上运行代码,因为 Gecko 驱动程序路径信息与我的本地计算机相关?有没有办法让 gecko.driver 对于要在共享代码中运行的人可用,或者他们必须用自己的路径信息更改路径信息?
最佳答案
您有多种选择:
设置适当的环境变量
不要使用System.setProperty
来设置webdriver.gecko.driver
。这应该设置为机器上的环境变量,而不是代码中。这允许您在多个位置使用 gecko 驱动程序配置多台开发机器/构建盒。每台机器只需要设置环境变量webdriver.gecko.driver
以指向本地机器上的相关路径,它就会“正常工作”。
使用驱动程序二进制下载器maven插件
这将允许您的 Maven 项目自动下载关联的 RepositoryMap.xml 中指定的驱动程序二进制文件(显然需要您使用 Maven 进行构建/依赖管理)。如果您尚未定义,它将下载一组默认的二进制文件(但它们很可能已经过时)。了解更多详情See Here .
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.17</version>
<configuration>
<!-- root directory that downloaded driver binaries will be stored in -->
<rootStandaloneServerDirectory>/my/location/binaries</rootStandaloneServerDirectory>
<!-- Where you want to store downloaded zip files -->
<downloadedZipFileDirectory>/my/location/zips</downloadedZipFileDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
不幸的是,虽然这确实下载了二进制文件,但 Maven 不会在不同的 JVM 之间传递环境变量,它会在不同的阶段启动。因此,您需要将一些配置传递到测试配置中,例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<systemPropertyVariables>
<!--Set properties passed in by the driver binary downloader-->
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
<webdriver.edge.driver>${webdriver.edge.driver}</webdriver.edge.driver>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<!--This goal makes the build fail if you have test failures-->
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
See Here完整的工作示例。
使用 Webdriver 管理器
这将允许您使用 Java 代码下载和配置驱动程序二进制文件。您可以使用 versions.properties
文件指定特定版本:
public class ChromeTest {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.chromedriver().setup();
}
@Before
public void setupTest() {
driver = new ChromeDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
了解更多信息See Here .
关于java - 有没有办法让 gecko.driver 可供共享代码中的每个人使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56758747/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
Gecko 是 Firefox 的渲染引擎。使用 gecko-sharp 可以将它嵌入到任何 Mono/GTK# 程序中。有一个名为 GladeSharpBrowser 的示例应用程序为此。我可以设法
我正在寻找关于 Gecko 浏览器/Firefox 中是否有等同于 -webkit-mask 的可靠答案? 如果不是,是否有任何方法可以将 CSS 中的 -webkit-mask 降级为直接的背景图像
我在selenium Grid的帮助下运行基本的selenium代码。 以下是步骤: 第 1 步:- 下载最新版本的selenium Standalone 服务器 (3.4.0); 第 2 步:- 使
我使用 gecko 浏览器,我需要选择一个特定的列表框或组合框,但同一页面有多个列表框和组合框。我尝试了以下方法,但它适用于所有人。而且没有 ID 标签,只有名称标签。 GeckoElemen
这似乎是渲染引擎的一个怪癖,因为它已经过测试但无法在 WebKit 驱动的浏览器(Windows 的 Chrome 和 Safari)上重现。 描述 当使用深层嵌套的 DOM 结构时,例如 GXT G
今天我正在尝试优化我的网站,以便在 Firefox 中呈现更好的效果!我的问题是 text-shadow 和 font-weight 属性...我只想为 firefox 设置自定义值(我的网站只兼容
阅读后: Do not confuse the Gecko/XULRunner SDK with XULRunner itself. The Gecko SDK is a collection of
我遇到了 Actions 的问题类司机。我有这段代码 Actions act= new Actions(d1); act.moveToElement(d1.findElement(By.xpath("
问题: 当我使用 testNG 运行时,geckodriver.exe 未加载。 Firefox 将启动,但 selenium 无法连接到浏览器,并且出现错误: Unable to connect t
我希望能够用 Java 来控制 webkit/gecko/konqueror 浏览器。 Java 应该能够执行诸如“转到此 url;给我 DOM 树;模拟鼠标单击/键盘输入等”之类的操作。 最简单的方
编写一些 css hack,为 :hover {} 设计样式很有趣,但浏览器会处理 a:hover完整链接 VS 哈希标签不同。 来自 http://inqdrops.com/welcom/ a, a
当我开始最小的 Selenium 测试时,我得到了奇怪的日志(不确定是否是 Gecko Driver 的日志)。如何禁用这些日志如何解决这些问题? import org.openqa.selenium
帮助!我使用 GeckoFx-Windows-10.0-0.6 浏览器和 xulrunner-10.0.en-US.win32。 ( Visual Studio 2010 c# ) 一切正常。但我需要
我正在尝试仅使用 css 来屏蔽其中包含一些图像的元素。我已经做到了这一点,它在使用 -webkit-mask-box-image 的 webkit 中运行良好,它做的正是我想要的,但我在使用其他浏览
我有一个字符串,例如 Hello World!我想在不自己解析 HTML 的情况下获取#message 元素的内容。 我想也许我可以从 Gecko 中的字符串创建文档对象(这是用于 Firefox 附
我想通过每次使用列表中的下一个代理加载 X 页面来测试代理列表。 我正在使用 Gecko 网页浏览器 (GeckoFX),如何在网页浏览器控件执行时更改代理 IP:端口以使用其他代理打开网页? 最佳答
引用 nsICacheService ( https://developer.mozilla.org/en/NsICacheService ) 和 nsICacheVisitor ( https://
我将通过 BitBucket 分享我在 Selenium/Cucumber 框架中编写的代码。我使用以下方法使代码在 Firefox 中可执行。 System.setProperty("webdriv
我安装了 Gecko 驱动程序,因为我收到此错误:“java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属
我是一名优秀的程序员,十分优秀!