Using Selenium Grid with Two Nodes-FF & Chrome(HUB)


Steps for Setting Up the Grid

1. Download the Selenium Sever Jar File using the link

2. Pre-requisite for Every Machine 
Copy  the Selenium Server in every host hub,remote node1,remote node2

3. To check the default port number used by Hub '4444' is reserved or not
Command --> netstat -a -n | findStr 4444
We have to check this command only in hub machine.

4. Starting the Hub. Navigate to the location where the selenium-server jar is downloaded and execute the below command.
java -jar selenium-server-standalone-2.44.0.jar  -role hub

5. Starting the Hub using particular port. If the default port '4444' is already in use. Then we have to pass another port number in the command line for the argument -port as mentioned below:
java -jar selenium-server-standalone-2.44.0.jar  -role hub -port 4545

6. Verifying the Hub Console
7.Starting Node1: Navigate to the location where selenium server jar is located and execute the below command
java -jar selenium-server-standalone-2.44.0.jar  -role webdriver -browser "browserName=firefox,version=35,maxInstances=1,platform=WINDOWS" -hubHost localhost -port 4546

8. Starting Node2: Navigate to the location where selenium server jar is located and execute the below command
java -jar  selenium-server-standalone-2.44.0.jar -role webdriver -browser "browserName=chrome,version=40,maxInstances=1,platform=WINDOWS" -hubHost localhost -port 4547 -Dwebdriver.chrome.driver=D:\\Selenium\\chromedriver_win32\\chromedriver.exe 

9. Selenium WebDriver Script for FF
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("firefox");
caps.setVersion("35");
caps.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

10. Selenium WebDriver Script for CH
 DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("chrome");
caps.setVersion("40");
caps.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

Selenium WebDriver Program:

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.Platform;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class GridTests {
RemoteWebDriver  driver;
DesiredCapabilities caps;
@Parameters({"browsertype","url"})
@BeforeTest
public void invokebrowser(String browserType,String url) throws MalformedURLException
{
if(browserType.equals("FF"))
{
caps = DesiredCapabilities.firefox();
caps.setBrowserName("firefox");
caps.setVersion("10");
caps.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);
System.out.println("in FF");
//driver =new FirefoxDriver();
}
else if(browserType.equals("IE"))
{
System.out.println("in IE");
File f =new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver",f.getAbsolutePath());
driver = new InternetExplorerDriver();
}
else
{
caps = DesiredCapabilities.chrome();
caps.setBrowserName("chrome");
caps.setVersion("40");
caps.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

System.out.println("in CH");
}
driver.get(url);
}
@Test
public void verifyTitle()
{

Assert.assertEquals(driver.getTitle(),"Facebook");

}
}




Handling Security Authentication Pop-up Using Autoit-Selenium WebDriver!!!

Implementation of AUTO IT in Selenium
Pre-Requisites: Download the AutoIT Full Installation and AutoIT Script Editor from the url AutoIT Website  http://www.autoitscript.com/site/autoit/downloads/
Download both the AutoIt Window Identification and Editor


Handling HTTPS pop-up using Auto it->

Url to access-> http://www.engprod-charter.net/

Step 1- Open Autoit Editor and write the following script

 Step2-Write the below program and Save the program.
$title= "Authentication Required"
WinWaitActive($title)
send("sudheer")
send("{TAB}")
send("welcome")
send("{ENTER}")
  
Step3- Compile the Script which generates the .exe file.
Step4-Execute the Script
Step5- Implement this selenium.
Runtime.getRuntime().exec("Absolute path to the https autoit script ");

Flickering issue of IE browser while taking screenshot in Selenium WebDriver Handled Using java.awt.Robot Class


import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/*
 * 
 * Taking a screenshot using Robot class in java rather than 
 * TakesScreenshot Interface in Selenium Webdriver.
 *
 */

public class CaptureFullScreen {

public static void main(String[] args) throws AWTException {
try 
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");

//Implementing the Robot Class
Robot robot = new Robot();
String format = "jpg";  
String imgFileName= new SimpleDateFormat("mm-dd-yyyy_HH-ss").
format( new GregorianCalendar().getTime());
System.out.println(new GregorianCalendar().getTime());

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, format, new File("d:\\"+imgFileName+".jpg"));

System.out.println("Screenshot Saved in today's date format in d:\\");
catch (  IOException ex)
{
System.err.println(ex);
}
}
}