waitForElementPresents method to check for multiple elements on a webpage 

waitForElementPresents method is used to check for multiple elements on a webpage at one time. Java Selenium Webdriver.
[code]
public void waitForElementPresents(int i, By... by) throws InterruptedException, IOException {
for (int second = 0; second <= i; second++) {
if (second >= i) {
takeScreenshot();
break;
}
if (areAllElementsPresent(by)) {
for (By singleBy : by) {
pass("Found:"+singleBy);
}
break;
}
Thread.sleep(1000);
}
}
[/code]
[code]
public boolean areAllElementsPresent(By... by) {
for (By singleBy : by) {
if (!isElementPresent(singleBy)) {
return false;
}
}
return true;
}
[/code]

By Pavandeep Puddupakkam on June 19, 2013 | Java, WebDriver | A comment?

Enable Auto suggest in Eclipse 

Navigate to the Content assist in Eclipse. Windows menu -> Preferences -> Java -> Editor -> Content assist

Auto suggest 263x300 Enable Auto suggest in Eclipse

Enter the following text in the Auto activation triggers for Java box: abcdefghijklmnopqrstuvwxyz.

By Pavandeep Puddupakkam on June 18, 2013 | Automation Tips | A comment?
Tags: ,

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”

Setup method for running Grid using Selenium Webdriver 

Here is the article that give you the details of how to create the Startup method to invoke the grid and passing the Grid IP Address parameter

The TestNG test suite is as under:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite" verbose="3" parallel="classes" thread-count="3">
<test name="Tests">
    <parameter name="IPAddress"  value="http://192.00.0.30:5000/wd/hub"/>
<classes>
    <class name="com.test.Test1"/>
    <class name="com.test.Test2"/>
    <class name="com.test.Test3"/>
</classes>
</test>
</suite>

By Pavandeep Puddupakkam on | Java | A comment?
Tags: , ,

How to read a PDF file using Selenium Webdriver Scripts 

I have been asked this questions a multiple of times about reading the PDF files. I had to do some research and found a way to read the content and also verify the content of the PDF file using the Selenium Webdriver script.

Here are the libraries you need to use to read the PDF:

import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.util.PDFTextStripper;
import java.io.BufferedInputStream;
import java.io.File;
import java.net.URL;
 
//Here is the code for the Check PDF content method.
 
 <code>public void checkPDFContent(String... checkValue) throws IOException {
        URL url = new URL(driver.getCurrentUrl());
        BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
        PDFParser parser = new PDFParser(fileToParse);
        parser.parse();
        String output = new PDFTextStripper().getText(parser.getPDDocument());
        int len = checkValue.length;
        for (int i = 0; i <= (len - 1); i++) {
          if(output.contains(checkValue[i])){
              pass(checkValue[i] + " is present in the PDF file");
          } else {
              fail(checkValue[i] + " is not present in the PDF file");
              resultcount++;
              takeScreenshot();
          }
        }
        pass(output);
        parser.getPDDocument().close();
    }

By Pavandeep Puddupakkam on May 24, 2013 | Java, WebDriver | A comment?
Tags: , , , , ,

Using Ternary Operator in Webdriver Automation Scripts 

I was recently been introduced to Ternary Operator by my colleague and I stared to like it because it can get rid of all the if..else.. conditions and just does the lot in one line.

Here is the traditional way of checking a condition using if.. else..

By Pavandeep Puddupakkam on | Java, WebDriver | A comment?
Tags: , ,


Automation Tips
Automation Tools
QA Interview Q&A
Selenium IDE
Selenium RC
Software Testing
WebDriver
XPath

css.php