Disadvantages of Test Automation

Disadvantages of Test Automation

Test Automation or Automated Testing: Testing Computer Software or Mobile Software using any Automation tool or Automation script.


Important Tasks in Test Automation:

• Select areas / Test cases for Automation

• Create Tests / Test Scripts using Test Tool IDE features and Programming features.

• Executing Tests (Single Test or Test Batches).

• Debugging Tests if required.

• Analyzing Test Results and Reporting Defects.
----------------------------------------------------------
Disadvantages of Test Automation / Automated Testing

i) Test Automation requires lot of efforts at initial stage.

(In Software Testing two important tasks, one is Test Design and another is Test Execution, For Test Design User (Tester) interaction is mandatory, Testers only create Test scripts using Test Tool features and Programming features, It takes more time than Manual Test Case Design.)

ii) 100% Test automation is impractical.
 

(Generally we try to automate maximum Test cases, not all Test cases, for some Test human user observation is required.

Due to some Environment limitations we can't automate all testable requirements.)

iii) All types of Testing not possible (Ex: Usability).
 

(We can automate Functionality tests, Performance Tests but not possible to automate tests that verify User friendliness of the System(AUT).

iv) Debugging issues

(We use programming syntax/logic to write Tests, some times locating errors in Test Script is difficult.)

v) Tools may have their own defects.

(Test tool also a Software, it may have its own defects in it, so that we may not achieve desired benefits).

vi) Programming Knowledge is required.

(Every Test Tool uses any one of the Programming languages (Example UFT supports VBScript, Selenium supports Java, Perl, PHP, C#, PHP and Ruby) to write Test scripts. So in order to create and edit Test Scripts Programming knowledge is mandatory.

In Manual Testing, no programming knowledge is required.)

vii) Test Tools have Environment Limitations.
 

(Test Tools have some compatibility issues with Operating Systems and browsers etc...

Example:
 

UFT / QTP Supports Windows operating environment only, doesn't support other operating environments like UNIX, Macintosh etc...

Selenium Supports Web Application test automation only, doesn't support Desktop / windows based applications.

For Manual Testing no environment limitations, we can test computer software or mobile software on any operating system and any Browser.)

viii) Not suitable for dynamically changing UI designs.
 

(Most of the Test Tools support Test automation based on front-end objects, if User Interface design changes dynamically then it is difficult to automate.)
-------------------------------------------------------------------------

Test Tool: A Software that used to automate Software Test process.

Test Tool is one software, Application Under Test (AUT) is another software.

Debugging: Locating and Isolating errors through step by step execution.

Advantages of Test Automation

Advantages of Test Automation

Test Automation or Automated Testing is a process of Testing Computer Software or Mobile Software using any Software Tool (Test Tool).

We have several Test Tools in the IT Industry, They are,

i) UFT (formerly QTP), Selenium, RFT, SilkTest etc... for Functional Test Automation

ii) LoadRunner, JMeter, SlikPerformer etc... for Performance Test Automation

iii) ALM / QC, Jira etc... for Test Management/Project Management

iv) Bugzilla, Issue Tracker, PR-Tracker etc... for Defect Management

Advantages (Benefits) of Test Automation

i) Fast:

Tools are faster in Test execution than human users (Software Testers).

In Software Testing 2 import tasks are there,

a) Test Design

In Test Design no time saving, it takes more time than manual testing, testers only generate Tests (Test scripts)
using Test tool IDE features (Example: Recording, Inserting Chechpoints etc...) and Program / Script features (Example: Flow Control, Functions/Methods etc...)
, but Test design is one time activity.

b) Test Execution

Test Tool can execute Tests (Single Test or Series of Tests) quickly than human users (Testers).

Test design is one time activity, but we have to execute Tests multiple times, so we can save time.

Example: Sanity Tests and Regression Tests can be executed multiple times.

ii) Reusable:

Tests(Test Scripts) can be reused on different versions of Software easily.

Example: Sanity Tests, Regression Tests

If it is Manual Testing user/Tester interaction is mandatory for every test iteration.

iii) Repeatable:

Tests can be repeated with multiple sets (multiple values) of Test Data without user/tester interaction.

Example: Data Driven Tests

iv) Accuracy / Reliable:

If Testers provide correct logic then tool can execute Tests correctly. In case of manual Testing, human users may make mistakes (in case of complex calculations).

v) Programmable:

Programming features (Variables, Operators, Conditional Statements, Loop Statements, Functions etc...) can be used for enhancing Tests/Test scripts.

Computer programming allows us to work with different types of Files and Databases for Testing activities (Ex: Data Driven Testing, Generating Test Reports etc...).

Testers can apply programming logic to tests, so they have a facility to insert multiple verification points in a test.

Note: If it is manual testing, human users can concentrate on one or two verification points only (In a test case execution).

If it is Test automation tool can execute multiple verification points at a time.

Final conclusion: Automated Test scope is very high than manual test case.

vi) Comprehensive:

Test Tool supports Batch testing (Executing series of tests), series of tests can be executed without human user (tester) interaction.

If it is Manual Testing human user (tester) interaction is required for every Test iteration.

------------------------------------------------------------------     
 Note:

• For Functional Testing we can follow Manual Testing or Test Automation.

• For Performance Testing Test Automation is the only solution, Manual Testing is impractical.

• We can't automate Usability Tests, Human user (Tester) only can Test the user friendliness of the System (AUT).

• We need to purchase vendor Tool (Ex: UFT/QTP, LoadRunner, RFT etc...), Some Test Tools are Open source tools (Ex: Selenium, Bugzilla etc...), we can use Open source tools with free of cost.

------------------------------------------------------------------    

Drawbacks of Manual Testing

Drawbacks of Manual Testing

Software Testing can be done in two ways,

 
a) Manual Testing

Testing Computer Software manually without using any Automation Tool. 


Important Tasks in Manual Testing:

•    Testers derive Test scenarios from Requirements, Document Test Cases and collect Test Data.

•    Testers Execute Test Cases, if they find any deviations from expected then Report Defects.

b) Test Automation / Automated Testing

Testing Computer software using any Software tool like UFT or Selenium or RFT or SilkTest etc…

Important Tasks in Test Automation:

 
•    Testers generate Tests /Test Scripts using Test Tool’s IDE features and supported programming features.

•    Test Tool Executes Tests (Test Batches) without User/ Tester interaction and provide test results.

•    Testers analyze Test Result and send Defect Reports if they find any deviations from requirements.

Drawbacks of Manual Testing

i) Manual Testing requires more time or more resources, some times both Time and Resources.


(Covering all areas of the Application requires more Tests, Creating all possible Test cases, and executing Test cases takes more time. If it is Test Automation, Test tool can execute Tests quickly.)

ii) Less Accuracy


(Human Users (Testers) may make mistakes, so we cannot expect more accuracy in Manual Testing,

If it is Test Automation / Automated Testing, if you provide the correct logic then test tool can provide correct output.)

iii) Performance testing is impractical in manual testing.


(Organizing Thousands of Machines / Computers and human Users is impractical, If it is Test Automation, we can create thousands of Virtual users and using 3 or 4 Computers we can apply the Load and test the Performance of the Application)

iv) Comparing large amount of data is impractical. 


(Comparing two Databases that have thousands of records is impractical, but it is very is in Test Automation.)

v) Processing change requests during software maintenance takes more time.
 
vi) Batch Testing is possible, but for each test execution Human user interaction is mandatory.


(Batch Testing means executing series of tests, In Batch Testing for every test case execution User / Tester interaction is mandatory, If it is Test Automation Test tool can execute series of Tests without human user interaction.)

 
vii) GUI Objects Size difference and Color combinations etc.. are not easy to find in Manual Testing.

viii) Manual Test Case scope is very less, if it is Automated test, scope is more.



(In Manual Testing, Test case scope is very limited why because Tester/user can concentrate on one or two Verification points only, If it is Test Automation, Test tool (Tool also Software) can concentration on multiple verification points at a time.)
 
ix) Executing same tests again and again is time taking process as well as Tedious.
 

(Sometimes we need to execute same tests using multiple sets of Test data, for each test iteration user interaction is mandatory, In Test Automation using Test Data data file (either Text file or Excel file or Database file) we can easily conduct Data driven Testing.)

x) For every release you must rerun the same set of tests which can be tiresome.

(We need to execute Sanity Test Cases and Regression Test cases on every modified build, it takes more time. In Automated Testing / Test Automation once we can create Tests then Tool can execute Tests multiple times quickly.)
---------------------------------------------------------------------------
Advantages of Manual Testing

i) No Environment Limitations


(Irrespective of the AUT (Application Under Test) environment we can use Manual Test Process, If it is Test Automation so many environment limitations,

Examples:

UFT/QTP doesn't support Linux Operating Environment.

Selenium doesn't support Desk Applications Test Automation.)

ii) Programming Knowledge is not required.


(In Manual Testing, Understanding Requirements, Documenting Test Cases and Executing Test Cases are the important tasks, but Programming is not used. 

If it is Test Automation every tool uses anyone Programming language to enhance test cases, so programming knowledge is mandatory for Test Automation.)

iii) Recommendable for Dynamically changing GUI designs.


(If the Graphical User Interface of the Application changes dynamically then Test Automation is not recommendable.)
 
iv) Recommendable for Usability Testing.


(Human user only can judge the look & feel accepts, We cannot check User friendliness of the System (AUT) using Test tools.)

v) Manual testing allows for human observation, which may be more useful to find potential defects.


(In Manual Testing, User / Tester interacts more with the AUT then it is easy to find defects and Tester can provide suggestions to the development team.) 
------------------------------------------------------------------------------

Software Testing Live Project

Software Testing Live Project

Functional Test Automation using Selenium

Project Info:
Project Domain: Ecommerce

Sub-Domain: B2C (Business to Customer)

Application: Online Shopping Portal

Application Environment: LAMP (Linux, Apache, MySQL and PHP)

Production Environment: Internet Public Application

Test Environment: Intranet
--------------------------------------------------------
Project Description:

This web portal provides interface between Vendors/Manufacturers and Customers,
Manufacturers place their products information and sell,
Customers view Products and Buy Products,
Financial Service providers provide money transactions,
Courier Service Providers ship products, return products, (From Manufacturers to Customers, Customers to Manufacturers)
--------------------------------------------
www.gcrit.com -Domain

www.gcrit.com/build3/ - (build3 is Folder)

english.tupaki.com/ - (english - Sub-Domain)
-------------------------------------------------------------
Stake holders of the Project

i) Web Portal Owner/Developer
ii) Manufacturers
iii) Financial Service providers
iv) Courier Service Providers
v) Customers.
-----------------------------------------------
Two Interfaces of the Application

i) Admin Interface (Provides Master Data (Add/Edit/Delete), and Maintenance)

ii) User Interface (Business Operations)

i) Admin Interface

Users:
Project Admin
Manufacturers
Financial Service provider
Courier Service Provider

Admin URL:

http://www.gcrit.com/build3/admin/

User Name: admin
Password: admin@123
----------------------------------------------
Features to be Tested in Admin Interface

i) Redirect from Admin Interface to User Interface before Login

ii) Admin Login

iii) Redirect from Admin Interface to User Interface after Login

iv) Add / Edit / Delete Manufacturers(Project Admin)

v) Add / Edit / Delete Categories (Manufacturers)

vi) Add / Edit / Delete Products (Manufacturers)

vii) Add / Edit / Delete / Set default Currency) Currencies

viii) Product Reports

ix) Customer Reports etc...
----------------------------------------------------------------
Features to be Tested in User Interface

Users

i) Guest Users (Launch Application, View Products, Search Products)
ii) Registered Users (Launch Application, View Products, Search Products, Buy Products etc...)

i) Launch Application

ii) Search products

iii) Customer Registration

iv) Customer Login

v) Buy Products (Add/delete products, Add/edit Quantity, Discounts, Select payment option and Checkout etc...)
--------------------------------------------------------------------
Smoke Tests for Admin Interface

Smoke Testing and Sanity Testing

Test Execution Levels
    Smoke Testing
    Comprehensive Testing
    Defect Reporting and Tracking
    Sanity Testing
    Regression Testing Cycle 1
    Defect Reporting and Tracking
    Sanity Testing
    Regression Testing Cycle 2
    Defect Reporting and Tracking
    .
    .
    .
    Final Regression
--------------------------------------------------
Test Scenario and Test Case

Business Requirement
Software Requirement
Test Requirement / Use Case
    Test Scenario
        Test Cases (Test Data-Applicable for some Test Cases, Input data to execute the Test Case)
---------------------------------------------
Functional Test Requirements
Functionality Tests
Security Tests


Non-Functional Test Requirements
Performance Test Requirements
Usability Test Requirements
Reliability Testing etc...

Example for Functional Test Requirement

Admin User Login to Application
---------------------------------------------
Example for Performance Test Requirement

Login for 1000 Concurrent users (within 5 Seconds)

Example for Usability Test Requirement

Verify Alignment of Elements of Admin Login Page
----------------------------------------------------------
Test Requirement: Admin User Login to Application

Test Scenarios:

i) Admin Login to Application using Valid Username and password
ii) Error message for invalid Login attempt

Test Cases:
For Positive Scenario
(Input, precondition, post condition, Steps, expected result etc...)
i) Verify Admin Login using Valid User name and Valid Password

Test Data:
Username: admin
Password: admin@123

For Negative scenario:
i) Verify Admin Login using Valid User name and Invalid Password

Test Data:
Username: admin
Password: abcd123

ii) Verify Admin Login using Invalid User name and Valid Password
Test Data:
Username: abcd123
Password: admin@123

ii) Verify Admin Login using Invalid User name and Invalid Password

Test Data:
Username: xyz123
Password: abcd123
etc...
----------------------------------------------------------------------
Smoke Tests for Admin Interface
 

i) Launch Application
ii) Admin Login
iii) Add Manufacturer
iv) Add Category
v) Add Product
vi) Add Currency
vii) Admin Logoff etc...
-----------------------------------------
All Possible Tests in Admin Interface

i) Launch Application
ii) Verify Elements presence in Login page
iii) Redirect to User Interface from Admin Interface
iv) Admin Login
v) Admin Login Invalid attempt
vi) Verify maximum Login attempts
vii) Verify Elements presence in Index page (After Login)
* Verify Elements in each page of the Application
viii) Verify Add Manufacturer
ix) Invalid attempt for Add Manufacturer
x) Verify Edit Manufacturer
xi) Verify Delete Manufacturer
xii) Verify Add Category
xiii) Verify Edit Category
xiv) Verify Delete Category
xv) Verify Add Product
xvi) Verify Edit Product
xvii) Verify Delete Product
xvii) Verify Add Currency
xix) Verify Edit Currency
xx) Verify Delete Currency
xxi) Set default Currency
xxii) Verify Product viewed report
xxiii) Verify Product purchased report
etc...
------------------------------------------------------------
Smoke Tests for User Interface

i) Verify Launch Application
ii) Verify "Create an account" with valid input data
iii) Customer Login with Valid inputs
Etc..

All Possible Tests for User Interface

i) Verify Launch Application
* Verify Existence of Elements for every page of the Application
ii) Verify "Create an account" with valid input data
iii) Invalid attempt for "Create an account"
iv) Customer Login with Valid inputs
v) Customer Login with Invalid inputs
vi) Verify Customer Logout
vii) Verify "Add product ro Cart"
viii) Verify Remove Product
ix) verify Add Quantity
x) Verify Update Quantity
xi) Verify Change Address
xii) Verify Select Payment method
xiii) Verify Checkout
Etc...
-----------------------------------------------
Element Locators
Selenium WebDriver Commands/Methods
Java Programming
TestNG Annotations
-------------------------------------------
Automate Admin, User interfaces Test cases.

TestNG Testing Framework for Selenium Part 2


TestNG Testing Framework for Selenium Part 2

TestNG Testing Framework for Part-1

I) Introduction to TestNG

II) Install TestNG and write first TestNG Test Case

III) Create multiple Test Cases and Execute
-----------------------------------------------
TestNG Testing Framework Part-2

IV) Executing multiple Programs / Classes using XML

V) Grouping Test Cases

VI) Parallel Test Execution
--------------------------------------------------------
IV) Executing multiple Programs / Classes using XML

i) Creating multiple Test Cases in a TestNG Program

TestNG Program

public class Abcd {
@Test(priority=1)
public void login(){
System.out.println("Login Successful");
}
@Test(priority=5)
public void logout(){
System.out.println("Logout Successful");
}   
@Test(priority=3)
public void addProduct(){
System.out.println("Add Product Successful");
}
@Test(priority=2)
public void addVendor(){
System.out.println("Add Vendor Successful");
}
@Test(priority=4)
public void addCurrency(){
System.out.println("Add Currency Successful");
}
}
---------------------------------------------------
Test Execution Flow:

i) login
ii) addVendor
iii) addProduct
iv) addCurrency
v) logout
----------------------------
ii) Using BeforeMethod and AfterMethod Annotations

TestNG Program

public class Abcd {
@BeforeMethod
public void login(){
System.out.println("Login Successful");
}
@AfterMethod
public void logout(){
System.out.println("Logout Successful");
}   
@Test(priority=2)
public void addProduct(){
System.out.println("Add Product Successful");
}
@Test(priority=1)
public void addVendor(){
System.out.println("Add Vendor Successful");
}
@Test(priority=3)
public void addCurrency(){
System.out.println("Add Currency Successful");
}
}
----------------------------------------------------
Test Execution Flow:

Login Successful
Add Vendor Successful
Logout Successful

Login Successful
Add Product Successful
Logout Successful

Login Successful
Add Currency Successful
Logout Successful
----------------------------------------------
iii) Using BeforeClass and AfterClass Annotations

TestNG Program

@BeforeClass
public void login(){
System.out.println("Login Successful");
}
@AfterClass
public void logout(){
System.out.println("Logout Successful");
}   
@Test(priority=2)
public void addProduct(){
System.out.println("Add Product Successful");
}
@Test(priority=1)
public void addVendor(){
System.out.println("Add Vendor Successful");
}
@Test(priority=3)
public void addCurrency(){
System.out.println("Add Currency Successful");
}
}
-----------------------------------------
Test Execution Flow:

Login Successful
Add Vendor Successful
Add Product Successful
Add Currency Successful
Logout Successful
-------------------------------------------------------------
XML file for executing multiple programs/classes
Tags in XML

<suite name = "Suite Name">
<test name ="Test Name">
<classes>
<class name ="package.Class1Name"/>
<class name ="package.Class2Name"/>
</class>
</classes>
</test>
</suite>
-----------------------------------
<classes>


</classes>

Or
<classes           />
--------------------------------------------
Navigation for creating XML file in Eclipse IDE

Select Java Project/Package > Right Click > New > Other...
> Enter TestNG and Select TestNG Class
> Enter source and package names
> Enter XML File name > Finish
--------------------------------
XML File

<suite name="Ecommerce" parallel="false">
  <test name="SanityTests">
    <classes>
      <class name="seleniumWebDriver.Abcd"/>
       <class name="seleniumWebDriver.Xyz"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
--------------------------------------------
Test Execution Flow:

login
addVendor
addProduct
addCurrency
logout
login
deleteVendor
deleteProduct
deleteCurrency
logout

Class 1

@BeforeClass
public void login(){
System.out.println("Login Successful");
}
@AfterClass
public void logout(){
System.out.println("Logout Successful");
}   
@Test(priority=2)
public void addProduct(){
System.out.println("Add Product Successful");
}
@Test(priority=1)
public void addVendor(){
System.out.println("Add Vendor Successful");
}
@Test(priority=3)
public void addCurrency(){
System.out.println("Add Currency Successful");
}
}
-----------------------------------
Class 2

public class Xyz {
@BeforeClass
public void login(){
System.out.println("Login Successful");
}
@AfterClass
public void logout(){
System.out.println("Logout Successful");
}   
@Test(priority=2)
public void deleteProduct(){
System.out.println("Delete Product Successful");
}
@Test(priority=1)
public void deleteVendor(){
System.out.println("Delete Vendor Successful");
}
@Test(priority=3)
public void deleteCurrency(){
System.out.println("Delete Currency Successful");
}
}
--------------------------------------------------------
Using BeforeTest and AfterTest Annotations

Class 1
@BeforeTest
public void login(){
System.out.println("Login Successful");
}
@AfterTest
public void logout1(){
System.out.println("Logout Successful");
}   
@Test(priority=2)
public void addProduct(){
System.out.println("Add Product Successful");
}
@Test(priority=1)
public void addVendor(){
System.out.println("Add Vendor Successful");
}
@Test(priority=3)
public void addCurrency(){
System.out.println("Add Currency Successful");
}
}
-------------------------------------
Class 2

public class Xyz {
@Test(priority=2)
public void deleteProduct(){
System.out.println("Delete Product Successful");
}
@Test(priority=1)
public void deleteVendor(){
System.out.println("Delete Vendor Successful");
}
@Test(priority=3)
public void deleteCurrency(){
System.out.println("Delete Currency Successful");
}
}
-------------------------------------------------
Test Execution Flow:

login
addVendor
addProduct
addCurrency
deleteVendor
deleteProduct
deleteCurrency
logout
----------------------------------------------
TestNG Annotations

@Test - The annotated method is a part of a Test case

@BeforeMethod - The annotated method will be run before each Test method
@AfterMetod - The annotated method will be run after each Test method

@BeforeClass - The annotated method will be run before the first Test method in the current class is invoked.
@AfterClass - The annotated method will be run after all the Test methods in the current class have been run.

@BeforeTest -The annotated method will be run before any Test method belonging to classes inside the tag is run.
@AfterTest -The annotated method will be run after all the Test methods belonging to the classes inside the tag.
----------------------------------------------------
V) Grouping Test Cases

XML File for grouping test cases

<suite name = "Suite Name">
<test name = "Test name">
<groups>
<run>
<include name = "group name"/>
</run>
</groups>

<classes>
<class name ="Package.ClassName">
</classes>

</test>
</suite>
-----------------------------------------------------------
1) XML file for executing multiple programs or classes
Tags

suite
test
classes
class

2) XML file for executing test groups

Tags

suite
test

groups
run
include

classes
class
----------------------------------------------------
Class File

public class ClassNew {
@Test(groups = {"sanity", "regression"}, priority=1)
public void login(){
System.out.println("Login Successful");
}
@Test(groups = {"sanity", "regression"}, priority=10)
public void logout(){
System.out.println("Logout Successful");
}   
@Test(groups = {"sanity"}, priority=2)
public void search(){
System.out.println("Search Successful");
}   
@Test(groups = {"regression"}, priority=2)
public void advancedSearch(){
System.out.println("Advanced Search Successful");
}
@Test(groups = {"sanity", "regression"}, priority=3)
public void prepaidRecharge(){
System.out.println("Prepaid Recharge Successful");
}
@Test(groups = {"regression"} , priority=4)
public void billPayments(){
System.out.println("Bill Payments Successful");
}
}
---------------------------------------------------
XML File

<suite name="Suite" parallel="false">
  <test name="Test">
  <groups>
  <run>
  <include name ="regression"/>
   </run>
 
  </groups>
    <classes>
      <class name="seleniumWebDriver.ClassNew"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
--------------------------------------------------------------------
VI) Parallel Test Execution

Thread - A Thread is a concurrent unit of execution

1) Parallel Test Execution Methods

XML File

<suite name="Suite" parallel="methods" thread-count="2">
  <test name="Test">
    <classes>
      <class name="seleniumWebDriver.Class1"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Class File:

public class Class1 {
@Test
public void testCase1(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 1 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase2(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 2 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase3(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 3 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase4(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 4 is Successful" + "Thread id is: "+ id);   
}
}
------------------------------------------------------
2) Parallel Test Execution Classes

XML File

<suite name="Suite" parallel="classes" thread-count="2">
  <test name="Test">
    <classes>
      <class name="seleniumWebDriver.Class1"/>
      <class name="seleniumWebDriver.Class2"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Class 1 File

public class Class1 {
@Test
public void testCase1(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 1 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase2(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 2 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase3(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 3 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase4(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 4 is Successful" + "Thread id is: "+ id);   
}
}

Class 2 File

public class Class2 {
@Test
public void testCase5(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 5 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase6(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 6 is Successful" + "Thread id is: "+ id);   
}
@Test
public void testCase7(){
long id = Thread.currentThread().getId();
System.out.println("Test Case 3 is Successful" + "Thread id is: "+ id);   
}
}
-------------------------------------------------------------
Parallel Test Execution using TestNG - Single Computer
Parallel Test Execution using Selenium Grid - Multiple Computers
-----------------------------------------------------------------------

TestNG Framework for Selenium Part-1 Link

TestNG Testing Framework for Selenium


TestNG Testing Framework for Selenium Part 1

I) Introduction to TestNG

II) Install TestNG and write first TestNG Test Case

III) Create multiple Test Cases and Run

IV) Execute multiple programs / classes using XML
--------------------------------------------------------
I) Introduction to TestNG
In Selenium using Java there are two Testing frameworks available,

i) JUnit

ii) TestNG
------------------------------
TestNG Testing Framework

> TestNG is a Testing framework designed to simplify a broad range of testing needs, 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 functionalities that make it more powerful and easier to use.
-------------------------------------------------------------------
Advantages of TestNG:
1) TestNG Annotations are easy to create Test Cases.

2) Test Cases can be grouped and prioritized more easily.

3) Supports Parameterization.

4) Supports Data driven Testing using DataProviders.

5) Executes multiple programs / classes using XML.

6) Generates HTML Reports

7) Parallel Test Execution is possible.

8) Supports integration with other tools and plug ins (Eclipse IDE, build tools like ANT, Maven etc...)
------------------------------------------------------------------
Note: using TestNG we can create Test Cases, group Test Cases, prioritize Test Case, execute Test Cases and generate Test Reports.
----------------------------------------------------
II) Install TestNG and write first TestNG Test Case

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
-----------------------------------------------
Write first TestNG Test Case:

Manual Test Case:

Test Case name: Verify Title of the Page

Test Steps:

i) Launch the Browser
ii) Navigate to gmail.com

Verification point:

Capture the Page Title and Compare with expected.

Expected = Gmail

Actual =

Status =
-----------------------------------------------------
TestNG Test Case

public class VerifyPagetitle {
@Test
public void verifyTitle(){
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");

String pageTitle = driver.getTitle();
Assert.assertEquals(pageTitle, "Gmail");
driver.close();
}
}
-------------------------------------------------------
Note:

1) main method is not used for TestNG Programs.

2) TestNG program contains only methods that contain @Test Annotations.

3) If we don't write @Test Annotation then the method is not going to be executed.
---------------------------------------------------------------------------------
III) Write multiple Test Cases in a Program

public class VerifyPagetitle {
@Test
public void verifyTitle(){
Assert.assertEquals("Gmail", "Gmail");
}
@Test
public void abcd(){
Assert.assertEquals("Yahoo", "Yahoo");
}
@Test
public void xyz(){
Assert.assertEquals("abcde", "abcde");
}
}

Test Cases as per Program:

verifyTitle
abcd
xyz

Execution Flow:

abcd
verifyTitle
xyz

Note: TestNG Test Cases are execute in Alphabetical order

If you want to control the Test execution process then use priority attribute.


priority attribute Example:

public class VerifyPagetitle {
@Test(priority = 1)
public void verifyTitle(){
Assert.assertEquals("Gmail", "Gmail");
}
@Test (priority = 2)
public void abcd(){
Assert.assertEquals("Yahoo", "Yahoo");
}
@Test (priority = 3)
public void xyz(){
Assert.assertEquals("abcde", "abcde");
}
}
-----------------------------------------------------------
Instead of priority attribute we can use dependsOnMethods attribute
------------------------------------------------------------------
Example:

Using priority attribute

public class VerifyPagetitle {
@Test(priority = 1)
public void login(){
System.out.println("Login Successful");
}
@Test(priority = 4)
public void logout(){
System.out.println("Logout Successful");
}
@Test(priority = 2)
public void search(){
System.out.println("Search Successful");
}
@Test(priority = 3)
public void advancedSearch(){
System.out.println("Advanced Search Successful");
}
}
-----------------------------------------
Using dependsOnMethods attribute

public class VerifyPagetitle {
@Test
public void login(){
System.out.println("Login Successful");
}
@Test(dependsOnMethods = {"advancedSearch"})
public void logout(){
System.out.println("Logout Successful");
}
@Test(dependsOnMethods = {"login"})
public void search(){
System.out.println("Search Successful");
}
@Test(dependsOnMethods = {"search"})
public void advancedSearch(){
System.out.println("Advanced Search Successful");
}
}
------------------------------------------------------
public class VerifyPagetitle {
@Test
public void login(){
Assert.assertEquals("xyz", "xyz");
}
@Test(dependsOnMethods = {"advancedSearch"}, alwaysRun=true)
public void logout(){
Assert.assertEquals("abcder", "abcder");
}
@Test(dependsOnMethods = {"login"})
public void search(){
Assert.assertEquals("abcd", "abcd");
}
@Test(dependsOnMethods = {"search"})
public void advancedSearch(){
Assert.assertEquals("abcd", "xyz");
}
}
--------------------------------------------------
If we use priority attribute then all Test cases can be executed, no skips

If we use dependsOnMethods attribute then it will skip the test case whenever dependsOnMethods
Test case fails, if you want execute the test case forcebly then use alwaysRun attribute.
---------------------------------
Note:

If there is no functionality dependency then use priority attribute.

If there is any functionality dependency then use dependsOnMethods attribute
-----------------------------------------
Scenario 1: No functionality dependency - Use priority attribute

Scenario 2: Functionality dependency - Use dependsOnMethods attribute

Scenario 3: Functionality dependency for some Test Cases only - Use dependsOnMethods and alwaysRun attributes
-----------------------------------------------------------
Test Cases
 

i) Launch Browser
ii) Verify Gmail home Page Title
iii) Verify Yahoo home page Title
iv) Close Browser

TestNG Program:

public class TestngProgram {
public WebDriver driver;
@Test(priority =1)
public void launchBrowser(){
driver = new FirefoxDriver();
}
@Test(priority =2)
public void verifyGmailpage(){
driver.get("https://www.gmail.com");
Assert.assertEquals("Gmail", driver.getTitle());
}
@Test(priority =3)
public void verifyYahoopage(){
driver.get("https://in.yahoo.com/");
Assert.assertEquals("Yahoo", driver.getTitle());
}
@Test(priority =4)
public void closeBrowser(){
driver.close();   
}
}
--------------------------------------------------------
public class TestngProgram {
public WebDriver driver;
@Test
public void launchBrowser(){
driver = new FirefoxDriver();
}
@Test(dependsOnMethods = {"launchBrowser"})
public void verifyGmailpage(){
driver.get("https://www.gmail.com");
Assert.assertEquals("Gmail", driver.getTitle());
}
@Test(dependsOnMethods = {"verifyGmailpage"})
public void verifyYahoopage(){
driver.get("https://in.yahoo.com/");
Assert.assertEquals("Yahoo", driver.getTitle());
}
@Test(dependsOnMethods = {"verifyYahoopage"})
public void closeBrowser(){
driver.close();   
}
}
--------------------------------------------------
public class TestngProgram {
public WebDriver driver;
@Test
public void launchBrowser(){
driver = new FirefoxDriver();
}
@Test(dependsOnMethods = {"launchBrowser"})
public void verifyGmailpage(){
driver.get("https://www.gmail.com");
Assert.assertEquals("Gmail", driver.getTitle());
}
@Test(dependsOnMethods = {"verifyGmailpage"})
public void verifyYahoopage(){
driver.get("https://in.yahoo.com/");
Assert.assertEquals("YahooA", driver.getTitle());
}
@Test(dependsOnMethods = {"verifyYahoopage"}, alwaysRun=true)
public void closeBrowser(){
driver.close();   
}
}
--------------------------------------------------------
Test Cases


Launch Browser - Pre-condition for every Test case
Close Browser - Post-condition for every Test case

i) Verify Gmail home Page Title
ii) Verify Yahoo home page Title

Test Execution Flow:

Launch Browser
Verify Gmail home Page Title
Close Browser

Launch Browser
Verify Yahoo home page Title
Close Browser
--------------------------------------
@BeforeMethod - Pre-condition for every Test case in a Class /Program
@AfterMethod - Post-condition for every Test case in a Class /Program

Example:
public class TestngProgram {
public WebDriver driver;
@BeforeMethod
public void launchBrowser(){
driver = new FirefoxDriver();
}
@Test(priority = 1)
public void verifyGmailpage(){
driver.get("https://www.gmail.com");
Assert.assertEquals("Gmail", driver.getTitle());
}
@Test(priority = 2)
public void verifyYahoopage(){
driver.get("https://in.yahoo.com/");
Assert.assertEquals("Yahoo", driver.getTitle());
}
@AfterMethod
public void closeBrowser(){
driver.close();   
}
}
------------------------------------------------------

TestNG Framework for Selenium Part-2 Link

Writing Selenium Test Cases

Writing Selenium Test Cases
-------------------------------------------------------------------------
Writing Selenium Test Case Part-1 Video

Writing Selenium Test Case Part-2 Video

Writing Selenium Test Case Part-3 Video
-------------------------------------------------------------------------
Prerequisites for writing Selenium WebDriver Test Cases
i) Test Scenario or Manual Test Case

ii) Element Locators - To Locate/Indentify/Recognize Elements

iii) Selenium WebDriver Commands or Methods - To perform operations on Elements

iv) Programming features - To enhance Test Cases

v) JUnit / TestNG Testing Framework Annotations - To group Test Cases, Batch Testing, and generating Test Reports.
----------------------------------------------------------------------
Selenium Test Cases

1) Test Case: Verify Internal and External Links in Wikipedia.org
 

2) Test Case: Verify "Gmail" Link existence in "Google" Home page (Verify Element existence)
 

3) Test Case: Verify Login Functionality in Indian Railways Web Portal
 

4) Test Case: Verify Customer Registration in gcrShop web portal
 

5) Test Case: Verify Customer Login in gcrShop Web portal
 

6) Test Case: Verify Admin Login Functionality in gcrShop web portal (Verification Point for Valid Input)
 

7) Test Case: Verify Admin Login Functionality (Verification Points for Valid input and Invalid Input)
 

8) Test Case: Verify Admin Functionality with valid and invalid inputs (Positive and Negative Testing)
 

9) Test Case: Check communication between different browsers 

10) Data Driven Testing for Admin Login Functionality by fetching test data from an external file (Text file).

11) Writing Selenium WebDriver Test Cases using User defined methods/reusable components.

12) Writing multiple Test Cases in a Program using user defined methods/reusable components.

----------------------------------------------------------------------
1) Test Case: Verify Internal and External Links in Wikipedia.org
Internal Link: It redirects to another Page or location in the same application.

External Link: It redirects to another Page in other application.
------------------------------------
Test Steps:
i) Launch the Browser
ii) Navigate to https://en.wikipedia.org/wiki/Selenium_%28software%29
iii) Click "Create Account" Link
iv) Capture Current URL
v) Navigate back to Selenium Page
vi) Click "selenium.org" Link
vii) Capture Current URL
viii) Close Browser

Verification points:
i) Check if the 1st URL is an Internal Link or not?
ii) Check if the 2nd URL is an External Link or not?

Input Data:
NA
-------------------------------------------------------
Selenium WebDriver Test Case:
WebDriver driver = new FirefoxDriver();
driver.get("https://en.wikipedia.org/wiki/Selenium_%28software%29");
driver.findElement(By.linkText("Create account")).click();
String URL1 = driver.getCurrentUrl();

if (URL1.contains("wikipedia.org")){
System.out.println("It is an Internal Link - Redirected to another page in the Same Application - Passed");
}
else{
System.out.println("It is an External Link - Redirected to another page in Other Application - Failed");
}

driver.navigate().back();
driver.findElement(By.partialLinkText("seleniumhq.org")).click();

String URL2 = driver.getCurrentUrl();

if (! URL2.contains("wikipedia.org")){
System.out.println("It is an External Link - Redirected to another page in Other Application - Passed");
}
else{
System.out.println("It is an Internal Link - Redirected to another page in the Same Application - Failed");
}
driver.close();
----------------------------------------------------------
2) Test Case: Verify "Gmail" Link existence in "Google" Home page (Verify Element existence)

Test Steps:
i) Launch the Browser
ii) Navigate to Google.com (Google Home Page)

Verification Point
i) Check the existence of Gmail Link

Input Data:
NA
----------------------------------
Selenium WebDriver Test Case:
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
boolean linkPresent = driver.findElement(By.linkText("Gmail")).isDisplayed();

if (linkPresent == true){
System.out.println("Gmail Link Exists - Passed");
}
else {
System.out.println("Gmail Link Not Exists -Failed");
}
driver.close();
}
----------------------------------------------
Selenium Test Case with Exception Handling

WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");

try
{
boolean linkPresent = driver.findElement(By.linkText("xyz")).isDisplayed();
if (linkPresent == true){
System.out.println("xyz Link Exists - Passed");
}
}
catch (NoSuchElementException e){
System.out.println("xyz Link Not Exists -Failed");
}
driver.close();
-----------------------------------------------------
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
//boolean linkPresent = driver.findElement(By.linkText("xyz")).isDisplayed();
try

{
if (driver.findElement(By.linkText("xyz")).isDisplayed()){
System.out.println("xyz Link Exists - Passed");
}
}
catch (NoSuchElementException e){
System.out.println("xyz Link Not Exists -Failed");
}
driver.close();
-------------------------------------------------------
3) Test Case: Login to Indian Railways Web Portal
Test Steps:
i) Launch the Browser
ii) Navigate to https://www.irctc.co.in
iii) Enter User ID
iv) Enter Password
v) Enter Captcha (Verification Code)
vi) Click "Login" Button"

Verification Point
Capture URL after Login and Compare with expected URL.

Or

Check the existence of Signout Link
-------------------------------------------------
Input Data:

User ID: gcreddy7  - Static Input
Password: gld938 - Static Input

Captcha: (Dynamic value) -Dynamic Input
---------------------------------------------------------
Selenium WebDriver Test Case:
WebDriver driver = new FirefoxDriver();
driver.get("https://www.irctc.co.in");
driver.findElement(By.id("usernameId")).sendKeys("gcreddy7");
driver.findElement(By.className("loginPassword")).sendKeys("gld938");

Scanner scan = new Scanner(System.in);
System.out.println("Enter Captcha");
String captcha = scan.nextLine();

driver.findElement(By.className("loginCaptcha")).sendKeys(captcha);
driver.findElement(By.id("loginbutton")).click();

try
{
if (driver.findElement(By.xpath(".//*[@id='topnav']/li[7]/ul/li[5]/a/span")).isDisplayed()) {
System.out.println("Login Successful -Passed");
}
}
catch (NoSuchElementException x){
System.out.println("Login Unuccessful -Failed");   
}
driver.close();
-----------------------------------------------------------------------
4) Test Case: Verify Customer Registration in gcrShop web portal

Test Steps:
i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/
iii) Click "create an account" Link
iv) Enter all Mandatory fields
v) Click "Continue" Button

Verification Point:
Capture the conformation message and compare with expected

Expected Message: Your Account Has Been Created!
-------------------------------------------
Selenium WebDriver Test Case:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/");
driver.findElement(By.linkText("create an account")).click();
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).click();
driver.findElement(By.name("firstname")).sendKeys("Niladri");
driver.findElement(By.name("lastname")).sendKeys("abcde");
driver.findElement(By.name("dob")).sendKeys("10/10/1990");
Date date = new Date();
int x = date.getSeconds();
String Email = "abcderty1"+x+"@yahoo.com";
driver.findElement(By.name("email_address")).sendKeys(Email);
driver.findElement(By.name("street_address")).sendKeys("wrr ft etrtyty");
driver.findElement(By.name("postcode")).sendKeys("12345");
driver.findElement(By.name("city")).sendKeys("Hyderabad");
driver.findElement(By.name("state")).sendKeys("Telangana");

Select Dropdown = new Select (driver.findElement(By.name("country")));
Dropdown.selectByVisibleText("India");

driver.findElement(By.name("telephone")).sendKeys("9876787678");
driver.findElement(By.name("password")).sendKeys("abcd123");
driver.findElement(By.name("confirmation")).sendKeys("abcd123");
driver.findElement(By.id("tdb4")).click();

String Message = driver.findElement(By.xpath(".//*[@id='bodyContent']/h1")).getText();

if (Message.equals("Your Account Has Been Created!")){
System.out.println("Customer Registration Successful - Passed");
}
else{
System.out.println("Customer Registration Unsuccessful - Failed");   
}
driver.close();
---------------------------------------------------------
5) Test Case: Verify Customer Login in gcrShop Web portal

Test Steps:

i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/
iii) Click "login" Link
iv) Enter Email Address
v) Enter Password
vi) Click "Sign In" Button
-----------------------
Verification Point:
Capture current url and compare with http://www.gcrit.com/build3/index.php

Input Data:
Email Address: rahman1237@gmail.com
Password: abcd123
--------------------------
Selenium Test Case:

WebDriver driver = new FirefoxDriver();
driver.get("http://gcrit.com/build3/");
driver.findElement(By.linkText("login")).click();
driver.findElement(By.name("email_address")).sendKeys("rahman1237@gmail.com");
driver.findElement(By.name("password")).sendKeys("abcd123");
driver.findElement(By.id("tdb5")).click();
String url = driver.getCurrentUrl();
//System.out.println(url);

if (url.contains("http://www.gcrit.com/build3/index.php")){
System.out.println("Login Successful - Passed");
}
else{
System.out.println("Login Unsuccessful - Failed");
}
driver.close();
-------------------------------------------------
6) Test Case: Verify Admin Login Functionality in gcrShop web portal (Verification Point for Valid Input)

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter Valid User name
iv) Enter Valid Password
v) Click "Login" Button
-------------------------
Verification Point:
Capture the url and compare with expected.

Expected url:http://www.gcrit.com/build3/admin/index.php

Actual:
Test Data:
User name = admin
Password = admin@123
-----------------------------------
Selenium Test Case:

 
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys("admin1");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();

String URL = driver.getCurrentUrl();

if (URL.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Admin Login Successful -Passed");   
}   
else {
System.out.println("Admin Login Unsuccessful -Failed");
}
driver.close();
--------------------------------------
7) Test Case: Verify Admin Login Functionality (Verification Points for Valid input and Invalid Input)

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter Invalid User name and / or Password
iv) Click "Login" Button
----------------------------
Verification points:
1) Capture the url and compare with expected.

Expected url:http://www.gcrit.com/build3/admin/index.php

2) Capture the Error Message and compare with expected.

Expected: Error: Invalid administrator login attempt.

Test Data:
User Name: admina
Password: admin@123
----------------------------------------------------
Selenium Test Case:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys("admin1");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();

String URL = driver.getCurrentUrl();
if (! URL.equals("http://www.gcrit.com/build3/admin/index.php")){
Error_Message = driver.findElement(By.className("messageStackError")).getText();
}

if (URL.equals("http://www.gcrit.com/build3/admin/index.php")) {
System.out.println("Admin Login Successful -Passed");   
}   
else if ((! URL.equals("http://www.gcrit.com/build3/admin/index.php")&& (Error_Message.contains("Error: Invalid administrator login attempt.")))){
System.out.println("Admin Login Unsuccessful and Showing Correct Error Message-Failed");
}
driver.close();
----------------------------------
Assignment:

Verify the maximum Login attempts (For invalid inputs only)
Verification: After 3 attempts it blocks the Login Functionality for 5 minutes.
----------------------------------------------
8) Test Case: Check Admin Functionality with valid and invalid inputs (Positive and Negative Testing)

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter valid "User name"
iv) Enter Valid "Password"
v) Click "Login" Button
---------------
* Repeat the navigation with Invalid User Name and / or Password

Verification points:
i) Capture the url and compare with expected.
Expected: http://www.gcrit.com/build3/admin/index.php

Test Data:
User name = admin
Password = admin@123
--------------
ii) Capture the Error message and compare with expected:
Expected =Error: Invalid administrator login attempt.

Test Data:
User name = admina
Password = admin@123a
(Invalid User name and Invalid Password)

Other Negative Scenarios:

1) Valid User name and Invalid Password
2) Invalid user Name and Valid Password
3) Blank User name and Valid Password/Invalid Password
4) Valid / Invalid User name and Blank password
5) Blank User name and Blank password
-----------------------------------
Selenium Test Case:

public class VerifyAdminlogin {
public static String Error_Message, username, password, iteration;

public static void main(String[] args) {
for (int i =1; i <=2; i++){
if (i == 1){
username ="admin";
password="admin@123";
iteration ="Iteration 1";
}
else if (i == 2){
username ="admin1";
password="admin@123";
iteration ="Iteration 2";   
}

WebDriver driver = new FirefoxDriver();
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();

String URL = driver.getCurrentUrl();
if (! URL.equals("http://www.gcrit.com/build3/admin/index.php")){
Error_Message = driver.findElement(By.className("messageStackError")).getText();
}

if (URL.equals("http://www.gcrit.com/build3/admin/index.php")) {
System.out.println(iteration+" - Admin Login Successful -Passed");   
}   
else if ((! URL.equals("http://www.gcrit.com/build3/admin/index.php")&& (Error_Message.contains("Error: Invalid administrator login attempt.")))){
System.out.println(iteration+" -Admin Login Unsuccessful and Showing Correct Error Message-Failed");
}
driver.close();
}
}
}
----------------------------------------------------------------------
9) Test Case: Verify communication between different browsers
 

Test Steps:
i) Create Mozilla Firefox driver, Google chrome driver and IE driver.
ii) Launch three different applications
iii) Interact from one application to another
iv) Close all browsers one by one.
-------------------------------------------
Selenium Test Case:

WebDriver firefoxDriver = new FirefoxDriver();
firefoxDriver.get("https://www.google.com");
firefoxDriver.findElement(By.linkText("Gmail")).click();
String text = firefoxDriver.findElement(By.xpath("html/body/div[1]/div[2]/div[1]/h2")).getText();

System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
WebDriver chromeDriver = new ChromeDriver();
chromeDriver.get("http://www.gcrit.com/build3/create_account.php?osCsid=1vbg1oj32ole3qrcv4b6mr7m24");
chromeDriver.findElement(By.name("firstname")).sendKeys(text);
Thread.sleep(3000);

System.setProperty("webdriver.ie.driver", "E:\\IEDriverServer.exe");
WebDriver IEDriver = new InternetExplorerDriver();
IEDriver.get("https://in.mail.yahoo.com/");

firefoxDriver.close();
chromeDriver.close();
IEDriver.close();
-----------------------------------------------------------

10) Data Driven Testing for Admin Login Functionality by fetching test data from an external file (Text file).

public class Class1 {
public static WebDriver driver;
public static String error_Message;
public static void main(String[] args) throws IOException {

FileReader file = new FileReader("C:/Users/gcreddy/Desktop/input.txt");
BufferedReader br = new BufferedReader(file);

int Count =0;
int Iteration =0;
String line;
while ((line= br.readLine())!=null){
Count = Count+1;
Iteration = Iteration + 1;
if (Count > 1){
String [] inputData = line.split(" ", 2);   
   
driver = new FirefoxDriver();
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();

String url = driver.getCurrentUrl();

if (! url.equals("http://www.gcrit.com/build3/admin/index.php")){
error_Message = driver.findElement(By.className("messageStackError")).getText();
}

if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println(Iteration+" - Admin Login Successful - Passed");   
}
else if ((! url.equals("http://www.gcrit.com/build3/admin/index.php")) && (error_Message.contains("Error: Invalid administrator login attempt."))){
System.out.println(Iteration+" - Admin Login Unsuccessful and Showing correct Error Message - Failed");   
}
driver.close();
}
}
br.close();
file.close();
}
}
-------------------------------------------------------
11) Writing Selenium WebDriver Test Cases using User defined methods/reusable components.
public static WebDriver driver;

//Launch Browser
public void launchBrowser(){
driver=new FirefoxDriver();
}
//Admin Login without Parameters
public void adminLogin(){
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();
}
//Admin Login without Parameters
public void adminLogin(String Username, String Password){
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
public void closeBrowser(){
if (! driver.toString().contains("null")){
driver.close();   
}
}
public static void main(String[] args) {
Class2    obj = new Class2();
//Test Case 1: Admin Login Test Case (Positive Test Case)
//----------------------------------------------
obj.launchBrowser();
obj.adminLogin();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Test Case 1"+" - Admin Login Successful - Passed");
}
else {
System.out.println("Test Case 1"+" - Admin Login Unsuccessful - Failed");
}
obj.closeBrowser();
//----------------------------------------------   
//Test Case 2: Admin Login (Invalid Input-Negative Testing)   
obj.launchBrowser();
obj.adminLogin("Hyderabad", "admin@123");
String error_Message = driver.findElement(By.className("messageStackError")).getText();
if (error_Message.contains("Error: Invalid administrator login attempt.")){
System.out.println("Test Case 2"+" - Login Successful and Showing Error Message - Passed");
}
else{
System.out.println("Test Case 1"+ " - Login Successful and Not Showing Error Message - Failed");
}
obj.closeBrowser();
//----------------------------------------------   
//Test Case 3: Redirect from Admin Interface to User Interface after Admin Login
obj.launchBrowser();
obj.adminLogin();
driver.findElement(By.linkText("Online Catalog")).click();
String url2 = driver.getCurrentUrl();

if (url2.equals("http://www.gcrit.com/build3/")){
System.out.println("Test Case 3" + " - Redirected to user Interface - Passed");
}
else {
System.out.println("Test Case 3"+" - Not Redirected to user Interface - Failed");
}
obj.closeBrowser();
//----------------------------------------------   
}
}
------------------------------------------------------------------------------
12) Writing multiple Test Cases in a Program using user defined methods/reusable components

public class Class3 extends Class2{

public static void main(String[] args) {
//Create Object
Class3 objNew = new Class3();
objNew.launchBrowser();
//Test Case 1: Admin Login with Valid Inputs
objNew.launchBrowser();
objNew.adminLogin();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Test Case 1"+" - Admin Login Successful - Passed");
}
else {
System.out.println("Test Case 1"+" - Admin Login Unsuccessful - Failed");
}
objNew.closeBrowser();
//Test Case 2: Admin Login with Invalid Inputs
objNew.launchBrowser();
objNew.adminLogin("Hyderabad", "admin@123");
String error_Message = driver.findElement(By.className("messageStackError")).getText();
if (error_Message.contains("Error: Invalid administrator login attempt.")){
System.out.println("Test Case 2"+" - Login Unsuccessful and Showing Error Message - Passed");
}
else{
System.out.println("Test Case 1"+ " - Login Successful and Not Showing Error Message - Failed");
}
objNew.closeBrowser();
//Test Case 3: Redirect from Admin Interface to User Interface
objNew.launchBrowser();
objNew.adminLogin();
driver.findElement(By.linkText("Online Catalog")).click();
String url2 = driver.getCurrentUrl();

if (url2.equals("http://www.gcrit.com/build3/")){
System.out.println("Test Case 3" + " - Redirected to user Interface - Passed");
}
else {
System.out.println("Test Case 3"+" - Not Redirected to user Interface - Failed");
}
objNew.closeBrowser();
}
}
-------------------------------------------------------------------------------
 

Software Test Design Techniques

Software Test Design Techniques

1) Introduction to Software Test Design Techniques

2) Static and Dynamic Test Design Techniques

3) Black box Test Design Techniques

    a) Equivalence Partitioning (EP)

    b) Boundary Value Analysis (BVA)

    c) Decision Table Testing

    d) State Transition Testing

    e) Use Case Testing
--------------------------------------------------
1) Introduction to Software Test Design Techniques
 

> What is Technique?

An Efficient way of doing or achieving something.

> What is Test Design Technique?

A test design technique is used to select a good set of tests from the all possible tests for a given system.

> Why we need to use Test Design Techniques?

Exhaustive Testing is not possible, so we need to use Test Design Techniques in order to reduce the size of the input.

Exhaustive Testing is a Test approach in which the test suite comprises all combination of input values and preconditions.

Exhaustive Testing is not recommendable due to Time and Budget considerations.

> Categories of Test Design Techniques?

There are two main categories of Test Design Techniques, They are:

    a) Static Techniques
    b) Dynamic Techniques
--------------------------------------------------
2) Static and Dynamic Test Design Techniques


A) Static Techniques
 

> Testing of the software documents manually or with a set of tools but without executing the Software.

Two types of static testing techniques

i) Reviews (Manual Examination)

ii) Static Analysis (Automated Analysis)
-------------------------------
i) Reviews
 

Types of Reviews

a) Informal Review
b) Walkthrough
c) Technical Review
d) Inspection

ii) Static Analysis
 

Static analysis tools are typically used by developers, Compilers offer some support for Static analysis,
------------------------------------
B) Dynamic Test Design Techniques
 

> The software is tested by executing it on computer.

Categories of Dynamic Test Design Techniques

i) Specification based or Black box Techniques    a) Equivalence Partitioning (EP)
    b) Boundary Value Analysis (BVA)
    c) Decision Table Testing
    d) State Transition Testing
    e) Use Case Testing Etc...

ii) Structure based or White box Techniques    a) Statement Testing and coverage
    b) Decision Testing and Coverage
    c) Condition Testing, Multi Condition Testing etc...

iii) Experience based Techniques    a) Error Guessing
    b) Exploratory Testing
--------------------------------------------------
3) Black box Test Design Techniques
    

    a) Equivalence Partitioning (EP)

    b) Boundary Value Analysis (BVA)

    c) Decision Table Testing

    d) State Transition Testing

    e) Use Case Testing
--------------------------------------------------
a) Equivalence Partitioning (EP)
 

• It can be applied at any level of testing (Unit, Integration, System and Acceptance Testing)

• In Equivalence Partitioning, inputs to the Software are divided into groups that are expected to exhibit similar behavior.

• Equivalence Partitions/Classes can be found for both valid data and invalid data.

Example 1 (Data Range):

Tickets field in a Reservation system accepts 1 to 10 Tickets only.

Partition 1    Partition 2    Partition 3

0                 1 to 10         11 to 99 or above
(Invalid)       (Valid)          (Invalid)

Example 2 (Data Type):

Customer Identification Number field in a CRM system accepts only numbers.

Partition 1        Partition 2    Partition 3              Partition 4     
Alpha bytes      Numbers     Special Characters    Alpha-numeric 

(Invalid)          (Valid)         (Invalid)                  (Invalid)               

Example 3 (Data Size)

Phone Number filed accepts 10 digits number only

Partition 1    Partition 2    Partition 3
Below 10      10               Above 10
(Invalid)       (Valid)         (Invalid)

Example 4 (Others)

A Payment management system accepts credit card payments only

Partition 1     Partisan 2         Partisan 3
Credit card    Net Banking      Cash on Delivery
(Valid)          (Invalid)            (Invalid)
--------------------------------------------------
b) Boundary Value Analysis (BVA)
 

• The maximum and minimum values of a partition are its boundary values.

• Behavior at edge of each equivalence partition is more likely to be incorrect than behavior within the partition.

• Boundary value analysis can be applied at all Test levels(Unit, Integration, System and Acceptance Testing).

Example 1:
Partition 1    Partition 2    Partition 3

0                  1 to 10        11 to 99 or above
(Invalid)        (Valid)        (Invalid)

Minimum/maximum 0
Minimum 1
Maximum 10
Minimum 11
Maximum 99
-------------------------------------
Example 3 (Data Size)

Phone Number filed accepts 10 digits number only

Partition 1    Partition 2    Partition 3
Below 10      10               Above 10
(Invalid)      (Valid)          (Invalid)

Minimum -9
Minimum and Maximum - 10
Maximum -11
----------------------------------------
Example: User Id field accepts 10 to 20 characters

Partition 1    Partition 2    Partition 3
Below 10     10 to 20        11 to 99

Minimum -1
Maximum - 9

Minimum - 10
Maximum - 20

Minimum - 21
Maximum -99
--------------------------------------------------
c) Decision Table Testing
 

• The decision tables are good way to capture system requirements that contain logical conditions.

• It may be applied for all situations when the action of the software depends on logical decisions.

BSRB (Govt) System Job eligibility criteria,

Age should be in between 21 and 35

Conditions:
i) For SC or ST Candidates 5 Years age relaxation
ii) For BC Candidates 5 Years age relaxation
iii) PHC Candidates 5 Years age relaxation

Category        Age    Valid/Invalid
----------------------------------------------
OC                 20       Invalid
OC                 21       Valid
OC                 35       Valid
OC                 36       Valid
BC                 36       Valid
BC                 39       Invalid
SC                 39       Valid
PHC               39       Valid
ST                 40       Valid
-----------------------------------------------------
Banking System interest rates For fixed deposits.
1 to 2 years 7%
2 to 3 Years 8%
3 to 5 Years 10%

Condition:

For Senior citizens 0.5% extra for all ranges

Age    Period    Interest Rate
-----------------------------------
25     1 year      7%
35     2.5          8%
56     4            10%
66     4            10.5%
--------------------------------------------------
d) State Transition Testing
 

• In State transition Testing Test cases are designed to execute valid and invalid state transitions.

• A System (Application Under Test) may exhibit a different response on current conditions or previous history.

Example: Internet Banking System Fund Transfer operation

Initial Balance: 45000

Transaction 1    Transaction Amount        Transaction
1                       20000                            Successful (Pass)
2                       20000                            Successful (Pass)
3                       20000                            Unsuccessful (Pass)
--------------------------------------------------
e) Use Case Testing
 

• In Use Case Testing Test Cases are designed to execute User Scenarios or Business Scenarios.

• A Use Case describes interactions between actors, including users and the system.

• A Use case usually has a mainstream scenario and sometimes alternative scenarios.

Example:

Business Scenario: ATM Cash Withdrawal operation

Mainstream Scenario:
 

1)
User: Inserts ATM Card

System: Asks for PIN

2)
User: Enters PIN

System: Validates PIN and asks to select language

3)
User: Selects Language

System: Asks to select Account Type

4)
User: Selects Account Type

System: Asks to enter Amount

5)
User: Enters Amount

System: Releases Money
--------------------------------------------------
Alternatives
 

2a) Suppose if user enters invalid Pin

System: Shows error message and asks to enter correct PIN
User: Enters Correct PIN
-----------------------
4a) Suppose if user selects incorrect Account Type

System: Shows error and asks to select correct Account Type
User: Select correct account type

5a) If User enters incorrect amount (More than the balance amount or more than the day limit)

System: Shows Error message and asks to enter correct amount
User: Enters correct amount
--------------------------------------------------