Professional Documents
Culture Documents
A) Java Fundamentals
i) Comments in Java
iv) Variables
v) Operators
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
———————————-
Steps:
———————————-
i) Comments in Java
———————-
/* Statements
—————
——————
————*/
———————-
Example:
System.out.println(a+b);
else {
}*/
———————————-
A Data Type is a classification of the type of data that a variable or object can hold in computer
programming.
Character,
Integer
String
Float
Boolean etc…
Example:
int a=10;
char b =’A’;
double c = 123.234;
boolean d = true;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
———————————-
Modifiers are used to set access levels for Classes, Variables and Methods etc…
Example:
System.out.println(result);
obj.add();
———————————-
1) Local Variables
2) Instance Variables
int c = 30;
System.out.println(a);
System.out.println(c);
if (a > b){
int d=40;
System.out.println(a + b + d);
System.out.println(d);
//System.out.println(d);
System.out.println(b);
———————————-
v) Operators in Java
1) Arithmetic Operators
2) Relational Operators
3) Assignment Operators
4) Logical Operators
Etc…
——————————–
1) Arithmetic Operators
c) Multiplication *
d) Division /
e) Modules %
f) Increment ++
g) Decrement —
————————
2) Relational Operators
a) ==
b) !=
c) >
d) >=
e) <
f) <=
—————————
3) Assignment Operators
a) Assignment =
————————
4) Logical Operators
c) Logical Or operator ||
———————————-
Example:
System.out.println(a+b);
System.out.println(a*b);
System.out.println(a-b);
System.out.println(a+10);
else {
———————————-
a) if statement
b) switch statement
———————–
———————————-
b) Execute a block of statements when a condition is true, otherwise execute another block of
statements.
c) Execute a block of statements when a Compound condition is true, otherwise execute another
block of statements.
e) Execute a block of statements when more than one condition is true (Nested if).
—————————-
Example:
if (a > b){
if (a > b){
else {
else
{
———————————-
1) for loop
2) while loop
3) do while loop
————————-
Examples:
//Print 1 to 10 Numbers
System.out.println(i);
——————–
//Print 1 to 10 Numbers
int i=1;
while (i<=10){
System.out.println(i);
i++;
—————————-
System.out.println(i);
———————————-
> String may contain Alfa bytes or Alfa-numeric or Alfa-numeric and Special characters or only
numeric.
“ABCD”
“India123”
“India123$#@”
“123”
————————–
Example:
System.out.println(“India”);
System.out.println(“India123”);
System.out.println(“123”);
System.out.println(“$%^”);
System.out.println(“India123%^&*”);
———————————-
Creating Strings
System.out.println(myTool);//UFT
————————
Example 3:
System.out.println(str1.concat(str2));//Selenium UFT
System.out.println(“Selenium”+1+1);//Selenium11
System.out.println(1+1+”Selenium”);//2Selenium
———————————-
> In Java, Array is an Object that contains elements of similar data type.
—————————-
Example:
int a [];
a= new int[3];
a[0]=10;
a[1]=20;
a[2]=30;
System.out.println(a[1] + a[2]);
——————————–
a[0]=10;
a[1]=20;
a[2]=3;
System.out.println(a[0] – a[2]);
——————————-
System.out.println(a[1] + a[3]);
——————————–
———————————-
x) Java IO Operations
—————————–
Using java.util.Scanner is the easier way and it includes many methods to check input is valid to read.
Examples:
1) Read Input:
—————————
System.out.println(a);//10
———————————-
A) Java Fundamentals
i) Comments in Java
iv) Variables
v) Operators
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
———————————-
Java Environment Setup & Verify
Steps:
————————-
———————————-
i) Comments in Java
———————-
/* Statements
—————
——————
————*/
———————-
Example:
System.out.println(a+b);
else {
}*/
———————————-
A Data Type is a classification of the type of data that a variable or object can hold in computer
programming.
Character,
Example:
int a=10;
char b =’A’;
double c = 123.234;
boolean d = true;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
———————————-
Modifiers are used to set access levels for Classes, Variables and Methods etc…
Example:
System.out.println(result);
obj.add();
———————————-
1) Local Variables
2) Instance Variables
int c = 30;
System.out.println(a);
System.out.println(c);
if (a > b){
int d=40;
System.out.println(a + b + d);
System.out.println(d);
//System.out.println(d);
System.out.println(b);
———————————-
v) Operators in Java
1) Arithmetic Operators
2) Relational Operators
3) Assignment Operators
4) Logical Operators
Etc…
——————————–
1) Arithmetic Operators
c) Multiplication *
d) Division /
e) Modules %
f) Increment ++
g) Decrement —
————————
2) Relational Operators
a) ==
b) !=
c) >
d) >=
e) <
f) <=
—————————
3) Assignment Operators
a) Assignment =
————————
4) Logical Operators
c) Logical Or operator ||
———————————-
Example:
System.out.println(a+b);
System.out.println(a*b);
System.out.println(a-b);
System.out.println(a+10);
else {
———————————-
a) if statement
b) switch statement
———————–
———————————-
b) Execute a block of statements when a condition is true, otherwise execute another block of
statements.
c) Execute a block of statements when a Compound condition is true, otherwise execute another
block of statements.
e) Execute a block of statements when more than one condition is true (Nested if).
—————————-
Example:
if (a > b){
if (a > b){
else {
else{
System.out.println(“B is a Big Number”);
———————————-
1) for loop
2) while loop
3) do while loop
————————-
Examples:
//Print 1 to 10 Numbers
System.out.println(i);
——————–
//Print 1 to 10 Numbers
int i=1;
while (i<=10){
System.out.println(i);
i++;
—————————-
if (i != 4){
System.out.println(i);
}}
———————————-
> String may contain Alfa bytes or Alfa-numeric or Alfa-numeric and Special characters or only
numeric.
“ABCD”
“India123”
“India123$#@”
“123”
————————–
Example:
System.out.println(“India”);
System.out.println(“India123”);
System.out.println(“123”);
System.out.println(“$%^”);
System.out.println(“India123%^&*”);
———————————-
Creating Strings
System.out.println(myTool);//UFT
————————
Example 3:
System.out.println(“Selenium”+1+1);//Selenium11
System.out.println(1+1+”Selenium”);//2Selenium
———————————-
> In Java, Array is an Object that contains elements of similar data type.
—————————-
Example:
int a [];
a= new int[3];
a[0]=10;
a[1]=20;
a[2]=30;
System.out.println(a[1] + a[2]);
——————————–
a[0]=10;
a[1]=20;
a[2]=3;
System.out.println(a[0] – a[2]);
——————————-
System.out.println(a[1] + a[3]);
——————————–
———————————-
x) Java IO Operations
—————————–
Using java.util.Scanner is the easier way and it includes many methods to check input is valid to read.
Examples:
1) Read Input:
—————————
System.out.println(a);//10
System.out.println(“Addition of a, b is “+ (a+b));//Addition of a, b is 30
System.out.println(“value of a is “+ a + ” Value of b is “+b);//Value of a is 10 value of b is 20”}
———————————-
Phases:
i) Planning
—————————————–
Phases in STLC:
i) Test Planning
—————————————–
i) Test Planning
a) References / Input
Project Plan
Test Strategy
—————————-
Design docs
Prototypes etc…
b) Tasks
iv) Test Estimations (Scope of the AUT, Available Resources, Time, Budget etc…)
v) Team Formation
Output:
—————————————–
a) References / Input
Requirements
Test Plan
—————–
————————-
Design docs
Prototypes etc…
———————————
b) Tasks
c) Output
Test Data
—————————————–
a) References / Input
Test Requirements
Test Plan
Test Data
————————-
Readiness of AUT
————————
Defect Report
———————–
b) Tasks
Test Execution
Smoke Testing
Comprehensive Testing
Reporting Defects
Tracking Defects
Select Test Cases for Regression Testing Cycle 1
Sanity Testing
Reporting Defects
Tracking Defects
Sanity Testing
Reporting Defects
Tracking Defects
Final Regression
Output:
Tested Software
—————————————–
a) References/Input
Test Requirements
Test Plan
——————-
etc…
———————
—————————————–
i) Planning
—————————————–
i) Planning
ii) Tests that we have to execute on every modified build (Regression Tests)
iii) Tests that we have execute using multiple sets of Test Data (Data Driven Tests)
Download Selenium WebDriver Java language binding and Add WebDriver jar files to Java Project in
Eclipse.
Download TestNG from Eclipse and Install
—————————————–
Selenium IDE
By Recording user Actions on AUT Or Type Test Steps using Element Locators and Selenese
Commands
Selenium WebDriver
Type Test Steps using Element Locators and WebDriver API Commands
Selenium Grid – NA
—————————————–
Selenium IDE:
Selenium WebDriver
Add comments
Synchronization
Using Text files or Excel files with the help of Java conduct Data driven Testing
Or
—————————————–
Debugging Tests:
What is Debugging?
Scenario 3: Test is not showing any errors and Not providing correct output – Debugging is
Mandatory
Note: Whenever Test is not showing any error and not providing correct output then Debugging is
required.
Batch Testing
—————————————–
Or
Report Defects
———————————————
Selenium Manual
———————————————
———————————————
A) Java Fundamentals
i) Comments in Java
iv) Variables
v) Operators
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
———————————-
Steps:
————————-
———————————-
i) Comments in Java
———————-
/* Statements
—————
——————
————*/
———————-
Example:
System.out.println(a+b);
else {
}*/}
}
———————————-
A Data Type is a classification of the type of data that a variable or object can hold in computer
programming.
Example:
int a=10;
char b =’A’;
double c = 123.234;
boolean d = true;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
———————————-
Modifiers are used to set access levels for Classes, Variables and Methods etc…
Example:
System.out.println(result);
obj.add();
———————————-
1) Local Variables
2) Instance Variables
Example:
int c = 30;
System.out.println(a);
System.out.println(c);
if (a > b){
int d=40;
System.out.println(a + b + d);
System.out.println(d);
}
//System.out.println(d);
System.out.println(b);
———————————-
v) Operators in Java
1) Arithmetic Operators
2) Relational Operators
3) Assignment Operators
4) Logical Operators
Etc…
——————————–
1) Arithmetic Operators
c) Multiplication *
d) Division /
e) Modules %
f) Increment ++
g) Decrement —
————————
2) Relational Operators
a) ==
b) !=
c) >
d) >=
e) <
f) <=
—————————
3) Assignment Operators
a) Assignment =
————————
4) Logical Operators
c) Logical Or operator ||
———————————-
Example:
System.out.println(a+b);
System.out.println(a*b);
System.out.println(a-b);
System.out.println(a+10);
else {
———————————-
a) if statement
b) switch statement
———————–
———————————-
b) Execute a block of statements when a condition is true, otherwise execute another block of
statements.
c) Execute a block of statements when a Compound condition is true, otherwise execute another
block of statements.
e) Execute a block of statements when more than one condition is true (Nested if).
—————————-
Example:
if (a > b){
if (a > b){
else {
else
———————————-
1) for loop
2) while loop
3) do while loop
————————-
Examples:
//Print 1 to 10 Numbers
System.out.println(i);
——————–
//Print 1 to 10 Numbers
int i=1;
while (i<=10){
System.out.println(i);
i++;
—————————-
if (i != 4){
System.out.println(i);
———————————-
> String may contain Alfa bytes or Alfa-numeric or Alfa-numeric and Special characters or only
numeric.
“ABCD”
“India123”
“India123$#@”
“123”
————————–
Example:
System.out.println(“India”);
System.out.println(“India123”);
System.out.println(“123”);
System.out.println(“$%^”);
System.out.println(“India123%^&*”);
———————————-
Creating Strings
System.out.println(myTool);//UFT
————————
Example 3:
System.out.println(str1.concat(str2));//Selenium UFT
System.out.println(“Selenium”+1+1);//Selenium11
System.out.println(1+1+”Selenium”);//2Selenium
———————————-
> In Java, Array is an Object that contains elements of similar data type.
—————————-
Example:
int a [];
a= new int[3];
a[0]=10;
a[1]=20;
a[2]=30;
System.out.println(a[1] + a[2]);
——————————–
a[0]=10;
a[1]=20;
a[2]=3;
System.out.println(a[0] – a[2]);
——————————-
System.out.println(a[1] + a[3]);
——————————–
———————————-
x) Java IO Operations
—————————–
Using java.util.Scanner is the easier way and it includes many methods to check input is valid to read.
Examples:
1) Read Input:
—————————
System.out.println(a);//10
System.out.println(“Addition of a, b is “+ (a+b));//Addition of a, b is 30
———————————-
A) Java Fundamentals
i) Comments in Java
v) Operators
x) Java IO Operations
—————————————-
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
—————————————-
Example:
1) Create a Folder
fileObject.mkdir();
—————————————-
In structured programming (Ex: C Language) we use Functions (Built-in and User defined)
In Object Oriented Programming (Ex: Java Language) we use Methods (Built-in and User defined)
—————————————-
Whenever we want perform any operation multiple times then we choose methods.
Advantages of Methods
Code Reusability, using methods we can reduce the project code size.
—————————————
—————————————-
equals() Method
Example:
System.out.println(str1.equals(str2));//false
System.out.println(str1.equals(str4));//true
—————————————
round()
double a =10.234;
double b =-10.784;
.System.out.println(Math.round(a));//10
System.out.println(Math.round(b));//-11
—————————————
isAlphabetic()
char a =’Z’;
char b =’1';
System.out.println(Character.isAlphabetic(a));//true
System.out.println(Character.isAlphabetic(b));//false
System.out.println(Character.isAlphabetic(‘B’));//true
System.out.println(Character.isAlphabetic(‘a’));//true
System.out.println(Character.isAlphabetic(‘*’));//false
—————————————-
Examples:
return result;
//Create Object
//Call methods
System.out.println(x);
———————————
System.out.println(“Rank A”);
System.out.println(“Rank B”);
else{
System.out.println(“Rank C”);
}}
public static void main(String[] args) {
//Call Methods
JavaMethods.studentRank(650);
—————————————-
> An Exception is an event that occurs during execution of a program when normal execution of a
program is interrupted.
Example:
int a =10;
int b =0;
System.out.println(result);
System.out.println(“Hello Java”);
System.out.println(“Hello Selenium”);
—————————————-
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
—————————————-
i) Inheritance
> It is a process of Inheriting (reusing) the class members (Variables and Methods) from one class to
another.
> The Class 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 as Sub Class/Child
Class/Derived Class.
> The Inheritance between Super class and Sub class is achieved using “extends” keyword.
—————————–
Example
Class 1:
int a =10;
int b =20;
System.out.println(a+b);
System.out.println(objA.a);//10
objA.add();//30
——————————
Class 2:
int a =100;
int b =200;
System.out.println(a+b);
System.out.println(objB.a);//100
objB.add();//300
—————————————-
ii) Polymorphism
—————————————
If two or more methods with same name in the same class but they differ in following ways.
a) Number of Arguments
b) Type of Arguments
————————————
Example:
System.out.println(a+b);
System.out.println(a+b+c);
System.out.println(a+b);
obj.add(1.23, 2.34);
obj.add(10, 20);
obj.add(1, 5, 9);
—————————————-
iii) Abstraction
> It is a process of hiding implementation details and showing only functionality to the user.
> If we know the method name but don’t know the method functionality then we go for Abstract
methods.
—————————————-
—————————————-
iv) Encapsulation
Encapsulation is the technique making the fields in a class private and providing access via public
methods.
> By providing setter and getter methods we can make a class read only or write only.
—————————————-
Example:
Class 1:
return name; }
public void setName(String newName){
name = newName;
System.out.println(obj.getName());
—————————————-
Class 2:
//abc.setName(“Selenium Testing”);
System.out.println(abc.getName());
—————————————-
————————————-
> Selenium WebDriver supports various Browsers to create and execute Test Cases.
> Using Element Locators and WebDriver Commands we can create Test Cases.
> Its support Batch Testing, Cross Browser Testing and Data Driven Testing
——————————–
> It doesn’t have IDE, so difficult to create Test cases and takes more time.
————————————-
Steps:
i) Download and install Java (JDK) software. – To create and execute programs (Test scripts)
ii) Download Eclipse IDE and extract. – To write and execute Java programs.
————————————-
iii) Download Selenium WebDriver Java Language binding (from www.seleniumhq.org) and add
WebDriver jar files to Java project in Eclipse IDE.
————————————-
v) Firefox Driver is default driver in Selenium Webdriver, for IE, Chrome and Safari etc… Browsers we
need to download browser drivers and set path.
————————————-
Test Case Name: Verify Admin Login in GCR Shop web portal
Test Steps:
Password = admin@123
Verification Point:
Capture the Url (Actual) after Login to Application and Compare with Expected.
Test Result:
————————————-
Examples for Operations on Elements: Click, Enter a Value, Check, select etc…
————————————-
height 6
————————————-
weight 5
————————————-
Button id tdb1
————————————-
Selenium WebDriver Test Case:
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();
if (url.equals(“http://www.gcrit.com/build3/admin/index.php”)){
else {
————————————-
a) WebElements
Browser
Page
—————-
Edit box
Link
Button
Check box
Radio Button
List box
Combo box
Frame
Etc..
——————————-
b) Operations on Elements
i) Browser
(Launch Browser, Navigate to specified URL, Navigate back, Navigate forward, refresh, close
Browser….)
ii) Page
iii) Link
iv) Button
(Click, Check Displayed status, Enabled status, return button name ….)
v) Image
b) Image Button (Click, Check Displayed status, Enabled status, return button name ….)
c) Image Link (Click, Check the existence, Check Enabled status ….)
(Check Displayed status, Enabled status, Select, Unselect, check Selected status….)
(Check Displayed status, Enabled status, Select an Item, Get Items Count ….)
x) List Box
(Check Displayed status, Enabled status, Select one or more Items, Get Items Count ….)
(Check Displayed status, Enabled status, Select an Item, Enter an Item, Get Items Count ….)
(Return specified Cell value, Return Rows Count, Column Count etc…)
xiii) Frame
inLine Elements
————————————-
What is Locator?
> It is an address that identifies a Web element uniquely within the page.
————————————-
Syntax:
Example:
driver.findElement(By.id(“Email”))
————————————-
id – Locator
Email – Value
————————————-
Examples:
driver.findElement(By.name(“Email”)).sendKeys(“India”);
driver.findElement(By.className(“textboxcolor”)).sendKeys(“India”);
driver.findElement(By.tagName(“input”)).sendKeys(“India123”);
driver.findElement(By.linkText(“Gmail”)).click();
driver.findElement(By.partialLinkText(“Gma”)).click();
driver.findElement(By.cssSelector(“#next”)).click();
driver.findElement(By.xpath(“.//*[@id=’Email’]”)).sendKeys(“abcd123”);
————————————-
> Selenium WebDriver methods/commands are used to perform operations on Web Elements.
> Using Element Locators and WebDriver Methods we create Test Cases.
————————————-
driver.get(“https://www.google.com”);
————————————-
————————————-
driver.navigate().to(“https://in.yahoo.com”);
————————————-
driver.navigate().back();
————————————-
driver.navigate().forward();
————————————-
driver.get(“https://www.google.com”);
————————————-
driver.close();
————————————-
9) findElement() – Finds the first Element within the current page using given locator.
driver.findElement(By.id(“Email”)).sendKeys(“India123”);
————————————-
driver.findElement(By.id(“Email”)).sendKeys(“India@123”);
————————————-
driver.findElement(By.id(“Email”)).clear();
————————————-
12) click() – Clicks an Element (Buttons, Links etc…)
driver.findElement(By.id(“next”)).click();
————————————-
boolean a = driver.findElement(By.id(“next”)).isEnabled();
————————————-
boolean a = driver.findElement(By.linkText(“Gmail”)).isDisplayed();
————————————-
————————————-
———————————-
5) JUnit / TestNG Testing Framework Annotations – To group Test Cases, Batch Testing, and
generating Test Reports.
———————————-
Test Steps:
Verification Point:
Expected: Google
Result:
———————————-
driver.get(“https://www.google.com”);
if (PageTitle.equals(“Google”)){
else {
driver.close();
———————————-
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
driver.get(“https://www.google.com”);
else {
driver.close();
———————————-
System.setProperty(“webdriver.ie.driver”, “E:/IEDriverServer.exe”);
driver.get(“https://www.google.com”);
if (PageTitle.equals(“Google”)){
else {
driver.close();
———————————-
Test Case 2: Verify Redirect Functionality in gcrShop (From Admin Interface to user Interface)
Test Case 3: Verify the “Manufacturers” Link existence in gcrShop web portal after Admin Login——
—————————-
Selenium Test Batch:
//Launch Browser
//Admin Login
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(Username);
driver.findElement(By.name(“password”)).sendKeys(Password);
driver.findElement(By.id(“tdb1”)).click();
//Close Browser
driver.close();
obj.launchBrowser();
obj.adminLogin(“admin”, “admin@123”);
if (url.equals(“http://www.gcrit.com/build3/admin/index.php”)){
} else{
System.out.println(“Test Case 1: Admin Login Unsuccessful – Failed”);
obj.closeBrowser();
//——————————–
//Test Case 2: Verify Redirect Functionality in gcrShop (From Admin Interface to user Interface)
obj.launchBrowser();
obj.adminLogin(“admin”, “admin@123”);
driver.findElement(By.linkText(“Online Catalog”)).click();
if (url2.equals(“http://www.gcrit.com/build3/”)){
else {
System.out.println(“Test Case 2: Not Redirected from Admin Interface to User Interface – Failed”);
obj.closeBrowser();
//——————————–
//Test Case 3: Verify the “Manufacturers” Link existence in gcrShop web portal after Admin Login
obj.launchBrowser();
obj.adminLogin(“admin”, “admin@123”);
try {
if (linkExistence == true){
obj.closeBrowser();
//————————-
———————————-
Etc…
———————————-
Data Driven Test Case: Admin Login Functionality with valid and Invalid inputs
Test Steps:
3) Enter Username
4) enter Password
Verification Point:
Capture the URL after Login and Compare with expected
Expected: http://www.gcrit.com/build3/admin/index.php
———————————-
Iteration =0;
if (count > 1) {
Iteration = Iteration + 1;
driver.get(“http://www.gcrit.com/build3/admin”);
driver.findElement(By.name(“username”)).sendKeys(InputData[0]);
driver.findElement(By.name(“password”)).sendKeys(InputData[1]);
driver.findElement(By.id(“tdb1”)).click();
if (url.equals(“http://www.gcrit.com/build3/admin/index.php”)){
else {
System.out.println(“Iteration-“+Iteration+ ” – Admin Login Unsuccessful – Failed”);
driver.close();
file.close();
br.close();
———————————-
—————————–
1) JUnit
2) TestNG
> TestNG is a Testing Framework designed to simplify a broad range of Testing activities from Unit
Testing to System Testing.
> Initially developed for Unit Testing, now used for all kinds of Testing
> TestNG is an open source Framework where NG Stands for Next Generation.
> TestNG inspired from JUnit (Java platform and NUnit (.NET platform), but introduced some new
functionality.
—————————–
Advantages of TestNG
—————————–
In Eclipse IDE,
> Next > Next > accept License Agreement > finish
—————————–
Test Steps:
Verification Point:
Expected: Gmail
@Test
driver.get(“https://www.gmail.com”);
driver.close();
—————————–
Note:
3) If we don’t write @Test Annotation then the method is not going to be executed.
—————————–
@Test
Assert.assertEquals(“Gmail”, “Gmail”);
@Test
Assert.assertEquals(“abcd”, “abcd”);
@Test
public void xyz(){
Assert.assertEquals(“Yahoo”, “Yahoo”);
@Test
Assert.assertEquals(“Google”, “Google”);
—————————–
logout
abcd
xyz
login
—————————–
abcd
login
logout
xyz
If you want control the Test Execution then use priority attribute or dependsOnMethods attribute
—————————–
Required Flow:
login
abcd
xyz
logout
Using priority attribute
@Test(priority = 4)
Assert.assertEquals(“Gmail”, “Gmail”);
@Test(priority = 2)
Assert.assertEquals(“abcd”, “abcd”);
@Test(priority = 3)
Assert.assertEquals(“Yahoo”, “Yahoo”);
@Test(priority = 1)
Assert.assertEquals(“Google”, “Google”);
—————————–
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(dependsOnMethods = {“xyz”})
Assert.assertEquals(“Gmail”, “Gmail”);
}
@Test(dependsOnMethods = {“login”})
Assert.assertEquals(“abcd”, “abcd”);
@Test(dependsOnMethods = {“abcd”})
Assert.assertEquals(“Yahoo”, “Yahoo”);
@Test
Assert.assertEquals(“Google”, “Google”);
—————————–
Required Flow:
login
abcd
logout
login
xyz
logout
—————————–
@AfterMethod
public void logout(){
System.out.println(“Logout Successful”);
@Test
System.out.println(“abcd Successful”);
@Test
System.out.println(“xyz Successful”);
@BeforeMethod
System.out.println(“Login Successful”);
—————————–
Required Flow:
login
xyz
abcd
logout
—————————–
@AfterClass
public void logout(){
System.out.println(“Logout Successful”);
@Test(priority = 2)
System.out.println(“abcd Successful”);
@Test(priority = 1)
System.out.println(“xyz Successful”);
@BeforeClass
System.out.println(“Login Successful”);
—————————–
<classes>
</classes>
Tags
suite
test
classes
class
—————————–
Select Java Package > Right Click > New > Others…
> Finish
—————————–
Test Cases:
login
addVendor
addCurrency
addProduct
logout
—————————–
XML File
<classes>
<class name=”abcd.Class1?/>
<class name=”abcd.Class2?/>
</classes>
—————————–
Class 1
@BeforeTest
System.out.println(“Login Successful”);
@AfterTest
System.out.println(“Logout Successful”);
@Test(priority = 1)
@Test(priority = 3)
@Test(priority = 2)
} } --------------------------------------------------------------—————————–
Class 2:
/*@BeforeClass
System.out.println(“Login Successful”);
@AfterClass
System.out.println(“Logout Successful”);
}*/
@Test(priority = 1)
@Test(priority = 3)
@Test(priority = 2)
—————————–
<groups>
<run>
</run>
</groups>
<classes>
</classes>
—————————–
Tags
suite
test
groups
run
include
classes
class
—————————–
Sanity group
login
search
prepaidRecharge
logout
Regression group
login
advancedSearch
prepaidRecharge
billPayments
logout
—————————–
XML File
<test name=”Test”>
<groups>
<run>
</run>
</groups>
<classes>
<class name=”abcd.Class3?/>
</classes>
—————————–
Class File
System.out.println(“Login Successful”);
}
System.out.println(“Logout Successful”);
System.out.println(“Search Successful”);
—————————–
1) Launch Browser
—————————–
TestNG Program:
@BeforeClass
@AfterClass
driver.close();
@Test(priority=1)
driver.get(“https://www.gmail.com”);
Assert.assertEquals(“Gmail”, driver.getTitle());
@Test(priority=2)
driver.get(“https://in.yahoo.com”);
Assert.assertEquals(“Yahoo”, driver.getTitle());
—————————–