Wednesday, May 8, 2019


Open Application in the Different Browsers Through Selenium Java

Below are the Scripts for the Selenium Java

// Open the application in the Chrome browser

package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  {

 
//*************************** RUNNING CHROME DRIVER  *************

 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();


 String url ="http://www.xpr2t.com/Webobjects.html";

// Maximize the browser
driver.manage().window().maximize();
// Open the application in the browser
  driver.get(url );

   driver.close();
  driver.quit();

}
}



//  Open the application in the Firefox browser using Selenium Java

package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  {

//***********************************RUNNING IN FIREFOX *************************************************
 
 
// System.setProperty("webdriver.gecko.driver", "C:\\firefoxdriver\\geckodriver.exe");
// WebDriver driver = new FirefoxDriver();



 String url ="http://www.xpr2t.com/Webobjects.html";

// Maximize the browser
   driver.manage().window().maximize();  
// Open the application in the browser
    driver.get(url );

   driver.close();
  driver.quit();

}
}


//  Open the application in the Internet explorer browser using Selenium Java

package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  {

//Running in the Internet Explorer

//  System.setProperty("webdriver.ie.driver", "C:\\iedriver\\IEDriverServer.exe");
// WebDriver driver = new InternetExplorerDriver();


 String url ="http://www.xpr2t.com/Webobjects.html";

// Maximize the browser
   driver.manage().window().maximize();  
// Open the application in the browser
    driver.get(url );

   driver.close();
  driver.quit();

}
}


//  Open the Chrome application in Mac  - IOS  - apple mac laptop

package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  {

//MAC
system.setProperty("webdriver.chrome.driver",File.seperator+"User"+File.seprator+"downloads"+File.seperator+"chromedriver");
 
  WebDriver driver = new ChromeDriver();

 String url ="http://www.xpr2t.com/Webobjects.html";

// Maximize the browser
   driver.manage().window().maximize();  
// Open the application in the browser
    driver.get(url );

   driver.close();
  driver.quit();

}
}




Selenium Web Objects scripts
Below script to identify the Web objects - Text box, radio button, checkbox, list box, drop down box, Table, Links and Submit buttons.

d5//SCRIPT NAME :  Object identifications script - use the webobjects.html application
//This script will give the complete insight of objects identifications, Table, Iframes and alserts.


package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  { 

 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
   
String url ="http://www.xpr2t.com/Webobjects.html";
// Maximize the browser
driver.manage().window().maximize();
// Open the application in the browser
       driver.get(url);
//  driver.navigate().to(url);   ---- ANOTHER WAY OF PASSING URL
 // Hard wait for 5 sec
// Thread.sleep(5000);
 // TEXT FIELD IDENTIFICATION
driver.findElement(By.id("usernameid")).sendKeys("Selenium");

// get title
String title=driver.getTitle();
System.out.println(title);
// ************* ANOTHER WAY OF TEXT FIELD IDENTIFICATION  *********************************
// WebElement username= driver.findElement(By.id("usernameid"));
// username.sendKeys("selenium");
// *****************************************************************************************
//SLEEP
  Thread.sleep(5000);
 //GET TEXT FROM TEXTFIELD  - 2 WAYS CAN RETRIVE TEXT FROM TEXT FILED
  String text=driver.findElement(By.id("usernameid")).getText();
//   String text=driver.findElement(By.id("usernameid")).getAttribute("value");
 
//PRINT THE VALUE IN THE CONSOLE
  System.out.println("text filed value is :" +text);
// CLEAR TEXTFILED
  driver.findElement(By.id("usernameid")).clear();
 
String retrun =driver.findElement(By.id("usernameid")).getAttribute("value");//test

System.out.println("get attribute method:" +retrun);


boolean returnvalue= driver.findElement(By.id("usernameid")).isEnabled();
System.out.println("is enabled method :" +returnvalue);
 
boolean returnvalue1= driver.findElement(By.id("usernameid")).isDisplayed();
System.out.println("is displayed method :" +returnvalue1);
 //RADIO BUTTON IDENTIFICATION
  driver.findElement(By.name("radiobutton1")).click();
  driver.findElement(By.name("radiobutton2")).click();
  driver.findElement(By.name("radiobutton3")).click();

     
 //CHECKBOX IDENTIFICATION
driver.findElement(By.name("checkthebox")).click();

// SELECT DROP DOWN BOX 


  Select drp = new Select(driver.findElement(By.id("test")));
  drp.selectByVisibleText("Blue");
 
// SELECT MULTIPLE VALUES FROM LIST BOX   
   
  Select mullist = new Select(driver.findElement(By.name("dropdown")));
mullist.selectByVisibleText("Audi");
mullist.selectByVisibleText("Honda CRV");

     
//CLICK ON LINK
   driver.findElement(By.linkText("1.Yahoo")).click();
   Thread.sleep(2000);
  //NAVIGATE BROSER BACK
   driver.navigate().back();
       Thread.sleep(5000);
     
 // Relative XPATH  for Submit button
//    driver.findElement(By.xpath(".//input[@type='submit']")).click();
     
 // absloute path - html/body/font/p[1]/input
 
       driver1.findElement(By.xpath("html/body/table[6]/tbody/tr[2]/td[2]/input")).click();
 
             
 //CLOSE THE CURRENT BROWSER
       driver.close();
   
   
//CLOSE ALL OPENED BROWSERS
       driver.quit();

  }
  }


Handle Alerts, Iframes and Capture Text from webpage using Selenium Java

package Package;

//import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;


public class AzziAutomation
  {

public static void main (String[] args) throws InterruptedException
  {

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
 WebDriver driver = new ChromeDriver();   
String url ="http://www.xpr2t.com/Webobjects.html";

// Maximize the browser
driver.manage().window().maximize();

// Open the application in the browser
  driver.get(url);
//  driver.navigate().to(url);   ---- ANOTHER WAY OF PASSING URL
// Hard wait for 5 sec
// Thread.sleep(5000);      
     
     
//  MANAGET ALERT -  CLICK ON ALERT BUTTON
       driver.findElement(By.xpath("html/body/table[9]/tbody/tr/td/button")).click();  
// CAPTURING THE Alert Message            
     
  String alertMessage = driver1.switchTo().alert().getText();
   System.out.println(alertMessage);
//CLICK ON ALERT OK BUTTON
   driver1.switchTo().alert().accept();
//Click ON CANCEL BUTTON
   //driver.switchTo().alert().dismiss();
   Thread.sleep(5000);

// HANDLE TABLE - CAPTURE TEXT
 
 
String text1=  driver.findElement(By.xpath("html/body/table[10]/tbody/tr/td")).getText();
  System.out.println("Text value :"+text1);
   //another way of get text
 
//   WebElement tablevalue = driver.findElement(By.xpath("html/body/table[10]/tbody/tr/td"));
//System.out.println("Another approach cell value :"+tablevalue.getText());
   

   
//CLOSE THE CURRENT BROWSER
       driver.close();
   
   
//CLOSE ALL OPENED BROWSERS
       driver.quit();
 }
  }



//  Handle Iframes in Selenium Java

 3 Different ways to handle Iframes in Selenium Java.

               1.    switchTo().frame(index)
               2.    switchTo().frame(name)
               3.     switchTo().frame(WebElement)




package Package;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver.Options;
import org.openqa.selenium.WebDriver.Window;
import org.openqa.selenium.WebDriver.Options;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
//import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

//https://selenium.googlecode.com/git/docs/api/java/overview-summary.html
public class AzziAutomationProject
  {



public static void main (String[] args) throws InterruptedException
  {


//*************************** CHROME DRIVER *****************************

/  System.setProperty("webdriver.chrome.driver", "C:\\Ruby22-x64\\bin\\chromedriver.exe");
   WebDriver driver = new ChromeDriver();

 
   String url ="http://www.xpr2t.com/Webobjects.html";
// String url ="http://www.xpr2t.com/Webobjects.html";
// Maximize the browser
driver.manage().window().maximize();

//driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
   // Open the application in the browser
   // Open Url
  driver.get(url);
//  driver.navigate().to(url);


  // SWITCH TO  FRAME USING WEBELEMENT -xpath
  WebElement  iframe= driver.findElement(By.tagName("iframe"));

 driver.switchTo().frame(iframe);   

     driver.findElement(By.linkText("REGISTER")).click();
     Thread.sleep(5000);
     driver.switchTo().defaultContent();

  // SWITCH TO  FRAME USING INDEX
 
   driver.switchTo().frame(0);   
 
       driver.findElement(By.linkText("REGISTER")).click();
       Thread.sleep(5000);
       driver.switchTo().defaultContent();

 // SWITCH TO  FRAME USING NAME  - currently http://www.xpr2t.com/Webobjects.html doesn't have the name for the Iframe..
 
  //  driver.switchTo().frame(name );   
 
  //      driver.findElement(By.linkText("REGISTER")).click();
  //      Thread.sleep(5000);
  //      driver.switchTo().defaultContent();

//Get the no of Iframes in the application

  int size = driver.findElements(By.tagName("iframe")).size();
System.out.println(size);
 


       //CLOSE THE BROWSER
       driver.close();
       //CLOSE ALL BROWSERS
       driver.quit();

  }
  }







abcd


Monday, June 27, 2016

Strategy for Testing Web services and also SOA designed websites.



Hi everybody,

    I'd like to share the strategy for web service testing, it purely based on my testing exp with the web services.

Introduction :
 
Now a days most of the companies 

Wednesday, June 15, 2016

Selenium JAVA packages required for building the automation scripts


Selenium JAVA packages required for building the automation scripts


Sno
Package Name
Purpose
Example
1
import org.openqa.selenium.firefox.FirefoxDriver;
To invoke firefox driver

2
import org.openqa.selenium.chrome.ChromeDriver;
To invoke chrome driver

3
import org.openqa.selenium.ie.InternetExplorerDriver;
To invoke IE driver

4
import org.openqa.selenium.support.ui.Select;
To manage the drop down box and list box. Invoke select class and methods.

5
import org.openqa.selenium.interactions.Actions;
To manage keyboard and mouse operation. And invoke the actions class.

6
import org.openqa.selenium.*;
To manage Webelements, Alerts and Exceptions.

7
import java.util.concurrent.TimeUnit;
To manage implicit wait fucntions

8
import org.openqa.selenium.By;
To manage the findelement (By) method.

9
import org.testng.annotations.AfterTest
required for Test NG annotation - @AfterTest

10
import org.testng.annotations.BeforeTest;
required for Test NG annotation - @BeforeTest

11
org.testng.annotations.Test
required for Test NG annotation - @Test

12
import org.testng.annotations.AfterMethod
required for Test NG annotation - @AfterMethod

13
import org.testng.annotations.BeforeMethod;
required for Test NG annotation - @BeforeMethod

14
import org.openqa.selenium.Alert;
required to manage alerts

15
import org.openqa.selenium.TakesScreenshot;
Required for Screenshot

16
import org.openqa.selenium.OutputType;
Required for define outputtype in taking screenshot

17
import java.util.Properties;
Required for manage property files.

18
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Required for to use the excel(.xlsx) functions.

19
import java.io.File;
import java.io.FileInputStream;
Required for manage file operations( txt files,csv files)

20

import java.io.IOException;
Required for manage the exceptions.

21
import java.util.List;
Required for list.

22
import org.apache.commons.io.FileUtils;
Reuired for copyfile. Ex:FileUtils.copyFile

23

 import java.util.*;
 import java.text.*;
Required for Date and Dateformat.