如何更改Firefox WebDriver端口

3

我只是好奇如何在不同端口上运行Firefox驱动程序,就像IE和Chrome驱动程序一样。这个驱动程序有以下选项:

ChromeDriverService service=new ChromeDriverService.Builder().usingPort(7000).
                                            usingDriverExecutable(new File("")).build();

虽然Firefox驱动程序具有这样的选项,但需要注意的是:
System.setProperty("webdriver.firefox.port","7046");

或者

DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("webdriver_firefox_port",7046);

但是它无法在我使用的2.41 Selenium Webdriver和firefox 31版本上运行Firefox驱动程序。

有人能解释一下为什么吗?以及如何在指定端口上运行Firefox驱动程序。

1个回答

2

好的,不确定,但这应该可以工作


(注:保留HTML标签)
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("WebDriver");
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, 7046)
WebDriver driver = new FirefoxDriver(profile);

感谢您的评论......我以前做过这个,但它没有起作用,但是我使用了默认配置文件"user"......默认配置文件。 - saba
我创建了一个新的配置文件后也尝试了这个方法,但是结果仍然相同。它在默认端口7055上运行而不是7046。 - saba
3
非常有趣,但是如果只使用简单的FirefoxProfile而不是getProfile,例如FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("webdriver.firefox.port", 7046); WebDriver driver = new FirefoxDriver(profile);。我从未遇到过这样的问题=),很有趣,如何解决它。 - Andrey Egorov
我也这样做,但无法访问定义的端口.....你能帮我解决这个问题吗? - saba
我会尝试帮忙。1. 为什么要更改您的 Firefox 端口?这可能是不必要的吗?2. 主要的测试过程是什么(您是否使用 Selenium Grid,或者只是从代码运行测试)?与测试/目的相关的任何其他描述都将有所帮助。 - Andrey Egorov
没有,这与任何测试或其他事情都无关,只是出于好奇我问这个问题。 - saba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接