4

我想以編程方式創建一個臨時的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上創建配置文件並在啓動腳本中指定配置文件來選擇配置文件。但是,這不是我正在尋找的功能。

任何幫助將不勝感激!謝謝!

+0

爲什麼你認爲它應該將你的配置文件轉移到網格? –

回答

1

錯誤轉發新的會話找不到:能力[{browserName =火狐,版本=,平臺= ANY,

這基本上是告訴你,你所要求的電網分配的網格的方式一個可以運行firefox的節點(不管平臺風格或版本號),但是網格沒有任何可用的節點(在您的節點配置JSON文件中,您已指定關鍵的firefox_profile的值應爲「Selenium」

「firefox_profile」:「selenium」

不確定爲什麼要在您的JSON配置文件中設置此密鑰。

我明白,例外情況是說它無法在硒服務器上找到匹配的功能設置。但是,它應該轉移配置文件,而不是尋找匹配的配置文件。

只有當網格發現一個與請求能力匹配的節點時,網格纔會這樣做。在你的情況下,網格無法找到任何與你請求的節點相匹配的節點,因此配置文件將不會被傳輸(因爲此時目的地未知)。

因此,您需要從node_config JSON文件中刪除關鍵字「firefox_profile」以使其工作。然後,firefox配置文件將被轉發到該問題的特定節點,並且您的執行將使用您創建的firefox配置文件開始。

相關問題