我正在尝试使用Selenium 3.0.0和Jenkins上的Firefox 48.0.2版本(操作系统:Linux,64位),适用于Linux版本0.11.1的Gecko驱动程序进行selenium测试,它会引发以下异常:
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@1fdfafd2, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@1fdfafd2, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'host', ip: 'ip', os.name: 'Linux', os.arch: 'amd64', os.version: '3.11.0-20-generic', java.version: '1.8.0_60'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:259)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:247)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:242)
at selenium.utils.Browser.initForJenkinsJob(Browser.java:53)
这些是我用来初始化浏览器的设置:
File pathToLinuxGecko = new File("src/main/resources/geckoDriverLinux/geckodriver");
System.setProperty("webdriver.gecko.driver",pathToLinuxGecko.getPath());
File pathToBinary = new File(pathToFireFoxOnJenkinsServer);
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
DesiredCapabilities capabilities= DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(ffBinary,profile,capabilities);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
我在Windows上使用这些配置进行了本地尝试,并且它正在运行:
File pathToWindowsGecko = new File("src\\main\\resources\\geckoDriverWindows\\geckodriver.exe");
System.setProperty("webdriver.gecko.driver", pathToWindowsGecko.getPath());
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);