Tuesday, 14 January 2020

Selenium Interview Questions             TestNG Interview Questions

Appium Interview Questions             API Testing Interview Questions

What is Selenium-Grid?

Selenium-Grid allows you to run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems. Essentially, Selenium-Grid supports distributed test execution. It allows for running your tests in a distributed test execution environment.


When to Use 
There are two reasons why you might want to use Selenium-Grid. 
  •  To run your tests against multiple browsers, multiple versions of the browser, and browsers running on different operating systems. 
  • To reduce the time it takes for the test suite to complete a test pass.


Installation
Installation is simple. Download the Selenium-Server jar file from the SeleniumHq website’s download page. Place this jar in a folder of your choice. You’ll need to be sure the java executable is on your execution path so that you can run it from the command-line. If it does not run correctly, verify your system’s path variable includes the path to the java.exe.


Starting Selenium-Grid
Generally, we have to start a hub first since nodes depend on a hub. This is not absolutely necessary, however, since nodes can recognize when a hub has been started and vice-versa.


Selenium Grid Architecture

Selenium Grid has a Hub and Node Architecture.

The Hub

  • The hub is the central point where you load your tests into.
  • There should only be one hub in a grid.
The hub is launched only on a single machine, say, a computer whose O.S is Windows 10 and whose browser is Firefox.
The machine containing the hub is where the tests will be run, but you will see the browser being automated on the node.


The Nodes
  • Nodes are the Selenium instances that will execute the tests that you loaded on the hub.
  • There can be one or more nodes in a grid.
  • Nodes can be launched on multiple machines with different platforms and browsers.
  • The machines running the nodes need not be the same platform as that of the hub.
Selenium Grid can be set up in two different ways; one through command line and the other through JSON config file.


Starting a Hub
The Hub is the central point that will receive all the test request and distribute them the right nodes.
Open a command prompt and navigate to the directory where you copied the selenium-server-standalone file. Type the following command:
java -jar selenium-server-standalone-<version>.jar -role hub
The hub will automatically start-up using port 4444 by default. To change the default port, you can add the optional parameter -port when you run the command. 
You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console
If you have started a hub on Machine A's( IP address is 192.168.1.3), then on the browser on other machines you should type http://192.168.1.3:4444/grid/console


Starting a Node
To start a node using default parameters, run the following command from a command-line
java -Dwebdriver.gecko.driver="C:\geckodriver.exe" -jar selenium-server-standalone-<version>.jar -role webdriver -hub http://localhost::4444/grid/register -port 5566
We can also specify name of the browser, version, number of instances, number of sessionAdd below parameters at time of starting node
java -Dwebdriver.gecko.driver="C:\geckodriver.exe" -jar selenium-server-standalone-<version>.jar -role webdriver -hub http://localhost::4444/grid/register -port 5566 -browser “browserName=firefox,version=3.6,firefox_binary=c:\Program Files\firefox ,maxInstances=3, platform=WINDOWS”


Note
  • This assumes the hub has been started above using default parameters. The default port the hub uses to listen for new requests is port 4444. This is why port 4444 was used in the URL for locating the hub. 
  • The use of ‘localhost’ assumes your node is running on the same machine as your hub. For getting started this is probably easiest. If running the hub and node on separate machines, simply replace ‘localhost’ with the hostname of the remote machine running the hub. 
WARNING: Be sure to turn off the firewalls on the machine running your hub and nodes. Otherwise you may get connection errors.


Go to the Selenium Grid web interface (http://localhost:4444/grid/console) and refresh the page. You should see something like this.
Using Grid to run tests
For WebDriver nodes, you will need to use the RemoteWebDriver and the DesiredCapabilities object to define which browser, version, and platform you wish to use. Create the target browser capabilities you want to run the tests against:
DesiredCapabilities capability = DesiredCapabilities.firefox();


Pass that into the RemoteWebDriver object:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);


The hub will then assign the test to a matching node.
A node matches if all the requested capabilities are met. To request specific capabilities on the grid, specify them before passing it into the WebDriver object.
capability.setBrowserName();
capability.setPlatform();
capability.setVersion()

capability.setCapability(,);


No comments:

Post a Comment