我在 JUnit 中编写了一个测试来使用 Selenium 3.0.1 启动 Firefox。但我对 Firefox Portable 版本有疑问。在我的机器上安装了 Firefox,我没有这个问题。
我的测试很简单:
public class SeleniumTest extends FluentTest {
WebDriver webDriver = new FirefoxDriver();
static {
// 1) Work with native Firefox
System.setProperty("webdriver.gecko.driver", ClassLoader.getSystemResource("webdriver/geckodriver_0.11.1.exe").getFile());
// 2) Don't work when I add these 2 properties
// System.setProperty("webdriver.firefox.marionette", "true");
// System.setProperty("webdriver.firefox.bin", "D:\\firefox-portable\\FirefoxPortablex64-48.0.2\\FirefoxPortable.exe");
}
@Test
public void test() {
System.out.println("test is executed");
}
}
在第 2 种情况下,我添加了运行 Firefox 便携版所需的属性,但测试在“连接到 localhost:52702 上的 Marionette”步骤保持锁定。任何事情都会发生。
1478965841203 geckodriver INFO Listening on 127.0.0.1:45941
nov. 12, 2016 4:50:41 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFOS: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1478965841598 mozprofile::profile INFO Using profile path d:\Profiles\<username>\AppData\Local\Temp\rust_mozprofile.TisH4gXwlj3K
1478967041359 geckodriver::marionette INFO Starting browser D:\firefox-portable\FirefoxPortablex64-48.0.2\FirefoxPortable.exe
1478967041388 geckodriver::marionette INFO Connecting to Marionette on localhost:52702
但是使用本机 Firefox,我可以看到接下来的步骤并执行测试。
1478967281791 Marionette INFO Listening on port 53224
1478967283064 Marionette INFO startBrowser d3c2b382-5643-4149-9168-57fd36a43678
nov. 12, 2016 5:14:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFOS: Detected dialect: W3C
test is executed
最后,我希望使用 Firefox 便携版更加灵活和独立。
我的环境:Jdk 8 / Selenium 3.0.1 / FluentLenium 3.0.2 / GeckoDriver 0.11.1 / Native Firefox:49.0.2 / Firefox Portable edition:48.0.2 和 49.0
任何帮助将不胜感激。