Selenium Tutorial 23: Writing Test Cases

preview_player
Показать описание
Writing Selenium Test Cases tutorial explains Writing Test Cases using Element locators, WebDriver Methods and Java Programming features. Handling NoElementException in Test Cases, Inserting multiple verification points, and Dynamic Test data submission for Captcha fields. Writing Positive and Negative Test Cases using Selenium WebDriver.
Рекомендации по теме
Комментарии
Автор

Class Notes:
Selenium Class 23: Writing Test Cases

Writing Selenium WebDriver Test Cases

i) Test Scenario

ii) Element Locators - To Locate / identify/recognize Elements.

iii) Selenium WebDriver Commands/Methods - To perform Operations on Elements.

iv) Programming Features - To enhance Test cases

v) JUnit/TestNG Annotations - To group Test cases, Batch Testing and generate Test Reports.

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 or location in other application

Test Steps:

i) Launch the Browser
ii) Navigate to Selenium page in Wikipedia.org
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 First URL is an Internal Link or not?
ii) Check if the second URL is an External Link or not?

Selenium Webdriver Test Case:

WebDriver driver = new FirefoxDriver();
account")).click();
String url = driver.getCurrentUrl();
//System.out.println(url);
if
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 the Other Application - Failed");
}
driver.navigate().back();

url = driver.getCurrentUrl();

if (!
System.out.println("It is an External Link - Redirected to another page in the 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 Element Existence (Gmail link existence in Google home page)

Test Steps:

i) Launch the browser
ii) Navigate to Google.com (Google Home page)

Verification point
Check the existence of Gmail link.

Selenium Test Case:

WebDriver driver = new FirefoxDriver();
boolean existence =

if (existence == true){
System.out.println("Gmail Link Exists - Passed");
}
else {
System.out.println("Gmail Link Not Exists - Failed");
}
}
}

WebDriver driver = new FirefoxDriver();

try
{
if
System.out.println("Gmail Link Exists - Passed");
}
}

catch (NoSuchElementException e)
{
System.out.println("Gmail Link Not Exists - Failed");
}
driver.close();
}
}

3) Test Case: Login to Indian Railways Online web portal

Test Steps:
i) Launch the Browser
iii) Enter User Id
iv) Enter Password
v) Enter Captcha (Verification Code)
vi) Click Login Button

Verification Point:

Test Data:
User Id: gcreddy7 (Static Input)
Password: gld938 (Static Input)

Captcha: (Dynamic Input)

Selenium WebDriver Test Case:

WebDriver driver = new FirefoxDriver();



Scanner scan = new is an Input stream
System.out.println("Enter Captcha");
String captcha = scan.nextLine();



String url = driver.getCurrentUrl();

System.out.println("Login Successful - Passed");
}
else{
System.out.println("Login Unsuccessful - Failed");
}
driver.close();
}
}

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

Test Steps:
i) Launch the Browser
iii) Enter all Mandatory fields
iv) Click "Continue" Button

Verification point
Capture conformation message and compare with expected.

WebDriver driver = new FirefoxDriver();
an account")).click();



xyz");




Select Dropdown = new Select








if 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
iii) Click "login" Link
iv) Enter Email Address
v) Enter Password
vi) Click "Sign In" Button

Verification Point:

Selenium Test Case:

WebDriver driver = new FirefoxDriver();



String url = driver.getCurrentUrl();
//System.out.println(url);

System.out.println("Login Successful - Passed");
}
else{
System.out.println("Login Unsuccessful - Failed");
}
driver.close();

gcreddy
Автор

Hello, In place of captch user use to OTP in case what is syntax for otp?

ravalbhargavi
Автор

sir plz provide that handling elements notes class 1 and class 2.

swethasaladi
Автор

Sir you were use Firefoxdriver...can I use chromeDriver then it will be executed or not

vijju
Автор

sir, am following your classes, your way of explanation is very nice.
but am not able to understand that element lcators concepts.
plz help me sir.
and also not that much good in coding concept.
how can i improve my suject .
plz help me sir.

swethasaladi
Автор

Hi sir, can you explain how to pick calender(particular date)

gopikrishnagollaprolu
Автор

im trying but all the time am getting invalid captcha login getting failed ... can you please advise

devsenapati
Автор

i have write selenium java program for test case, but main error
Exception in thread "main" invalid selector: Compound class names not permitted
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b), platform=Windows NT 6.1.7601 SP1 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 40 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:01:03'
System info: host: 'Vinosys-IT', ip: '192.168.0.107', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_121'
Driver info:
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, (cc17746adff54984afff480136733114c6b3704b), userDataDir=C:\Users\user\AppData\Local\Temp\scoped_dir5528_2369}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID:
*** Element info: {Using=class name, value=labeltxt captchacls}
at Method)
at
at
at
at
at
at
at
at
at
at
at

tamilstudio
Автор

Hi Sir, Please share the notes for this class

MahaboobBasha-fckx
Автор

if (existence) is same as if(existence==true)
because here existence=true

biswajitsatpathy