我想以編程方式創建一個臨時的firefox配置文件,以便在selenium測試中使用硒grid2。使用FireFoxProfile和RemoteWebDriver,Selenium Grid2導致功能異常
這是我目前正在運行的代碼。
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(PREFERENCE_NAME,userAgent.getUserAgentString());
capabilities.setCapability(FirefoxDriver.PROFILE,profile);
RemoteWebDriver driver = new RemoteWebDriver(url, capabilities);
如果關於配置文件的所有行都被註釋掉,則此代碼將運行。但是,現在會導致這種異常。
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{browserName=firefox, version=, platform=ANY, firefox_profile=UEsDBBQACAgIAFxzBEkAAAAAAAAAA...}]
我明白,例外情況是說它無法在硒服務器上找到匹配的功能設置。但是,它應該轉移配置文件,而不是尋找匹配的配置文件。而「firefox_profile =」後面的字符串是「profile.toJson()」的輸出,所以看起來它在某種程度上正確地做了正確的事情。我只是無法弄清楚爲什麼服務器不會接受它。
這裏是我的硒服務器啓動腳本
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6565 -cp selenium-server-standalone-2.53.0.jar org.openqa.grid.selenium.GridLauncher -role node -nodeConfig nodeconfig.json -hub http://192.168.5.151:4444/grid/register
和節點配置文件
{
"capabilities": [
{
"browserName": "firefox",
"nativeEvents": true,
"acceptSslCerts": true,
"javascriptEnabled": true,
"takesScreenshot": true,
"firefox_profile": "selenium",
"version": "44.0",
"platform": "WIN10",
"maxInstances": 1,
"firefox_binary": "C:\\Program Files\\Mozilla\ Firefox\\firefox.exe",
"cleanSession": true,
"file.download.supported": true,
"file.download.watcher": "WindowsFirefoxDownloadWatcher",
"file.download.directory": "C:\\Users\\IEUser\\Downloads"
},
{
"browserName": "chrome",
"nativeEvents": true,
"maxInstances": 1,
"platform": "WIN10",
"webdriver.chrome.driver": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
},
{
"browserName": "MicrosoftEdge",
"nativeEvents": true,
"maxInstances": 1,
"platform": "WIN10"
}
],
"configuration":
{
"_comment" : "Windows 10 with file download support",
"cleanUpCycle": 2000,
"timeout": 0,
"port": 5555,
"host": ip,
"register": true,
"hubPort": 4444,
"maxSessions": 1,
"Dwebdriver.edge.driver=C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe": ""
}
}
我研究這個了很多,一直沒能找到任何/任何人有類似問題。我能夠通過直接在vm上創建配置文件並在啓動腳本中指定配置文件來選擇配置文件。但是,這不是我正在尋找的功能。
任何幫助將不勝感激!謝謝!
爲什麼你認爲它應該將你的配置文件轉移到網格? –