DesiredCapabilities 'Chrome' > doesn't work with 'Selenium Grid.
I have a hub setup correctly and a node
however when trying to point Chrome browser to one of the nodes it doesn't work.
Current code:
case "chrome":
if (null == webdriver) {
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY);
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("55.0.2883.87 m");
capability.setPlatform(Platform.WINDOWS);
webdriver = new RemoteWebDriver(new URL("http://172.16.1.48:5555/wd/hub"),capability);
}
break;
Exception:
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=55.0.2883.87 m, platform=WINDOWS}], required capabilities = Capabilities [{}]
Couple of things :
On the node side, please ensure that the chromedriver (for chrome browser), geckodriver(for firefox browser) and IEDriverServer(for IE) are all available in the PATH variable and can be invoked by just opening up a command prompt and typing their names.
When you do DesiredCapabilities capability = DesiredCapabilities.chrome(); it automatically sets the browser name appropriately. So you don't need to set it again via capability.setBrowserName("chrome"); (So you can remove it off).
Unless and until you have explicitly set a browser version at your node level via the nodeConfig json file, please remove capability.setVersion("55.0.2883.87 m"); because this causes your test to ask for a node that can support chrome 55 version, but if you don't specify the same versioning at your node, your grid will turn down your new session request stating it cannot find the required desired capabilities.
Going by your screenshot it looks like your hub is running on localhost listening to the port 4444 but your code shows as if you are trying to connect to the node directly. So please change webdriver = new RemoteWebDriver(new URL("http://172.16.1.48:5555/wd/hub"),capability); to `webdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);
Once you have taken care of these items, your issue should get fixed.
Related
Hi i am trying to connect to remote webdriver on browserstack using Selenium but whenever the page loads in Chrome and Firefox i get a security message (see images below).
my URL is starting with https:// (when i manually open the browser i have to accept the certificates and continue before the webpage loads)
i have added this line to my code but it does not seem to make any difference:
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, "true");
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
NOTE: This issue only occurs then the tests are run on the GoCD pipeline. when running on intellij it all works fine
error:
org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=nssFailure2&u=https%3A//transport....
in chrome i see this:
and in firefox i get a similar message:
Can you try adding something as below and test:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("ignore-certificate-errors");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
options.addArguments("--test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-gpu");
chromeOptions.AddArguments("window-size=1980,1080");
Driver = new ChromeDriver(chromeOptions);
i have found the problem for anyones future reference.
This is because DNS requests were not forwarded for our host name on GocD.
I am getting the below WebDriver exception when trying to navigate to a URL (just simply to Google) using Selenium Grid running locally.
org.openqa.selenium.WebDriverException: Session [null] not available
and is not among the last 1000 terminated sessions.
I am running selenium-server-standalone-3.141.59.jar on my desktop in the Grid configuration with one hub and one node. In two different cmd windows I start the hub with -role hub, and then the node with -role node -hub http://localhost:4444/grid/register. All seems to start just fine.
Java code:
public void initialGridTest() throws Exception {
try {
System.setProperty("webdriver.chrome.driver", "D:\\SeleniumWebDrivers\\chromedriver.exe");
DesiredCapabilities capability = DesiredCapabilities.chrome();
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.get("http://www.google.com");
String doodleText = driver.findElement(By.id("logo-doodle-image")).getText();
} catch (Exception e) {
System.out.println("e: " + e);
}
}
I have a simple test in a Java class running in IntelliJ that calls RemoteWebDriver to navigate to Google. When I execute new RemoteWebDriver(... in the code, I see my Java program connecting to the hub and the hub connecting with the node, and the node opens a new instance of Chrome. But when the program runs driver.get() I get the WebDriverException. I see in the node console that it has a session id, but for some reason the session is null in my Java code.
This error message...
org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.
...implies that the Selenium Grid Node was unable to communicate with the Selenium Grid Hub.
As per the following discussions:
Session [url] not available and is not among the last 1000 terminated sessions. How to solve this?
Selenium: Session externalKey not available
It seems this error stems out when:
Selenium Grid Hub, Selenium Grid Node and the Client Process are initiated/spawned from different versions of Selenium client.
Solution
Ensure that Selenium Grid Hub, Selenium Grid Node and the Client Process all of them uses the same version of Selenium client i.e. Selenium v3.141.59
Error in opening new driver window:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
server log:
Forwarding newSession on session null to remote
I am running following code on linux:
driver= new RemoteWebDriver((new URL( "http://"+ip+":5555/wd/hub")), capability);
My hub-node already up and running. Then why i am getting this error.
This error message...
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
and the server log...
Forwarding newSession on session null to remote
...implies that the Selenium Grid Hub / Selenium Grid Node wasn't properly initiated/started. As a result a null session was forwarded to the RemoteWebDriver.
Some more information regarding the versions of the binaries which you have used interms of Selenium server/client, WebDriver variant /version and WebBrowser variant /version and the commands you have used to initiate the Selenium Grid Hub / Selenium Grid Node would have helped us to debug your issue in a easier way.
However this issue can happen due to multiple factors as follows:
You are using the uri 5555/wd/hub, so ensure that Selenium Grid Hub is initiated on port 5555.
You may opt to replace the capability argument with an instance of Options class as follows:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "chrome");
//seting the required capabilities
ChromeOptions options = new ChromeOptions();
options.merge(caps);
WebDriver driver = new RemoteWebDriver((new URL( "http://"+ip+":5555/wd/hub")), options);
You can find a relevant discussion in Remote WebDriver UnreachableBrowserException: Could not start a new session
This issue is frequently observed with GeckoDriver/Selenium/Mozilla due to version mismatch of the binaries you are using. As a thumb rule always follow the configuration matrix from the GeckoDriver, Selenium and Firefox Browser compatibility chart
You can find a relevant discussion in WebDriverException: Message: newSession with GeckoDriver Firefox v65 and Selenium through Python 3.7
I need to start Firefox / Chrome using remote webdriver with a specific browser language. I know how to do it while running locally. But is it possible to start a remote webdriver with specifying browser language.
This is how object creation done is RemoteWebDriver,
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), DesiredCapabilities.firefox());
Profiller is the key here,
var fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-au");
desiredCap.SetCapability(FirefoxDriver.ProfileCapabilityName,fp.ToBase64String());
your code seems specific to chrome so you can use this, I hope this might help you,
var options = new ChromeOptions();
options.AddArgument("--lang=zh"); // this sets US english
desiredCap.SetCapability(ChromeOptions.Capability, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), desiredCap.chrome());
Possible duplicate of How to set Browser Language using RemoteWebDriver
From what I understand so far, Chrome Driver always starts without any stored browser cookies.
I need the driver start with all the cookies stored by Chrome.
I wonder if there is any way to start the driver with the cookies that are already stored? I'm using C# with .net 4.5.
Yes we can do it by invoking saved chrome profile just like firefox profile. below are steps i noted when i am doing bit back ago
in Java, we can do it by using ChromeOptions and Chrome Profile. In chrome navigate to chrome://version/ It will display profile path and Executable path.
As per my working on this, The profile path is \Local\Google\Chrome\User Data\Profile 3 This is displaying what is displayed when i navigate to chrome://version/ in normal chrome browser. In this profile, i navigated to stackoverflow and saved credentials. So used below code
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\poi-3.12\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
//WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com/");
As per my understanding, i excepted stackoverflow.com page displayed as logged in. but for first time, i am not logged in. so cross checked with chrome://version/ in chrome opened by driver, profile path is displayed as
\Local\Google\Chrome\User Data\Profile 3\Default . then logged manually in that profile it self, which is opened by webdriver and executed gain by closing it.
Finally, page is displayed as logged in. So it may be in java, i hope it will helps you to try in C# .