Jul 1, 2015

Software Testing Learning Objectives

Software Testing Learning Objectives

Software Testing can be done in two ways
 

1) Manual Testing

2) Test Automation or Automated Testing

What is Manual Testing?

Testing Computer Software manually (without using any Tool)

What is Test Automation?

Testing Computer Software using any Test tool or program.
--------------------------------------
I) Manual Testing Learning Objectives

1) SDLC Models    
    Waterfall Model
    V Model
    Prototype Model
    Spiral Model
    Agile Methodologies (Scrum, XP etc...)

2) Software Test Levels    

    Unit/Component/Program Testing
    Integration Testing
    system Testing
    Acceptance Testing

3) Software Test Types    

   Functional Testing
   
    Functionality Testing
        Security Testing etc...
   Non-Functional Testing
   
    Performance /Load/Stress Testing
        Usability Testing
        Availability Testing
        Reliability Testing
        Maintainability Testing
        Portability Testing
        Documentation Testing
        Recovery Testing
        Internationalization Testing and Localization Testing
        Etc...

4) Test Design Techniques        

       White Box Test Design Techniques
        Black Box Test Design Techniques
        Experience Based Techniques

5) Software Test Process        

        Test Planning
        Test Design
        Test Execution
        Test Closure

6) Software Test Documents        

        Test Policy
        Test Strategy
        Test Plan
        RTM
        Test Case
        Defect Report
        Test Summary Report Etc...

7) Software Quality Standards        

        ISO
        CMM/CMMI
        IEEE
-----------------------------------------
II) Selenium Learning Objectives
 

1) Test Automation and Selenium Basics
    Overview on Test Automation
    ATLM (Automated Test Life Cycle Methodology) 
    Selenium Test Process
    Overview on Selenium
    Selenium Suite of Tools 
    Overview of Java for Selenium

2) Java for Selenium   
    Java Environment Setup
    Comments in Java 
    Java Data Types 
    Java Modifiers 
    Java Variables
    Java Operators
    String Handling in Java
    Java Conditional Statements 
    Java Loop Statements 
    Arrays in Java 
    Java Built in Methods 
    Java User defined Methods
    File and IO operations in Java
    Exception Handling in Java
    Inheritance
    Abstraction
    Polymorphism
    Encapsulation

3) Selenium WebDriver
    Selenium WebDriver Environment Setup
    WebDriver Environment Setup and Write 1st Test Case
    Element Locators in Selenium 
    WebDriver Methods
    Handle Elements in WebDriver
    Write Test Cases
    Cross Browser Testing 
    Enhancing WebDriver Test Cases  

4) Selenium IDE   
    Selenium IDE Download and Install
    Create and Execute Test Cases and Test Suites
    Enhance Test Cases

5) TestNG Framework Implementation   
    Install TestNG
    Create Multiple Test cases
    Executing one or more Programs using XML file
    Grouping Test Cases
    Data Driven Testing using DataProvider Annotation
    Parallel Test execution
-----------------------------------------
III) UFT (Formerly QTP) Learning Objectives
 

1) UFT Tool Fundamentals    
    Test Automation Fundamentals
    UFT Tool Fundamentals
    UFT Tool Features
    Software Test Process
    UFT Test Proces

2) Test Automation Using UFT
    Recording and Running Tests
    Types of Objects in UFT  
    Object Repository
    Object Identification Configuration
    Prerequisites for Generating Tests
    Keyword Driven Methodology
    Types of Statements in UFT Test
    Descriptive Programming
    Test Methods or Operations
    Inserting Checkpoints
    Inserting Output Values
    Inserting Transaction Points
    Parameterization
    Actions
    Synchronization  
    Environment Variables
    Debugging Tests
    Batch Testing
    Recovery Scenarios
    UFT Tool Administration
    Integrating UFT with ALM/QC

3) VBScript for UFT
    VBScript Fundamentals
    Adding Comments
    VBScript Data Types
    VBScript Variables
    VBScript Constants
    VBScript Operators
    VBScript Conditional Statements
    VBScript Loop Statements
    Built-in Functions
    User Defined Functions
    Regular Expressions
    File System Operations
    Excel Application Operations
    Database Operations
    Dictionary Object
    Error handling in VbScript
    VBScript Coding Conventions

4)  UFT Scripting
    Windows Scripting
    Web Scripting

5) Automation Framework Design and Implementation
    Test Planning
    Automation Framework Fundamentals
    Automation Framework Implementation
    Keyword Driven Framework
    Hybrid Framework
----------------------------------
IV) Quality Center / ALM Learning Objectives
  

    ALM Installation and Integration with UFT
    ALM Administration        

        Create/delete Domains
        Create/Delete Projects
        Create / Delete Users
        Track Project Status
    ALM/Quality Center
   
    Create/edit/Delete Requirements
        Create /edit/Delete Tests
        Map Tests with Requirements
        Execute Tests
        Report and Track defects
----------------------------------

Jun 28, 2015

Selenium for Beginners

Selenium Complete Reference

I) Selenium Fundamentals


What is Selenium?
 

Selenium is a Suite of Tools to automate Browsers, Selenium can automate Web Applications only, It doesn't automate Desktop Applications.

History of the Selenium Project
 

> Selenium first came to life in 2004 when Jason Huggins was testing an internal application at ThoughtWorks. He developed a Javascript library that could drive interactions with the page, allowing him to automatically rerun tests against multiple browsers.

> In 2006 an engineer at Google named Simon Stewart started work on a project he called WebDriver.

> In 2008, the whole Selenium Team decided to merge WebDriver and Selenium RC to form a more powerful tool called Selenium 2.

> Selenium RC is still being developed but only for maintenance.

Selenium License
 

All Selenium projects are licensed under the Apache 2.0 License, It is Open source anybody can download and use selenium suite(Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid) of tools with free of cost.

Note: Anybody can download and use Selenium components, but selling updated code is not permited.

Selenium Supporting Platforms and Environments
 

a) Operating Systems:
 

Microsoft Windows   
UNIX/ Linux
Macintosh
Apple OS X etc...

b) Browsers:  
 

Mozilla Firefox
Internet Explorer
Google Chrome
Safari
Opera etc...

c) Scripting/Programming:
 

Java
C#
Perl
Python
PHP
Ruby

d) Software Applications
 

> CUI based Applications (* It doesn't support)

> Desktop Applications (I-Tier and II-tier Applications) (* It doesn't support)

> Web Applications (It Supports)

> Mobile Applications (*Which have web forms) (It supports)

Selenium suite of tools or Selenium Components
 

a) Selenium IDE:
Selenium IDE, It is a tool for creating test cases.
It is a Firefox plugin and provides an easy-to-use interface for developing automated tests.

b) Selenium RC
Selenium RC solves the limitations of Selenium IDE. It supports various programming languages like Java, C#, PHP, Perl, Python and Ruby languages to achieve logic required in test cases like conditional statements, iterations, exception handling, test reporting, database testing, capturing screen shots of failed tests, test case grouping etc...

c) Selenium WebDriver
The biggest change in Selenium recently has been the inclusion of the WebDriver API. Selenium WebDriver fits in the same role as RC did.

WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API.

d) Selenium Grid
Selenium Grid allows you to run your tests in parallel, that is, different tests can be run at the same time on different remote machines.

Advantages of Selenium


> It is Open source Software, no license cost, anybody can download and use with free of cost.


>
Selenium was first written in Java but it also supports C#, Ruby, Perl, PHP and Python. This is a big plus when we want to build our framework in a language that has the highest adoption in the organization it is being built within. Tools like UFT / QTP force you to use VBScript – which is almost never the preferred scripting language for developers.

>    It has support for all of the popular browsers like IE, Firefox, Chrome, Safari etc. It also supports several Operating Systems and that makes it a tool of choice for cross browser/ cross platform certification.


>    Once you get Selenium to work for you, it works reliably when used for running the tests over and over again. It’s definitely a lot more reliable than tools like QEngine or JExplorer but about the same as tools like UFT / QTP.


>    You can instantiate several concurrent tests (Parallel Test execution) with Selenium Grid.  


Disadvantages of Selenium
 

> Supports Web based (Browser based) Application only, doesn't support Desktop or standalone Application test automation.

> Since it is Open source software, no reliable technical support from anybody.

> No centralized maintenance of Elements (Objects)

> Limited support for Image testing.

> Some new features may or may not work properly.

> Deploying Selenium Tool is difficult than UFT (Formerly QTP) Tool.

II) Java for Selenium

III) Selenium WebDriver


Selenium WebDriver Introduction:
 

> Selenium 1.0 (Selenium IDE + selenium RC + Selenium Grid)

> Selenium 2.0 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)
 

Note: Selenium WebDriver merged with Selenium 1.0

> It is a most important tool in Selenium suite.

> It is has programming interface allows us to create and execute Test cases against different browsers (ex: Firefox, IE, Google Chrome etc...)

> WebDriver supports various programming languages to enhance Test cases.
Java
.NET
PHP
Perl
Python
Ruby

> WebDriver supports various operating environments to create and execute Test cases(Ex: MS Windows, UNIX and Macintosh etc...)

> WebDriver supports Data Driven testing, cross browser testing.

> Webdriver is faster than other tools of Selenium suite.

> WebDriver supports Parallel test execution with the help of TestNG.

> WebDriver doesn't have IDE, only Programming interface.

> WebDriver doesn't have built in Result reporting facility, it provides summary only.(* with the help of TestNG we can generate HTML test reports.)

> No object Repository in selenium WebDriver (It is for entire Suite), so no centralized maintenance of Objects)


Using Element locators, Webdriver methods and Java programming features we can create and execute Test cases.

Element Locators - to recognize / identify Elements (Objects)

Webdriver Methods - to perform operations on Elements.

Java programming features - for Enhancing Test Cases.

Selenium Webdriver Environment Setup:
 

> Download and install Java (JDK) software - to enhance test cases using Java programming features.

> Set Path environment variable- to access Java from any directory.

> Download Eclipe IDE and extract

> Download WebDriver Java Language binding and add Webdriver jar files (in Eclipse)


>  Install Firebug and FirePath plug ins for Mozilla Firefox browser to inspect Elements.

Note 1: For Internet explorer and Google chrome, no need to install any plug ins, They have built in Developer tools.

Note 2: Element locators and WebDriver methods are common for all browsers, browser driver only varies from one browser to another.

Note 3: Firefox driver is default driver in Webdriver, For IE and Chrome we need to download drivers.


Download Selenium WebDriver Java binding from www.seleniumhq.org website and extract.

Navigation for adding Webdriver jar files in Eclipse.
 

> Create Java project

> Select src and right click

> Build path

> Configure Build Path

> select Libraries tab

> Click "Add External JARs

> Browser path of the WebDriver jars

> Add

Pre-requisites to Create Automated Tests / Test Scripts / Test Cases
 


> Import WebDriver Libraries and Firefox driver/IE driver/Chrome Driver

> Using Web Element (object) locators and WebDriver methods write object call statements

> Insert Java programmatic statements to enhance Test cases.


Element Locators 
 

Selenium supports 8 element locators to identify objects/elements on web pages.

We can use any one unique locator to identify elements.

1) id
2) name
3) classname
4) tagName
5) linkText
6) partialLinkText
7) cssSelector
8) xpath


IV) TestNG Framework


TestNG Introduction
 

> In Selenium using Java there are two Automation frameworks available:

i) JUnit

ii) TestNG

> TestNG is more powerful than JUnit framework.

> TestNG is an open source test automation framework, where NG stands for Next Generation

> TestNG inspired from JUNit but introduced some new functionality.

Benefits of TestNG:
 

> It generates HTML test reports

> TestNG Annotations are easy to create Test cases.

> Test cases can be grouped and prioritized more easily.

> Parallel Testing is possible

> Parameterization is possible.

Note: Using TestNG we can create Test cases, execute Test cases and generate reports in HTML format.

Install TestNG:
 

In Eclipse IDE,

Help menu -> Install New Software -> Click Add

-> Enter Name as "TestNG"

-> Enter URL as "http://beust.com/eclipse/"

-> Select TestNG

-> Next -> Next -> Accept the Agreement -> Finish

A Sample TestNG Program
 

public class SampleTest {
    @Test
    public void verifyTitle()
    {
    WebDriver driver = new FirefoxDriver();
    driver.get("http:/www.gmail.com");
    String Actual = driver.getTitle();
    Assert.assertEquals(Actual, "Gmail");
    }
    }
Create Multiple Test cases in a Program/Class
 

TestNG test cases can be executed in alphabetical order, if you want to control the Test execution then use Attributes.

public class SampleTest {
    @Test
    public void testA()
    {
    Assert.assertEquals("Google", "Google");
    }
    @Test
    public void testC()
    {
    Assert.assertEquals("Gmail", "Google");
    }
    @Test
    public void testB()
    {
    Assert.assertEquals("Yahoo", "Yahoo");
    }
    }
TestNG Annotations
 

@Test

@BeforeMethod
@AfterMethod

@BeforeClass
@AfterClass

@BeforeTest
@AfterTest

@BeforeSuite
@AfterSuite

@DataProvider

@BeforeGroups
@AfterGroups

@Parameters

@Factory

@Listeners

V) Selenium IDE

Selenium IDE Introduction:
 

> Selenium IDE (Integrated Environment) is a Tool, used to develop Selenium Test Cases.

> It is Firefox plug in, works only on Firefox Browser.

> It provides Graphical user interface for Recording user actions using Firefox Browser.

> Firebug Add on is used to inspect elements.

> Selenium IDE should only be used as a prototyping tool.
Note: We can't develop complex Test cases using Selenium IDE.

Test Step in Selenium IDE Test Case
 

Test Step Syntax:

Command + Target + value

Command - forms the functionality of the Test step

Target - Identifies the Element on the web page.

Value - Input data (This applicable only for few commands)

Example:

Type     id=Email     abcd123

Download Install Selenium IDE
 

> Using Firefox browser, download selenium IDE from the Seleniumhq.org website.

> Firefox will protect you from installing add ons from unfamiliar locations, so we  will need to click "Allow" to proceed with the installation.

> Install multiple items to support Java, Ruby, Python etc... formats.

> Restart Firefox browser.

> After Firefox reboots then we can use Selenium IDE.

Features of Selenium IDE
 

Using Selenium IDE, we can,

> Create Test cases and Test suites

> Open existing Test case

> Run Test case and Run Test suite.

> Export Test case in a Language of our choice.

> Debug Test cases.

> Add Comments, Insert verification points.
Etc...

Drawbacks of Selenium IDE
 

> It supports Firefox Browser only, so cross browser testing is not possible.

> No Flow control statements (Conditions and Loops)

> Parametrization is not possible.

> Not suitable for creating complex Test cases.

> Doesn't provide detailed test reports, provides summary only.

> No Object Repository, so no centralized maintenance of Objects(Elements)

Create Test cases in Selenium IDE
 

By Recording Or Type steps using Selenese commands and element locators.

Difference between "assert" and "verify" Commands
 

> When an "assert" command fails then test execution will be aborted.

> When a "verify" command fails then test will continue execution and logging the failure.

VI) Selenium Grid 


Selenium Grid Introduction:
 

> Selenium Grid is part of the Selenium project.

> Using Selenium Grid we can distribute test execution across several machines.

> There are two main elements to Selenium Grid -- a hub, and nodes.

> First we need to stand up a hub, and then you can connect (or "register") nodes to that hub. Nodes are where your tests will run, and the hub is responsible for making sure your tests end up on the right one (e.g., the machine with the operating system and browser you specified).

Jun 25, 2015

Selenium Download

Selenium Downloads
 

Selenium is a suite of tools to automate Browsers, and it is free Software released under the License of Apache 2.0

Java Software Link


(If you want to use Java for Selenium, Download and install Java (JDK), Set Path Environment Variable for accessing Java from any directory.)

How to set Path Environment Variable (For Windows 7):
Select Computer icon on Desktop and Right click

> Properties

> Advanced System Settings

> Environment Variables

> Select New in System Variables

> Enter Variable as Path

> Enter Jdk bin directory path (C:\Program Files\Java\jdk1.8.0_40\bin) in Value field

> Ok > OK >OK

------------------------------------------------  
Eclipse IDE Link

(Eclipse IDE also Open source software used to write and execute Java Programs. Download Eclipse and extract the Software, no need to install, you can launch Eclipse IDE using Eclipse file in Eclipse directory)
---------------------------------------------------------------- 
Selenium IDE Link

(It is Firefox browser Add on, Download and Install, then Restart Firefox browser.)
--------------------------------------------------------
Firebug  Link



(It is Firefox browser Add on or Plug in to inspect elements.
Note: For Internet Explorer and Google chrome you no need to install any plug in for inspecting elements, they have built in Developer tools (shortcut key: F12))
-----------------------------------------------------------
 Firepath Link

(It is also Firefox browser Add on or Plug in to find xpath for elements.)
---------------------------------------------------------------
Selenium WebDriver 

(Download Webdriver Language bindings from seleniumhq.org website and add Webdriver files in Elispse IDE)

Navigation for adding Webdriver jar files in Eclipse:
 
Create Java project
> Select src and right click
> Build path
> Configure Build Path
> select Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
 

-------------------------------------------------------------- 
Internet Explorer Driver

(If you want to execute Selenium Test cases using Internet Explorer browser the download IE driver and set path)

Example:
System.setProperty("webdriver.ie.driver", "E:/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
 

--------------------------------------------------------- 
Google Chrome Driver

(If you want to execute Selenium Test cases using Google Chrome browser the download Chrome driver and set path)

Example:
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = new ChromeDriver();

---------------------------------------------------------
 TestNG

(TestNG Framework for creating and grouping test cases, parallel test case execution, test batch execution and generating HTML test reports.) 

How to Install TestNG:
In Eclipse IDE,

Help menu -> Install New Software -> Click Add

-> Enter Name as "TestNG"

-> Enter URL as "http://beust.com/eclipse/"

-> Select TestNG

-> Next -> Next -> Accept the Agreement -> Finish

----------------------------------------------------------------
Selenium Grid


(If you want to execute Selenium Test cases in parallel then configure Selenium grid.)
------------------------------------------------------------

Selenium Tutorial 8

Selenium Tutorial 8

Recap:
1) Overview on Test Automation

2) Overview on Selenium

3) Selenium Test Process

4) Java for Selenium
--------
5) Java Environment setup

6) Java program structure/Java Syntax

7) Writing comments

8) Java Data types

9) Java Modifiers

10) Java Variables

11) Java Operators

12) Java Conditional statements

13) Java Loop statements

14) String handling in Java

15) Arrays in Java

16) Java Methods - Built-in methods

17) Java Methods - User defined methods

18) Java exception handling
---------------------------------------
Input and Output Operations in Java.
There are three ways available for reading input:
i) Scanner

ii) DataInputStream

iii) BufferedReader
---------------
Using java.util.Scanner is the easier and includes many methods to check input data is valid to read.

Example:
package javaiooperations;
import java.util.Scanner;
public class ReadInput {
public static void main(String [] args){
    Scanner scan = new Scanner(System.in);
   
    System.out.println("Enter Your Name");
    String s1 = scan.nextLine();
    System.out.println("Your Name is: " + s1);
   
    System.out.println("Enter Your City Name");
    String s2 = scan.next();
    System.out.println("Your City Name is: " + s2);
   
    System.out.println("Enter Your Number");
    int a = scan.nextInt();
    System.out.println("Your Number is: " + a);
   
    System.out.println("Enter Your City Name");
    double b = scan.nextDouble();
    System.out.println("Value is: " + b);
    scan.close();
}
}
-------------------------------------------
File handling in Java
Two categories of File System Operations

i) High level operations / External operations

Create a folder

delete a folder

create a text file

delete a text file etc...

ii) Low level operations / Internal operations

Read data

Write data etc...
------------------------
Using File Class we can perform High level operations

Examples:
1) Create a Folder
package javaiooperations;

import java.io.File;

public class CreateFolder {
   
    public static void main(String [] args){
        File fileObject = new File("C:/Users/G C Reddy/Desktop/Selenium");
        fileObject.mkdir();
        }
}
---------------------------------
2) Check the existence of Selenium Folder


public static void main(String [] args){
        File fileObject = new File("C:/Users/G C Reddy/Desktop/UFT");
        boolean a = fileObject.exists();
        System.out.println(a);
        }
-------------------------------------
3) Delete a Folder
public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium");
        abc.delete();
        boolean a = abc.exists();
        //System.out.println(a);
        if (a == true) {
            System.out.println("Folder exists");
        }
        else{
            System.out.println("Folder doesn't exist");   
        }
        }
-----------------------------------
4) Create a Text file
public class CreateFolder {
   
    public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium.txt");
        try {
            abc.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
-------------------------------------------
5) Delete a text file


    public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium.txt");
        abc.delete();
       
    }
------------------------------------               
Java OOPS
Inheritance

Polymorphism

Abstraction

Encapsulation
-------------------------------------------
Java Inheritance
> It is a process of inheriting (reusing) the class members 9variables and methods) from one class to another class is called Inheritance.

> Non static (object level) class members only can be inherited.

> The class from where the class members are getting inherited is called as Super class/ Parent class/base class

> The class to which the class members are getting inherited is called
Sub class/ Child class / Derived class.

> The Inheritance between Super class and Sub class is achieved using "extends" keyword.

Syntax:

Class SubClass extends SuperClass {
//body
}
They are three types of Inheritance:

i) Single Inheritance
Ex:

Class B extends Class A
---------------------------
ii) Multi level inheritance:
Ex:

Class B extends Class A

Class C extends Class B

iii) Multiple Inheritance (*Java doesn't support)

Ex:

Class B extends Class A

Class C extends Class B

In Class C
add method
-----------------------------
Class C extends Class D
-------------------------------

Selenium Tutorial 7

Selenium Tutorial 7

Java User defined Methods:
Creating methods with returning value and without returning value.

Calling Internal and external methods

Method Overloading:
If a Class have multiple methods with same name, but with different parameters, then it is known as Method overloading.

There are two ways to overload the method in Java.

i) By changing number of Arguments
Example: We have two methods in our class with the name of add.

a) int add(int a, int b)

b) int add(int a, int b, int c)
-----------------------------
ii) By changing data types.
a) int add (int a, int b)

b) double add (double a, double b)
--------------------------------------
Example:package Saturday;

public class JavaMetods {
    public static void main (String [] args){
        int x = add(5, 9);
        int y = add (5, 7, 9);
        double z = add(5.234, 6.123);
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
    }
    public static int add (int a, int b){
        int result;
        result = a + b;
        return result;
    }
    public static int add (int a, int b, int c){
        int result;
        result = a + b + c;
        return result;
    }
    public static double add (double a, double b){
        double result;
        result = a + b;
        return result;
    }
}
-------------------------------------
Advantages of Method overloading
It increases the readability of the Program.
----------------------------------------------
Java Built in Methods
Categories of Built in methods:
a) Number methods
b) Character methods
c) String methods
d) Array methods etc...
------------------------------
a) Number methods
1) compareTo() method

Example:
Integer a = 5;
        System.out.println(a.compareTo(8)); //-1
        System.out.println(a.compareTo(5));//0
        System.out.println(a.compareTo(2));//1

Result Criteria:

if the integer is equal to the argument then 0
if the integer is less than the argument then -1
if the integer is greater than the argument then 1
-----------------------------------
2) equals() method

Integer a = 5;
        Integer b = 10;
        Integer c = 5;
        Short d = 5;
        System.out.println(a.equals(b));//false
        System.out.println(a.equals(c)); //true
        System.out.println(a.equals(d)); //false
--------------------------------------
3) abs (Returns Absolute value)

Example:

Integer a = -5;
        double b = -10.234;
       
        System.out.println(Math.abs(a));// 5
        System.out.println(Math.abs(b));// 10.234

----------------------------------------------
4) round (Rounds the value nearest Integer)

Example:
double a = 10.575;
        double b = 10.498;
       
        System.out.println(Math.round(a));// 11
        System.out.println(Math.round(b));// 10

-----------------------------------------
5) min (Returns minimum value between two numbers)

Example:

int a =10, b =20;
        double c = 1.234, d = 3.567;
        System.out.println(Math.min(a, b)); // 10
        System.out.println(Math.min(c, d)); // 1.234
        System.out.println(Math.min(123, 124)); // 123
        System.out.println(Math.min(10.345, 10.3451)); // 10.345
        System.out.println(Math.min(1, 1)); // 1
-----------------------------------------
6) max (Returns maximum value between two numbers)

Example:
int a =10, b =20;
        double c = 1.234, d = 3.567;
        System.out.println(Math.max(a, b)); // 20
        System.out.println(Math.max(c, d)); // 3.567
        System.out.println(Math.max(123, 124)); // 124
        System.out.println(Math.max(10.345, 10.3451)); // 10.3451
        System.out.println(Math.max(1, 1)); // 1
-------------------------------
7) random (Generates Random Number)

Example:
System.out.println(Math.random()); //
System.out.println(Math.random()); //
---------------------------------------------
b) Character methods
1) isLetter (Checks weather the value is Alfa byte or not?)

Example:
        char a = '1';
        System.out.println(Character.isLetter(a)); //false
        System.out.println(Character.isLetter('A'));//true
        System.out.println(Character.isLetter('a'));//true
        System.out.println(Character.isLetter('*'));//false
--------------------------------
2) isDigit (It returns weather the value is Number or not?)

        char a = '1';
        System.out.println(Character.isDigit(a)); //true
        System.out.println(Character.isDigit('A'));//false
        System.out.println(Character.isDigit('a'));//false
        System.out.println(Character.isDigit('*'));//false
        System.out.println(Character.isDigit('7')); //true
-----------------------------------------------
3) isUppercase (Checks weather the value is Upper case or not?)

example:
System.out.println(Character.isUpperCase('C'));//true
System.out.println(Character.isDigit('z')); //false
-------------------------------------
4) isLowercase (Checks weather the value is Lower case or not?)

Example:
System.out.println(Character.isLowerCase('C'));//false
System.out.println(Character.isLowerCase('z')); //true
------------------------------
5) toUppercase (Converts the value to Upper case)

Example:
System.out.println(Character.toUpperCase('a'));//A
System.out.println(Character.toUpperCase('A')); //A
-----------------------------------
6) toLowercase (Converts the value to Lower case)

Example:
System.out.println(Character.toLowerCase('a'));//a
System.out.println(Character.toLowerCase('A')); //a
-------------------------------------------------------
c) String methods
1) compareTo() method (It compares two strings)

Example:
String str1 ="SELENIUM";
        String str2 ="selenium";
        String str3 ="seleniuma";
        String str4 ="selenium";
        int result;
        result = str1.compareTo(str2);
        System.out.println(result); //
       
        result = str3.compareTo(str2);
        System.out.println(result); //
       
        result = str2.compareTo(str4);
        System.out.println(result); //
-------------------------------------
2) charAt (character by position)

String str1 ="SELENIUM";
        char result = str1.charAt(0);
        System.out.println(result); //S
               
-------------------------
3) concat (String concatanation)

String str1 ="Selenium";
        String str2 = " Java";
        str1 = str1.concat(str2);
        System.out.println(str1);

-----------------------------
4) equals (String equals)

Example:
String str1 ="Selenium";
        String str2 = "UFT";
        String str3 ="Selenium";
       
        System.out.println(str1.equals(str2)); //false
        System.out.println(str1.equals(str3));     //true   
-----------------------------
5) equalsIgnorecase

Examples:
String str1 ="selenium";
        String str2 = "UFT";
        String str3 ="SELENIUM";
        String str4 ="SELENIUM";
       
        System.out.println(str3.equalsIgnoreCase(str4)); //true
        System.out.println(str1.equalsIgnoreCase(str3)); //true   
        System.out.println(str1.equalsIgnoreCase(str2)); //false
-----------------------------------------------
6) toUppercase (Converts values To Upper case)

Example:
String str1 ="selenium";
        String str2 ="SELEnium";
        String str3 ="SELENIUM";
       
        System.out.println(str1.toUpperCase());
        System.out.println(str2.toUpperCase());
        System.out.println(str3.toUpperCase());
-------------------------------------
7) toLowercase (Converts values To Lower case)

String str1 ="selenium";
        String str2 ="SELEnium";
        String str3 ="SELENIUM";
       
        System.out.println(str1.toLowerCase()); //selenium
        System.out.println(str2.toLowerCase()); //selenium
        System.out.println(str3.toLowerCase()); //selenium
---------------------------------------------
8) trim (removes spaces from both sides of a String)

Example:

String str1 ="           Selenium              ";
        String str2 ="               SELEnium";
        String str3 ="SELENIUM                ";
       
        System.out.println(str1);
        System.out.println(str1.trim());
        System.out.println(str2.trim());
        System.out.println(str3.trim());
---------------------------------------------
9) substring (Returns sub string)

Example:
String str1 ="Welcome to Selenium Testing";
       
        System.out.println(str1.substring(10)); // Selenium Testing
        System.out.println(str1.substring(19)); //Testing
        System.out.println(str1.substring(10, 18)); //Selenium
------------------------------------------------
10) endsWith (ends with specified suffix)

Example:
-----------
String str1 = "Selenium Testing";
       
        System.out.println(str1.endsWith("Testing"));//true
        System.out.println(str1.endsWith("ing"));//true
        System.out.println(str1.endsWith("Selenium"));//false
--------------------------------------------------
d) Array methods
1) length method

int [] array1 = {10, 20, 30, 40, 50};
System.out.println(array1.length);//5
-------------------------------------
2) toString() (print Array)

String [] arr1 ={"UFT", "Selenium", "RFT", "SilkTest"};
        String str = Arrays.toString(arr1);
        System.out.println(str);

--------------------------------------
3) contains (Checks if the Array contains certain value or not?)

String [] arr1 ={"UFT", "Selenium", "RFT", "SilkTest"};
        boolean a = Arrays.asList(arr1).contains("UFT");
        boolean b = Arrays.asList(arr1).contains("uft");
        System.out.println(a);// true
        System.out.println(b);// false
----------------------------------------------------------
Exception Handling in Java
> An Exception is an event, it occurs during execution of a program,
when normal execution of the program is interrupted.

> Exception handling is mechanism to handle exceptions
--------------------------
Common Scenarios where exceptions may occur:------------------------------------------------
1) Scenario where ArithmeticException occurs
If we divide any number by Zero there ArithmeticException occurs

Ex:

int a = 10/0;
----------------------------------------------
2) Scenario where NullPointerException occurs
if we have null value in any variable, performing any operation by the variable,

ex:

String s = null;
System.out.println(s.length());//NullPointerException
---------------------------------------------------
3) Scenario where NumberFormatException occurs
The wrong formatting of any value, may occur  NumberFormatException

Ex:
String s = "abc";
        int y = Integer.parseInt(s);
        System.out.println(y);//NumberFormatException
--------------------------------------
4) Scenario where ArrayIndexOutOfBounds exception occurs
If we are inserting any value in the wrong index

Ex:
int [] a = new int [5];
        a[10] = 100;
        System.out.println(a[10]);//ArrayIndexOutOfBounds
--------------------------------------------------------------
Example:
int a =10;
        int b = 0;
        int result;
        result = a/b;
        System.out.println(result);
        System.out.println("Hello Java");
        System.out.println("Hello Selenium");
----------------------------------
Use try block:
Syntax:
--------
try {
Statements
------
-------
------
}
catch (exception e) {
Exception handling code
}
-----------------------------------
With Exception handling

int a =10;
        int b = 0;
        int result;
        try{
        result = a/b;
        System.out.println(result);
        }
        catch (ArithmeticException e){
        System.out.println("Divided by Zero Error");   
        }
        System.out.println("Hello Java");
        System.out.println("Hello Selenium");
        }
--------------------------------------
Multiple try blocks for handling multiple exceptions
Example:
int a =10;
        int b = 0;
        int result;
        int [] array1 = new int [4];
        try{
        result = a/b;
        System.out.println(result);
        }
        catch (ArithmeticException e){
        System.out.println("Divided by Zero Error");   
        }
       
        try{
            array1[10]= 100;
            System.out.println(array1[10]);
        }
        catch (ArrayIndexOutOfBoundsException e){
            System.out.println("Array Out of Bound Error");
        }
        System.out.println("Hello Java");
        System.out.println("Hello Selenium");
        }
---------------------------------------

Jun 24, 2015

Selenium Tutorial 6

Selenium Tutorial 6

Java Loop Statements
a) for..Loop
b) while...Loop
c) do while...Loop
d) enhanced for...Loop
--------------------------
a) for..Loop
It repeats a block of statements for a specified number of times

Syntax:

for (stratValue; endvalue; increment/decrement) {
Statements
----------
------------
----------
}

Example 1:

// Print 1 to 10 Numbers using for loop
    for (int i = 1; i <= 10; i++){
        System.out.println(i);
    }
-------------------------
Example 2:
// Print 10 to 1 Numbers using for loop
    for (int i = 10; i >= 1; i--){
        System.out.println(i);
    }
---------------------------
Example 3:
// Print 1 to 10 numbers except 7
    for (int i = 1; i <= 10; i++){
        if (i != 7){
        System.out.println(i);
        }
    }
---------------------------------
b) while loop
It repeats a block of statements while condition is true.

Syntax:

Initialization
while (condition) {
Statements
------------
-----------
increment/decrement
}

Example 1:
// Print 1 to 10 numbers using while loop
    int i = 1;
    while (i <= 10){
        System.out.println(i);
        i++;
        }
---------------------------------
example 2:

// Print 10 to 1 numbers using while loop
    int i = 10;
    while (i >= 1){
        System.out.println(i);
        i--;
        }
-------------------------------------------
c) do while loop
It repeats a block of statements while condition is true,
It executes a block of statements at least once irrespective of the condition.

Syntax:
Initialization
do
{
Statements
------
---------
increment/decrement
} while (condition);

Example:
---------------
// Print 1 to 10 numbers using do while loop
    int i = 1;
    do
    {
    System.out.println(i);
    i++;
    } while (i <=10);
-----------------------------
int i = 100;
    do
    {
    System.out.println(i);
    i++;
    } while (i <=10);

-------------------------------------
d) Enhanced for...loop
It executes all elements in an Array

Syntax:

Array declaration

for (declaration: expression/Array){
Statements
-------
}

--------------------------------
Example:

String [] languages = {"C", "COBOL", "Java"};
   
    for (String lang: languages){
        System.out.println(lang);
    }
-----------------
Example 2:
----------------
int [] mathoperations = new int [3];
    int a =10, b= 20;
    mathoperations[0] = a + b;
    mathoperations[1] = a - b;
    mathoperations[2] = a * b;
   
    for (int operation: mathoperations){
        System.out.println(operation);
    }
------------------------------------------------
String Handling in Java
What is String?
String is a sequence of characters written in double quotes.

String may have Alfa bytes, numbers and special characters.

Example:

System.out.println("Selenium Testing"); //Selenium Testing
System.out.println("123 Selenium Testing");//123 Selenium Testing
System.out.println("Selenium*&123 Testing");//Selenium*&123 Testing
-------------------   
Creating Strings
String is considered as object in Java.

Example:

String myTool = "Selenium"; //String variable
    String [] myTools = {"UFT", "Selenium", "LoadRunner", "Quality Center"};// Array of Strings
   
    System.out.println(myTool); //Selenium
   
    for (String tool: myTools){
        System.out.println(tool);
    }
-----------------------------
for (int i = 0; i < myTools.length; i++){
        System.out.println(myTools[i]); // Print Array of strings
    }
-----------------------------------------
Concatenating Strings
String str1 = "Selenium";
    String str2 = " Testing";
    System.out.println(str1 + str2); // Selenium Testing
    System.out.println("Selenium" + " Testing"); // Selenium Testing
    System.out.println(1 + 1 + "Selenium"); // 2Selenium
    System.out.println("Selenium" + 1 + 1); // Selenium11
    }
---------------------------------
String comparison
a) String comparison using (==) Operator

    It supports 2-way comparison (true or false)

b) String comparison using equals() method

    It supports 2-way comparison (true or false)

c) String comparison using compareTo() method

    It supports 3-way comparison (0, > 1 and <1)
    If Str1 = str2 then 0
    If str1 > str2 then > 0
    If str1 < str2 then < 0

-----------------------------------------
Example:
String str1 = "selenium";
    String str2 = "SELENIUM";
    String str3 = "SELENIUM";
    String str4 = "zselenium";
   
    // String comparison using == Relational Operator
    System.out.println(str1 == str2); // false
    System.out.println(str2 == str3); // true
   
    // String comparison using equals method
    System.out.println(str1.equals(str2)); // false
    System.out.println(str2.equals(str3)); // true
   
    // String comparison using compareTo() method
    System.out.println(str1.compareTo(str2)); // Greater than 1 (Positive)
    System.out.println(str2.compareTo(str3)); // 0
    System.out.println(str1.compareTo(str4)); // less than 0 (Negative value)
---------------------------------   
Java Arrays
Java Array is an Object that holds a fixed number of values of a single data type.

The length of an Array is established whe the Array is created.

Array length is fixed, java Array has zero based index.
--------------------------------------
Declaration of Arrays
1st method
int abc []; //Creating Array
    abc = new int [4]; // Defining size
   
    abc[0] = 10; // Assigning values
    abc[1] = 20;
    System.out.println(abc[0] + abc[1]); //30
-----------------------------
2nd method

int [] xyz = new int [5];
   
    xyz[0] = 10; // Assigning values
    xyz[1] = 20;
    System.out.println(xyz[1] + xyz[2]); //20
------------------------------
3rd method:

int [] xyz = {10, 20, 30, 40, 50};
   
System.out.println(xyz[1] + xyz[2]); //50
--------------------------------------------
Creating different types of Arrays
char [] abc = {'A', 'B', 'C', 'd'}; //Array of Characters
    int [] xyz = {10, 20, 30, 40}; // Array of Integers
    String [] a = {"Selenium", "UFT", "LoadRunner"}; //Array of Strings
    boolean [] b = {true, false, false, true}; //Array of Boolean values
   
    System.out.println(abc [1]); //B
    System.out.println(xyz [2]);//30
    System.out.println(a [1]); //UFT
    System.out.println(b [1]); // false
-------------------------------------------------
Copy values an Array into another Array
int [] array1 = {1, 2, 3, 4, 5};
    int [] array2;
    array2 = array1;
    System.out.println(array2[1]); // 2
   
    for (int i=0; i < array2.length; i++){
    System.out.println(array2[i]);
    }
--------------------------------------------------
Types of Arrays
Two types of Arrays

i) Single dimensional Array

ii) Multi dimensional Array

Ex:
int [] array1 = {1, 2, 3, 4, 5}; // Single dimensional Array
    int [] [] array2 = {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}; //Multi dimensional Array
   
    System.out.println((array2[0][0]));//1
    System.out.println((array2[1][0]));//2
    System.out.println((array2[0][4]));//9
    System.out.println((array2[1][3])); //8
Assignment:
print Multi dimensional array values using nested for loop.
------------------------------------------------------
Advantages of Arrays
> Using Arrays we can optimize the code, data can be retrieved easily

> we can get required data using index position.
-----------------------------
Disadvantages of Arrays
We can store fixed number of elements only
It doesn't change its size during execution.
-----------------------------------------
Java Methods
What is Method?

A set of statements to perform an Operation.

Methods are also known as procedures or functions.

In structured programming we use functions (Built in and user defined)

In Object Oriented programming we use Methods (Built in and user defined)

Usage of Methods:
---------------------
Whenever we want to perform operations several times then we prefer methods.

Using methods we can reduce the code size.

Types of Methods:
Basically we have two types of methods in Java.

i) Built in methods

ii) User defined methods
-----------------------------------------
Built in Methods:
> Java has a library of classes and methods, organized in packages.

> In order to use built in methods, we import pre-defined packages/particular classes.

> java.lang package is automatically imported in any java program.

> Using import keyword we can import pre-defined packages.
-------------------------------
Categories of Built in methods:
a) String Methods

b) Character methods

c) Number methods

d) Array methods etc...
--------------------------------------
User defined methods in Java:
Two types of user defined methods:

i) Method without returning any value

ii) Method with returning a value.
--------------------------------------
Writing Methods (With Returning value)
Syntax:

modifier returnType methodname (parameters) {
Statements
----------
----------
}

Example:

public static int add (int a, int b){
        int result;
        result = a + b;
        return result;
    }

--------------------
calling a Method

dataType variablename = Method(Values)
----------------------------------
Example:
int a = add(123, 456);
    System.out.println(a);
--------------------------------------
Example 2:

public static void main (String [] args){
    int a = xyz(2, 4, 6);
    System.out.println(a);
    }

// Write a method to multiply 3 numbers

    public static int xyz (int a, int b, int c){
        int result;
        result = a * b * c;
        return result;
    }
----------------------------------------------
Method without returning any value
Syntax:

modifier methodName(Parameters){
Statements
----------
---------
}

Example:
public static void main (String [] args){
    studentRank(700);
    }
public static void studentRank(int marks){
    if (marks >= 600){
        System.out.println("Rank A1");
    }
        else if (marks >= 500){
            System.out.println("Rank A2");
        }
            else {
                System.out.println("Rank A3");
    }
    }
---------------------------------------
// Calling a method from another class (External Method)
public class SeleniumClass extends ArrayExamples {
    public static void main (String [] args){
        studentRank(650); // External method
    }
-------------------------------------

Jun 23, 2015

Overview of Selenium WebDriver


Overview of Selenium WebDriver

Selenium 1.0 (Selenium IDE + selenium RC + Selenium Grid)

Selenium 2.0 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)

Note: Selenium WebDriver merged with Selenium 1.0
-------------------------------------------------
Selenium WebDriver Introduction:
> It is a most important tool in Selenium suite.

> It is has programming interface allows us to create and execute Test cases against different browsers (ex: Firefox, IE, Google Chrome etc...)

> WebDriver supports various programming languages to enhance Test cases.

Java
.NET
PHP
Perl
Python
Ruby
-----------
> WebDriver supports various operating environments to create and execute Test cases
(Ex: MS Windows, UNIX and Macintosh etc...)

> WebDriver supports Data Driven testing, cross browser testing.

> Webdriver is faster than other tools of Selenium suite.

> WebDriver supports Parallel test execution with the help of TestNG.

> WebDriver doesn't have IDE, only Programming interface.

> WebDriver doesn't have built in Result reporting facility, it provides summary only.
(* with the help of TestNG we can generate HTML test reports.)

> No object Repository in selenium WebDriver (It is for entire Suite), so no centralized maintenance of Objects)
---------------
Using Element locators, Webdriver methods and Java programming features we can create
and execute Test cases.

Element Locators - to recognize / identify Elements (Objects)

Webdriver Methods - to perform operations on Elements.

Java programming features - Enhancing Test Cases.
--------------------------------------------
Selenium Webdriver Environment Setup:
i) Download and install Java (JDK) software - to enhance test cases using Java programming features.

ii) Set Path environment variable- to access Java from any directory.

iii) Download Eclipe IDE and extract

iv) Download WebDriver Java Language binding and add Webdriver jar files (in Eclipse)
--------------------------
v) Install Firebug and FirePath plug ins for Mozilla Firefox browser to inspect Elements.

Note: For Internet explorer and Google chrome, no need to install any plug ins, They have built in Developer tools.

Note 2: Element locators and WebDriver methods are common for all browsers, browser driver only varies from one browser to another.

Note 3: Firefox driver is default driver in Webdriver, For IE and Chrome we need to download drivers.
----------------------------------------------------
Download Selenium WebDriver Java binding from www.seleniumhq.org website and extract.

Navigation for adding Webdriver jar files in Eclipse.
Create Java project
> Select src and right click
> Build path
> Configure Build Path
> select Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
-------------------------
Pre-requisites to Create Automated Tests
Test / Test Script / Test Case

> Import WebDriver Libraries and Firefox driver/IE driver/Chrome Driver

> Using Web Element (object) locators and WebDriver methods write object call statements

> Insert Java programmatic statements to enhance Test cases.
---------------------------------------------------------

Selenium Test Cases

Create Test Cases using Selenium WebDriver

Pre-requisites for Creating Test cases in Selenium WebDriver:
 

i) Element Locators (To identify/recognize Elements(Objects)

ii) Webdriver Methods (To perform Operations on Elements)

iii) Java Programming concepts (To enhance Test cases)

 ---------------------------------------
iv) TestNG Annotations (For grouping test cases, generating HTML reports and parallel test case execution)
---------------------------------------------
i) Element Locators
 

1) id

2) name

3) classname

4) tagName

5) linkText

6) partialLinkText

7) cssSelector

8) xpath
----------------------
Web Elements
 

Browser,
Page,
------------------
Button,
Link
Text box
Edit box
Check box
Radio button
Drop down box / List box / Combo box
Web Table / HTML Table
Frame
---------------
Mouse hover
Span
Multiple Browsers
Duplicate Objects
---------------------------
Selenium WebDriver Methods
 

a) Methods on Browser
 ---------------------
1) get()

2) getTitle()

3) getpageSource()

4) getCurrentUrl()

5) getWindowHandle()

6) close()

7) quite()
--------------------------------
b) Browser navigation methods
 

1) navigate().to()

2) navigate().back()

3) navigate().forward()

4) navigate().referesh()
------------------------
c) Methods on Elements
 

1) findelement()

2) findelements()

3) sendkeys()

4) click()

5) clear()

6) isEnabled()

7) isdisplayed()

8) isSelected()

9) getText()

10) selectByVisibleText()

11) selectByIndex()
----------------------------
d) Others
 

manage().window().maximize()

explicitlyWait()

etc...
--------------------------------------
Java Programming Concepts
 

A) Java Fundamentals / Basics
 
1) Comments

2) Data Types

3) Modifiers

4) Variables

5) Operators

6) Conditional statements

7) Loop statements

8) Strings

9) Arrays

10) Built in Methods

11) User defined methods

12) File and IO operations

13) Exception handling
-----------------------------------
B) Object Oriented Programming System Concepts

 
1) Inheritance

2) Polymorphism

3) Abstraction

4) Encapsulation
-------------------------------