简体   繁体   中英

Using FireFoxProfile with RemoteWebDriver, Selenium Grid2, causes Capabilities Exception

I am trying to programmatically create a temporary firefox profile for use in selenium tests with selenium grid2.

Here is the code that I am currently running.

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);

This code will run if the all the lines regarding the profile are commented out. However, as is, it will cause this exception.

Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{browserName=firefox, version=, platform=ANY, firefox_profile=UEsDBBQACAgIAFxzBEkAAAAAAAAAA...}]

I understand that the exception is saying that it can't find a matching capabilities setup on the selenium server. However, it should be transferring the profile, not looking for a matching one. And the string following "firefox_profile=" is the output of "profile.toJson()" so it seems like it is doing things correctly to some extent. I just cannot figure out why the server won't accept it.

Here is my selenium server start script

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

And the node config file

{
"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": ""
    }
}

I have researched this a lot and haven't been able to find anything/anyone with a similar issue. I was able to select a profile by creating it directly on the vm and specifying it in the startup script. However, that is not the functionality I am looking for.

Any help would be greatly appreciated! Thank you!

Error forwarding the new session cannot find : Capabilities [{browserName=firefox, version=, platform=ANY,

This is basically the Grid's way of telling you that you requested the Grid to allocate a node which can run firefox (irrespective of the platform flavor or the version number), but the grid doesn't have any such node at its disposal (In your node configuration JSON file you have specified that the key firefox_profile should have a value of "Selenium".

"firefox_profile": "selenium"

Not sure why you would set this key in your JSON configuration file.

I understand that the exception is saying that it can't find a matching capabilities setup on the selenium server. However, it should be transferring the profile, not looking for a matching one.

The Grid will do it ONLY if it finds a node that matches the requested capabilities. In your case, the Grid is NOT able to find any node that matches whatever you are requesting for and hence the profile will not be transferred (because the destination is unknown at this point).

So you would need to get rid of the key "firefox_profile" from your node_config JSON file for this to work. Then the firefox profile will be forwarded to that particular node in question and your execution will begin using your created firefox profile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM