Sunday, July 12, 2015

Grid

Refer to blog for more details: This website has complete command and screenshots associated with GRID.
https://www.learn-automation.com



- This is the last type of Selenium types. It supports the scripts written in older versions of Selenium.

- Grid --- distributing the test cases into multiple systems. So make sure systesms are marked sub or hub accordingly. Here test cases can be executed acrosss multiple test cases in multiple browsers in parellel

- Hub system - distributes the tc's across sub and collects the results.

- Sub (node) system - executes the tc's assigned by Hub system

- This helps in compatability testing

- Using DesiredCapability object we can assign the browser settings we need to use.

Node matches if all the requested capabilties are met, so to request specific capabilities on the grid specify them before passing the it into the WebDriver object as mentioned below:

DesiredCapabilities capabilityobject = DesiredCapabilities.firefox();
capabilityobject.setBrowserName("firefox");
capabilityobject.setPlatform("LINUX");
capabilityobject.version("3.6");

WebDriver driver = new RemoteWebDriver(new URL(http://HubIP:4444/wd/hub), capability);



Difference between Selenium Grid and QTP remote connection for CI?

Based on the training- Jan 2016
 - QTP remote connection using Jenkins will need QTP installed on all the remote machines. Once remote machines are all set up, Jenkins will connect those machines and execute test cases instead of you doing it manually(clicking the run button).

- Selenium Grid, looks like advanced concept compared with QTP remote connection. Here we need systems to be distributed as node and hub, and node does not need Eclipse installed on them just hub will need. Hub will connect respect node, make use of the nodes to execute the scripts in multiple machines (node) and browsers.


Real code executed on my personal machine by registering hub and node on same machine:
package seleniumGridconceptsProject;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ExecutingGrid {

public static void main(String args[]) throws MalformedURLException { //Not sure about this exception, added due to URL class

DesiredCapabilities dc = DesiredCapabilities.chrome(); //path of chrome driver is given while registering node and hub

URL url = new URL("http://192.168.0.12:4444/wd/hub");  // it can be hub url or node url. This will tell trigger class to trigger on which node. If you give hub url then hub will take care of which node to pick on its own.

WebDriver driver = new RemoteWebDriver(url,dc);

driver.get("http://learn-automation.com/");

System.out.println("Printing through Grid");

}
}

/* Prerequisites: Selnium webdriver jar and Selenium Standalone jar
          *Register hub:Open cmd
       * Navigate to selenum jar file folder
* enter below command:
* java -Dwebdriver.chrome.driver= "path of driver file" -jar seleniumjarname -hub
*
* Once registered as hub, 
          * Register Node:
          *Enter below command in another session of command prompt t
* Navigate to selenium jar file folder
* enter below command:
* java -jar selenium jar name -role node -hub "hub url"
*
*
*/












No comments:

Post a Comment