How to take the Screen shot in Selenium Grid

Here is the code that you can use to take the screen shot when running the script using Selenium Grid or Remote machine

public void takeScreenshot() throws IOException {
Random rand = new Random();
int num = rand.nextInt(150);
File scrFile = null;
Integer numNoRange = rand.nextInt();
WebDriver underlyingDriver = driver.getWrappedDriver();
if (browser.contains("Remote")) {
try {
WebDriver augmentedDriver = new Augmenter().augment(underlyingDriver);
scrFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
String filename = numNoRange.toString();
copyFile(scrFile, new File("location were you want the file to be saved" + filename + ".png")); //Change location were you want the file to be saved
} catch (Exception n) {
LOGGER.warn("Failed to take screen shot of remote browser");
}
}
if (scrFile == null) {
try {
scrFile = ((TakesScreenshot) underlyingDriver).getScreenshotAs(OutputType.FILE);
String filename = numNoRange.toString();
copyFile(scrFile, new File("location were you want the file to be saved" + filename + ".png")); //Change location were you want the file to be saved
} catch (NullPointerException n) {
fail(n.getMessage());
}
}
}

Link

Setup Grid instance on a remote machine and executing the test script on the remote machine.

Requirements on your current system (System A) and remote system (System B)
Download and Install Chrome browser
Selenium Server Download version 2.33.0 from http://docs.seleniumhq.org/download/
Chromedriver from https://code.google.com/p/chromedriver/downloads/list
Latest version of Java Version 7 download it from http://java.com/en/download/index.jsp

Installation on your current system (System A) and remote system (System B)
Create a new folder “Selenium” in your C driver and copy the selenium-server-standalone-2.33.0.jar and chromedriver.exe to the folder

Running
Get your IP address (System A):
Run the following command on the command prompt to get your systems IP address – “ipconfig”.
Make a note of the IP address as we will use it on the remote machine
In this example I am using the IP address “192.000.0.0”. So just replace it as necessary.

On current machine run the following command to start the Selenium server hub from command prompt
java -jar c:\selenium\selenium-server-standalone-2.33.0.jar -role hub

Open another command prompt and run the following command to setup 10 instances on chrome browser on port 5000 (Replace 192.000.0.0 with System A’s IP Address).
java -jar c:\selenium\selenium-server-standalone-2.33.0.jar -role node -hub http://192.000.0.0:4444/grid/register -port 5000 -browser “browserName=chrome”,maxInstances=10 -Dwebdriver.chrome.driver=”C:\Selenium\chromedriver.exe”

On the current machine where you have hub running open the chrome browser window and enter http://localhost:4444/grid/console
You will see DefaultRemoteProxy (version : 2.33.0) and webdriver with 10 chrome icons

Setting-up 10 instances on chrome browser on port 6000 on the remote system (System B) (I am using Windows 7 OS)

Run the following command on the command prompt to get your systems IP address – “ipconfig”.
Make note of the IP address of System B

Open a new command prompt and run the following command to setup 10 instances on chrome browser on port 6000 (Replace 192.000.0.0 with System A’s IP Address).
java -jar c:\selenium\selenium-server-standalone-2.33.0.jar -role node -hub http://192.000.0.0:4444/grid/register -port 6000 -browser “browserName=chrome”,maxInstances=10 -Dwebdriver.chrome.driver=”C:\Selenium\chromedriver.exe”

Go to System A and refresh the browser window “http://localhost:4444/grid/console”
You will have two instances of Chrome browser running, one on Port 5000 on System A and Port 6000 on System B

Hints/Tips
Now that the Selenium Grid is running on two machines and two different ports its time run the scripts on System B (Port 6000)

Here is the Startup method

public void Startup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new RemoteWebDriver(new URL(“http://192.000.0.00:6000/wd/hub”), capabilities.chrome());//replace 192.000.0.00 with System B’s IP address.
}

If you want to run the scripts on System A (Port 5000)

public void Startup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new RemoteWebDriver(new URL(“http://192.000.0.00:5000/wd/hub”), capabilities.chrome());//replace 192.000.0.00 with System A’s IP address.
}

On Linux run the following command to setup 10 instances on chrome browser on port 8000 (Replace 192.000.0.0 with System A’s IP Address) (192.168.0.00 is the IP Address for the Linux machine).

java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://*192.000.0.0*:4444/grid/register -port 8000 -host 192.168.0.00 -browser “browserName=google-chrome,platform=LINUX,maxInstances=10″ -Dwebdriver.chrome.driver=”chromedriver”