Sunday, January 19, 2014

Selenium Testing Concepts

Selenium Testing Concepts
 
Introduction
What is automation testing
When best to go for automation
Advantages of Automation
Criteria for Automation
Introduction to Selenium
What is Selenium
Use of selenium
When selenium can be useful in testing
Features of Selenium
Differences between Selenium
and QTP
Selenium Components
Selenium IDE
Selenium RC
Selenium Webdriver
Selenium Grid
Configuration of IDE & Dev Scripts
Recording the script
Running the script
script
Object Identification
Difference between Test case and
test suit
Languages supported while
Recording
Synchronization in Selenium IDE
Testing Vs Selenium IDE
When to use Selenium IDE
How to run the recorded script
Against other browsers
Why companies are not using
Recording tools
Creating the Environment for
Selenium RC
Creating generic scripts in
Selenium
Creating scripts by using
Functions
Running the scripts in Eclipse
Inheritance
Browser commands with examples
Interactive commands with examples
Information commands with examples
Validation commands with examples
How to take data from excel sheets
Why should we use excel sheets
How to take large no of data from excel sheets
How to export data to an excel sheets
Export large no of data to an excel sheet
How to export results after completion of execution the script
How to use Eclipse
Debugging the script
Maintaining synchronization Points
How to handle Pop ups and alert messages
Recognizing Similar Elements
Working with Table Elements
Connecting to Database
Developing reusable script
Validations
What is validation
What is the use of validation in
Automation testing
When to use validation in real time
How to use validations
Core Java Fundamentals
Language Fundamentals
Java Programming Language Keywords
Class and Object
Data Types
Array Declaration, Construction and
Initialization
Flow Control, Exceptions, and
Assertions
Writing Code Using If and Switch
Statements
Writing Code using Loops
Handling Exceptions
Working with the Assertion Mechanism
Object Orientation, Overloading and
Overriding, Constructors
Benefits of Encapsulation
Overridden and Overloaded Methods
Using the java.lang.String Class
Using the java.lang.Math Class
Using Wrapper Classes
Using the equals() Method with
Strings, Wrappers and Objects
Defining, Instantiating, and
Starting
Threads
Preventing Thread Execution
Synchronizing Code
Thread Interaction
JUnit Introduction
Proving it works
Starting from scratch
Understanding unit testing
Frameworks
Setting up JUnit
Testing with JUnit
Object repository
What is object repository
How to use object repository in
Framework
What is the use of maintain
Object repository
Types of creating object repository
Additional concepts
How to use XPath
How to use DOM
How to use Key Commands
Selenium 2 / Web Driver
Selenium 2.0 Features
The Selenium Server – When to Use it
Setting up a Selenium – Web
Driver Project
Migrating from Selenium 1.0
Getting Started with Selenium
Web Driver
Introducing Web Driver’s Drivers
Commands & Operation
Web Driver backed Selenium RC
Programs on Web Driver
Programs on Web Driver Backed
Selenium RC
TestNG Framework
What is TestNG
Create TestNG.xml file
Integrate the Selenium Scripts
and Run from TestNG
Reporting Results & Analyze
Run Scripts from Multiple
Browsers
Automation Life Cycle
What is a Framework?
Types of Frameworks
Modular framework
Data Driven framework
Keyword driven framework
Hybrid framework
Use of Framework
How develop the framework
Integration of the framework
How execute the scripts from Framework
 

Basic Questions on Selenium

What is JAR?

JAR stands for Java ARchive. It's a file format based on the popular ZIP file format and is used for aggregating many files into one. Although JAR can be used as a general archiving tool, the primary motivation for its development was so that Java applets and their requisite components (.class files, images and sounds) can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece. This greatly improves the speed with which an applet can be loaded onto a web page and begin functioning. The JAR format also supports compression, which reduces the size of the file and improves download time still further. Additionally, individual entries in a JAR file may be digitally signed by the applet author to authenticate their origin.

JAR is:

  • the only archive format that is cross-platform
  • the only format that handles audio and image files as well as class files
  • backward-compatible with existing applet code
  • an open standard, fully extendable, and written in java
  • the preferred way to bundle the pieces of a java applet

JAR consists of a zip archive, as defined by PKWARE, containing a manifest file and potentially signature files, as defined in the JAR File Specification.

What Is a Package?


A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.
The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", or "API" for short. Its packages represent the tasks most commonly associated with general-purpose programming. For example, a String object contains state and behavior for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify a file on the filesystem; a Socket object allows for the creation and use of network sockets; various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. There are literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your particular application, rather than the infrastructure required to make it work.
The Java Platform API Specification contains the complete listing for all packages, interfaces, classes, fields, and methods supplied by the Java SE platform. Load the page in your browser and bookmark it. As a programmer, it will become your single most important piece of reference documentation.

How to login to Gmail with multiple data


1. Gmail Login with Multiple data
package com.gmail;
import java.io.FileInputStream;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import Claims.FetchExcelData;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class MultipleLogin {
                public static void main(String[] args) throws BiffException, IOException, NotFoundException, InterruptedException
                {
                               
                System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IeServerDriver\\IEDriverServer.exe");
                                WebDriver driver = new InternetExplorerDriver();
                                driver.get(FetchExcelData.Fetch("C:\\Selenium Automation1\\Test data\\TestData.xls", "URL"));
                                driver.manage().window().maximize();
                                FileInputStream fs= new FileInputStream("C:\\Selenium Automation1\\Test data\\LoginTest.xls");
                                Workbook wb= Workbook.getWorkbook(fs);
                               
                                Sheet sh= wb.getSheet(0);
                               
                                System.out.println(sh.getRows());
                                System.out.println(sh.getColumns());
                               
                                for (int row = 0; row < sh.getRows()-1; row++)
                                {
                                               
                                                String username = sh.getCell(0, row).getContents();
                                                System.out.println("Username" + username);
                                               
                                                driver.findElement(By.name("Email")).sendKeys(username);
                                               
                                                String password = sh.getCell(1, row).getContents();
                                                System.out.println("Password" + password);
                                               
                                                driver.findElement(By.name("passwrd")).sendKeys(password);
                                               
                                                driver.findElement(By.name("SignIn")).click();
                                                Thread.sleep(3000);
                                                driver.findElement(By.name("Logout")).click();
                                                Thread.sleep(3000);
                                               
                                }
                }
}
Test data :
2.
package MultiSignUp;
import java.io.IOException;
import java.util.logging.Logger;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import TestUtil.TestUtil;
public class SignUpMultiple extends TestUtil{

    public static Logger logger = Logger.getLogger(SignUpMultiple.class.getName());
    public String location = "C:\\Selenium\Automation\src\\TestData\\Testdata.xls";
    public String baseurl="paste the URL";
   
    public String sheetname1 = "SignUp";
    public String sheetname2 = "Login";
   
    @BeforeClass
    public void setUp() throws InterruptedException{
               
        driver= new FirefoxDriver();
        logger.info("Firefox driver instantiate");
        driver.get(baseurl);
        driver.manage().window().maximize();
        Thread.sleep(2000);
       
    }
    @Test(dataProvider="Login")
    public void LoginTest(String EmailAddress,String password,String Status,String TestCaseDescription) throws Exception{
               
             
       
                WaitForElementPresent("Login_hyperlink");
                getObject("Login_hyperlink").click();
               
                String windowhandle= driver.getWindowHandle();
                driver.switchTo().window(windowhandle);
                waitFor5Seconds();
                String HomePage = driver.getTitle();
                System.out.println(HomePage);
                getObject("Loginpage_EmailAddress_txt").clear();
                typeData("Loginpage_EmailAddress_txt", EmailAddress);
                getObject("Loginpage_password_txt").clear();
                typeData("Loginpage_password_txt", password);
                waitFor5Seconds();
                getObject("Login_button").click();
               
                if(getObject("Loginpage_dat_txt")!=null){
                             
                System.out.println("Valid Email Address and valid pwd"+Status+TestCaseDescription);
                waitFor5Seconds();
                takeScreenShot("Welcome home page", "modulename", "Filename");
                String LoginPage = driver.getTitle();
                System.out.println(LoginPage);
                getObject("Settings_Menu").click();
                logger.info("User clicked on Settings option in Login home page");
                getObject("Settings_SignOut").click();
                waitFor5Seconds();
                }
                if(getObject("Loginpage_Email_Invalid")!=null){
                    System.out.println("InValid Email Address and Valid passwords entered :"+ Status + TestCaseDescription);
                    waitFor5Seconds();
                    getObject("Loginpage_close_btn").click();
                   
                }
                if(getObject("Loginpage_Invalidpaswd_msg")!=null){
                    System.out.println("Valid Email id and INvalid pwd entry "+ Status + TestCaseDescription);
                }
               
}
    @AfterClass
    public void tearDown() throws IOException
    {
        takeScreenShot(driver.getTitle(), "tearDown", "Enrollment");
        driver.close();
        driver.quit();
    }

@DataProvider(name="Login")
public Object[][] createdata1() throws Exception{
               
                Object[][] retobjArr = getExcelData(location, sheetname2, "LoginHyperlink", "Loginbtn");
               
                return (retobjArr);
            }           
   

}

Friday, January 17, 2014

For Multiple windows handles code Reusability

package Sample;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class MultipleWindows extends Login
{
        public static void MultiWindows(WebDriver driver, String Searchfor, String value, String Search)
        {
                Set<String> winHandleBefore = driver.getWindowHandles();
                Iterator<String> it = winHandleBefore.iterator();
                String mwin= it.next();
                String Pwin = it.next();
                driver.switchTo().window(Pwin);
               
// Fetching the Member details from the Search Member Pop Up window.
               
            driver.findElement(By.name(Searchfor)).sendKeys(value);
                driver.findElement(By.name(Search)).click();
             
            driver.switchTo().window(mwin);
        }
}

 

 

Note : use the below method where ever multiple windows are opened.

 

MultipleWindows.MultiWindows(driver, "txtSearchFor", "value"), "PropertyName");


Wait For Alert message, read and Print


package Sample;
import org.openqa.selenium.Alert;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;

public class WaitForAlertMsg extends Login
{
  //public static WebDriver driver;
       public static void waitForAlert(WebDriver driver) throws InterruptedException
       {
          int i=0;

          while(i++<5)

          {
               try
               {
                   Alert alert = driver.switchTo().alert();
                   String Alerttext = alert.getText();
                   System.out.println("Alerttext");
                   alert.accept();
                   break;
               }
               catch(NoAlertPresentException e)
               {
                 Thread.sleep(2000);
                continue;
               }
          }
       }

}
 
 

Note: Use this method every where where ever you want to use.


WaitForAlertMsg.waitForAlert(driver);

 

How to read the properties from property file using java in Selenium


package TestNG;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import Claims.FetchExcelData;
public class secondfile {
public static void main(String[] args) throws IOException, NotFoundException, BiffException, InterruptedException
{
       System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IeServerDriver\\IEDriverServer.exe");
       WebDriver wd = new InternetExplorerDriver();
       wd.get(FetchExcelData.Fetch("C:\\Selenium Automation1\\Test data\\TestData.xls", "URL"));
Properties p=new Properties();
FileInputStream f=new FileInputStream("C:\\Selenium Automation1\\SeleniumPro\\src\\TestNG\\prop.properties");
p.load(f);
wd.findElement(By.name(p.getProperty("username"))).sendKeys("admin");
wd.findElement(By.name(p.getProperty("password"))).clear();
wd.findElement(By.name(p.getProperty("password"))).sendKeys("admin");
wd.findElement(By.name(p.getProperty("Login"))).click();
 
    }
}

Wednesday, January 8, 2014

Selenium Webdriver Tutorials -1

1. To find the list of items with tag name and click on particular link or Item.



List<WebElement> Member1 =

driver.findElements(By.tagName("a"));


float Members_Size1 = Member1.size();
  

system.out.println("Provider size is:"+Members_Size1);


Member1.get(2).click();
 

2. How to capture  the Text from alert .


 
Alert alert=
driver.switchTo().alert();
String text = alert.getText();
System.
out.println(text);
alert.accept();

3. Selenium Material Link :
http://www.browserstack.com/automate/java#

Coded UI Material Links

links:

http://binaryclips.wordpress.com/
http://roadtoautomation.blogspot.in/2013/03/data-driven-testing-using-java.html
http://mishra-vishal.blogspot.in/2012/12/automation-framework-testng-webdriver.html#!/2012/12/automation-framework-testng-webdriver.html

http://blogs.msdn.com/b/gautamg/archive/2009/12/18/why-is-coded-ui-test-generated-code-not-a-straight-line-code.aspx

http://www.dotnetcurry.com/showarticle.aspx?ID=702

http://webuiautomation.blogspot.in/

http://www.c-sharpcorner.com/UploadFile/25c78a/coded-ui-testing-in-visual-studio-2012/

http://www.articlesontesting.com/p/automation-testing-using-coded-ui.html

http://blog.imaginet.com/q-a-getting-started-with-visual-studios-coded-ui-testing/

http://softwaretestingbrains.blogspot.in/2013/01/coded-ui-test.html

http://swautomation.wordpress.com/tag/data-driven-testing/
 

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...