Java TestNg Selenium Webdriver Training syllabus

Syllabus of Training Session:

TestNG:
1. What is TestNg
2. Installing TestNg in Eclipse
3. TestNg annotations
4. Understanding usage of annotations
5. Running a Test in TestNg
6. Batch Running of tests in TestNg
7. Skipping Tests
8. Parameter zing Tests – DataProvider
9. Assertions/Reporting Errors
10. TestNg Reports
11. Advantages over Junit

Page Object Model for selenium webdriver

Like QTP, TestComplete and few other automation tools selenium webdriver does not provide any centralized repository where we can put object locator of page element. In POM object pattern we can accomplish this type approach.

What is POM:
In automated web testing, a Page Object is a class or object that represents a web page in your application. A Page Object hides the technical details about how you interact with a web page behind a more readable and business-focused facade. Following are the few points in details:
Page Object Model is a design pattern to create Object Repository for web UI elements. Like it provide you to option to put all locators in corresponding page (java file ) like for home page you  create a homepage java file and put all element locators of home page in same class.
Under this model, you should create java file like above ( homePage.java ) home page and create functions related to this page  like clickHomeMenu, clickProduct() verfiyHomePage() etc.
So your page object class contains elements locator and corresponding function what you need to perform on that particular page.
Name of these function and object locator must be logically defined like elements name username , password, loginButoon and corresponding function should be like enterUserName(), enterPassword(), clickLoginButton()

Road to capture android log using java code

In this post I will show you how to capture android log using java code.
public static void captureAndroidDevicesLog() {
  try {
   Process process = Runtime.getRuntime().exec("adb logcat");

   BufferedReader reader = new BufferedReader(new InputStreamReader(
         process.getInputStream()));
   String s;
   System.out.println("*********************************************");
   System.out.println("Printing android logs");
   System.out.println("*********************************************");
   while ((s = reader.readLine()) != null) {
    System.out.println(s);
   }
   System.out.println("*********************************************");
   System.out.println("End printing android logs");
   System.out.println("*********************************************");
  } catch (IOException e) {
   e.printStackTrace();
  } 
}

Above code capture all log of android device and print in console. Yo can manupulate as per you need.

Road to capture all connected devices using java code at run time

In this post you will learn how to capture connected devices udid at run time using java code.

public static List<String> getAttachedDevicesList(){
 
  List<String> devicesID = new ArrayList<String>();
  try {
         Process process = Runtime.getRuntime().exec("adb devices");       
         BufferedReader reader=new BufferedReader( new InputStreamReader(process.getInputStream()));
         String s;                
         while ((s = reader.readLine()) != null){         
          if(s.contains("device") && ! s.contains("attached")){
           String[] device = s.split("\t");
           devicesID.add(device[0]);
          }
         }  
        
     } catch (IOException e) {
         e.printStackTrace();
     }
     return devicesID;
 }


public static void main(String[] str) {
  List<String> devicesID = getAttachedDevicesList();
  for (String dvc : devicesID) {
   System.out.println(dvc);
  }
 }

When you run this you will get  all connected devices  udid.

Road to parallel execution of selenium webdriver test scripts using multithreading

In this post you will learn to how to execute selenium webdriver test script on two browser parallel using multithreading.
package com.test;

import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

public class GoogleSearchMultiThread extends Thread {

   private WebDriver driver;
   private String baseUrl;
   private String browsertype;

   public GoogleSearchMultiThread(String name, String browsertype) {
               super(name);
               this.browsertype = browsertype;
   }

   @Override
   public void run() {
        System.out.println("Thread- Started"
                                      + Thread.currentThread().getName());
        try {
                Thread.sleep(1000);
                setUp(this.browsertype);
                testGoogleSearch();

          } catch (InterruptedException e) {
                 e.printStackTrace();
         } catch (Exception e) {
               // TODO Auto-generated catch block
                e.printStackTrace();
        } finally {
                tearDown();
        }
       System.out.println("Thread- END " + Thread.currentThread().getName());
   }

   // main method to create thread and run multiple thread
   public static void main(String[] args) {

               Thread t1 = new GoogleSearchMultiThread("Thread Firefox", "Firefox");
               Thread t2 = new GoogleSearchMultiThread("Thread IE", "IE");
               System.out.println("Starting MyThreads");
               t1.start();
               t2.start();
               System.out.println("Thread has been started");

   }

   // set up method to initialize driver object
   public void setUp(String browsertype) throws Exception {

               if (browsertype.contains("IE")) {
                           File IEDriver = new File("IEDriverServer.exe");
                           System.setProperty("webdriver.ie.driver",
                                                   IEDriver.getAbsolutePath());
                           driver = new InternetExplorerDriver();
               } else if (browsertype.contains("Firefox")) {
                           driver = new FirefoxDriver();
               }
               baseUrl = "https://www.google.co.in/";
               driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
               driver.manage().window().maximize();
   }

   // test scripts
   public void testGoogleSearch() throws Exception {
               driver.get(baseUrl + "/");
               driver.findElement(By.id("gbqfq")).clear();
               driver.findElement(By.id("gbqfq")).sendKeys("Testing");
               driver.findElement(By.id("gbqfb")).click();
               driver.findElement(By.id("ab_opt_icon")).click();
               driver.findElement(By.cssSelector("#ab_as > div")).click();
               driver.findElement(By.xpath("//input[@value='Advanced Search']"))
                                       .click();
   }

   // tear down function to close browser
   public void tearDown() {
               driver.quit();
   }

}

In above class I use multithreading concept of java, when you run test it will execute two thread of test on at firefox browser and other on Internet explorer browser.

Road to parallel execution of selenium webdriver test using testng

In this post you will learn how to run selenium webdriver test scripts parallel in more two environments using testng suite, testng has a feature by which we can create multiple instance of a single testng class file.

In below example, I created a selenium webdriver test script for google search. Which will run on two browsers firefox and IE.

Road to use variable from bootstrap file in Codeception test

In this post I will show you how to create global variable which can be use in any codeception test scripts file. Suppose that we have user name and password which need to be use in all test scripts for login to application.  This is good practices to put these values in one place instead of passing in multiple test case.
You should see that “_bootstrap.php” files are generated in folder “acceptance”,  “functional” , “unit” and at root of test folder.
You can create a variable in this files with any desire values and can be use in corresponding folders scripts.

Integration of Webdriver ruby RSpec test suite with CircleCi

CircleCI has a continuous integration tool which builds and run your application in cloud environment. You can integrate and build your automation test scripts. CircleCI support following language:
Language:
1. Ruby.
2. PHP.
3. Java.
4. Python

Mobile Platform:
1. Android
2. iOS

How to setup:
1. You must have a git account.
2. Click on login circleci it will redirect git account login page.
3. Login in to git with your credential.
4. Click on Add Projects menu.
5. Choose a repository, of GitHub such as pushes and pull requests. It will kick off the first build immediately, and a new build will be initiated each time someone pushes commits.

Working in Git branches

In this post you will learn how to work in Git branches like: create, delete, merge branch data.
1. List all branches of your repository.
$ git branch

2. Create new branch.
$ git branch {branchName}

Example:
$git branch qa

3. Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
$ git branch -d {branchName}

Example:
$git branch -d qa

How to read XML file data in Java || How to create object repository in selenium

As most of the commercial automation tools has feature of object repository concept, which separate application objects from automation scripts, it help us to modify object when AUT object change without going into code.  Also if we create object repository then it reuse throughout scripts from one place.

In Webdriver we can put locator (object) of web elements in to xml, properties, excel file etc at one place, and can separate from test scripts with logically divided into files.

In this post I am going to show you how to read data and put locators into xml files.

We create xml files for object locator like “Header.xml” where put all locators related to header menus, “Login.xml” for locators of login page, “Dashborad.xml” for locator of dashboard page.