Understanding SeleniumGrid - selenium-webdriver

I have been trying to implement selenium grid being new to selenium2 .What i can't understand is do we actually need to have our node which we register with the hub have the configurations which we specify in our test.
By this I mean : say my machine which has windows on it,can I register it as node with the hub having configurations platform:LINUX,browserName:firefox or can I only register my machine as windows type?
I tried with Linux-firefox and my test passed also.But am not clear how can it run on a linux platform,if my machine was Windows
java -jar selenium-server-standalone-2.25.0.jar -role webdriver
-browser "browserName=firefox,platform=LINUX" -hub http://127.0.0.1:4444/grid/register

I currently have a Hub that is in Linux and several windows nodes and don't have an issue. When I register the HUB machine, I use the following code from the command prompt:
java -jar selenium-server-standalone-2.39.0.jar -role hub
Then, from each node machine, I run the a variant of the following code...depending on what configuration I want:
java -Dwebdriver.chrome.driver=c:\selenium\chromedriver.exe - Dwebdriver.iexplorer.driver=c:\selenium\IEDriverServer.exe -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://<YOURHUBSERVER>:4444/grid/register -port 6660 -browser browserName=firefox,maxInstances=0 -browser browserName=chrome,maxInstances=3 -browser browserName=iexplorer,maxInstances=0 -maxSessions=3
Just make sure the node computer has the jar file and all your paths are correct.
Once you do this, you will be able to see them in your Grid configuration.
Hope this helps.

Related

unable to Launch Selenium Script in Grid

i have started selenium server hub by running command :
java -jar selenium-server-standalone-3.4.jar -port 4444 -role hub
i have also connected node by running the command : java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser -browserName=firefox -port 5580
in grid console its showing v:null(don't know why?).
i am runing below code to run selenium :
public static void main(String[] args) throws MalformedURLException, InterruptedException{
String URL = "http://www.DemoQA.com";
String Node = "http://localhost:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WIN10);
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
Thread.sleep(5000);
driver.quit();
}
`
gettinf these errors, someone please help with these?.
many thanks in adc
Grid console shows no instance for Firefox is the issue you faced. There seems to be some issue with your node.
Check the node registration command.
java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser browserName=firefox,platform=WINDOWS,maxInstances=2
Try removing the - before browserName in the command.
The error message Error forwarding the new session cannot find is the Grid's way of telling you that whatever you requested for, the hub couldn't find any node that supports that capability.
In your case, when you did this
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WIN10);
You are basically telling the hub that you need a node that can support a browser with its name as firefox and the node should be running on a Windows 10 Operating system.
But in your node starting command, you used this
java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser -browserName=firefox -port 5580
which means you registered a node which supports firefox browsers, to the Hub, but you never mentioned anything about the platform. So the node assumes the platform to be "any".
Now when you created a new RemoteWebDriver instance, the Hub tried matching the requested capabilities with the available capabilities of every node. Since it didn't find any node that runs on Windows 10 and supports firefox (Remember you only have a node that supports firefox and whose platform is not set), the matching fails because "ANY" is not a match with "WIN10".
To fix the problem, please remove the line cap.setPlatform(Platform.WIN10); and try again.
PS :
The line DesiredCapabilities cap = DesiredCapabilities.firefox(); already figures out the browser name, so you don't need to explicitly set the browser name via cap.setBrowserName("firefox");

WebDriverException: Message: Missing 'marionetteProtocol' field in handshake

I'm currently trying to run a robotframework test scripts locally (Ubuntu 12.04 LTS 64 bit). The issue that I faced was not able to launch FF browser in Open Browser. Below is the details/specs of the setup that I have.
Firefox (v26.0)
Selenium2Library
selenium-server-standalone-2.53.1.jar
geckodriver-v0.9.0
Please note that I used same machine as hub and node (selenium grid)
Here the command to launch my hub :
java -jar selenium-server-standalone-2.53.1.jar -role hub -port 4444
While here's the command to register my node :
java -jar selenium-server-standalone-2.53.1.jar -role node -hub http://localhost:4444/grid/register -trustAllSSLCertificates
I did what is per told in https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver (add wires executable in the PATH)
I also did :
${ff default caps} Evaluate sys.modules['selenium.webdriver'].common.desired_capabilities.DesiredCapabilities.FIREFOX sys,selenium.webdriver
Set To Dictionary ${ff default caps} marionette=${True}
Create Webdriver Firefox executable_path=\home\my\wires
Open Browser ${HOMEPAGE} ff None ${HUB}
As a result, the FF browser launch, but not opening the URL ${HOMEPAGE}. I've been googling around and stuck in this issue for so long. Please help..
https://github.com/mozilla/geckodriver/releases
firefox version is too low , update to 48 is OK
python 2.7
selenium 3.0.1
geckodriver v0.11.0.exe
firefox 48.0

How to execute script on Multiple nodes parallely using Selenium Grid

Following is my code -
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.VISTA);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.manage().window().maximize();
driver.get(url);
I want to execute my script on 3 different nodes
For starting HUB I am using the command :-
java -jar selenium-server-standalone-2.53.0.jar -role hub -port 4444
and for nodes
Node 1 :-
java -jar selenium-server-standalone-2.53.0.jar -role webdriver -hub http://192.168.1.118:4444/grid/register -port 5556
Node 2 :-
java -jar selenium-server-standalone-2.53.0.jar -role webdriver -hub http://192.168.1.118:4444/grid/register -port 5557
Node 3 :-
java -jar selenium-server-standalone-2.53.0.jar -role webdriver -hub http://192.168.1.118:4444/grid/register -port 5558
All 3 nodes are on 3 different machines So my question is do i need to mention all 3 nodes ip address in my code or is there any way to execute script parallely on all 3 machines ?
No you cannot do this directly. By default I think a node supports 5 sessions. So only after all the 5 sessions in node 1 have been exhausted, can the tests go to the second node. So for you to be able to run your tests in parallel on all the 3 nodes, you would need to start all your nodes with a maxSession of 1 and then spin off 3 threads for your tests. That would cause all the nodes to run your tests simultaneously. But just wondering why would you want to run your tests against all the nodes ? What is your use case ?
If you are using testNG then you can use the 'parallel' attribute in testng.xml for a sample blog refer here.
you can also use Maven's maven-failsafe-plugin with <forkCount> tag, have a look at this.
hope this helps.

How to run selenium test case in two different nodes?

Actually I need to run my single selenium test case in two different nodes using FIREFOX browser (selenium grid) , I have started my hub using below command
java -jar selenium-server-standalone-2.32.0.jar -role hub
started two Nodes with two different port nos :
Node :1
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 7575 -browser browserName=firefox,version=18,platform=WINDOWS
Node :2
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 8585 -browser browserName=firefox,version=18,platform=WINDOWS
But when i execute my test case i can view my execution only in one node other node remains still, it shows Done :/status but no execution has taken place
can u please help out to solve this problem
thanks in advance
Tester approach:
Make your test to be runnable as indipendent .jar file. Which means the test wil not be actually a #Test but some method or piece of code inside main method
Pro tip: If you can, run the nodes against the same hub. This can be done if the computers are in same network and you can access these computers.
If this can be done, you will just run the .jar file twice, telling it where the huib is, and nodes will be assigned automatically
If this cannot be done, you will have to deploy these .jar files on each computer (node) and run them (requires two people in most cases)
Example:
My own computer has IP 10.131.7.11 inside local network. So I will run the hub and each node will just do this:
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://10.131.7.11:4444/grid/register -port 7575 -browser browserName=firefox,version=18,platform=WINDOWS
Once the nodes are running, I will run the test twice. The hub will then automatically assign browsers to concrete node.
Developer approach:
you can use multithreading and run the test once, in two threads.
But since I am tester, I use the first approach :) And I did communicate with our developers who helped me to create multithreading test suite which is idiot proof (tested on myself :) )

IE Opens When I Use ChromeWebdriver

I have tried searching, but have had no luck in finding a solution. I trying to get Selenium Grid to work on my local machine before placing nodes on other machines. Long story short when I try using the chromewebdriver IE opens.
Everything compiles but IE opens and not chrome. While trying to find the problem I used the driver.getCapabilities().getBrowserName() and it showed internetexplorer. I tried looking through the remoteWebDriver class but could not find where its capability was set to IE.
I've also tried coping and running some code from similar questions, but IE still opens. Any help would be appreciated.
Hub:
java -jar selenium-server-standalone-2.31.0.jar -role hub -port 4444
Nodes:
java -jar selenium-standalone-2.31.0.jar -role node -port 5555 -hub http://localhost:4444/grid/register -browser browserName=chrome,platform=WINDOWS -browser browserName=firefox,platform=WINDOWS
(I have also tried adding -Dwebdriver.chrome.driver={path to web driver} but had no luck)
Code:
WebDriver driver;
#Before
public void setUp()throws java.net.MalformedURLException{
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("Chrome");
capability.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new java.net.URL("http://localhost:5555/wd/hub"), capability, capability);
driver.get("http://book.theautomatedtester.co.uk/chapter1");
}
Browser you registered was under the name "chrome" and capability has "Chrome". Ideally this should throw a no browser available

Resources