SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Quality Assurance /
Software Testing Training
Selenium WebDriver
Page 2Classification: Restricted
Agenda
• Selenium Components
• Introduction to Web Driver
• Downloading and Configuring Web Driver with Eclipse
• Web Driver Methods
• Web Driver Locators
• Interacting with different UI elements
• Synchronization, Alert and multiple window
• Dynamic Menus
• Cookie Management
• Launching different web browsers
• Introduction to Test NG
Page 3Classification: Restricted
1. Selenium Components
Older version
Supports
multiple
browsers
New version
Supports
multiple
browsers
Record Run
tool with UI.
Works only on
Mozilla
Runs parallel test
cases on multiple
machines and
browsers
Page 4Classification: Restricted
How to install AUT(Orange HRM):
• https://www.orangehrm.com/OrangeHRM_Installation
1. Download ampstack for windows
2. Even if its 32 or 64 bit machine use the download win32 itself
3. 2. https://bitnami.com/stack/orangehrm
4. click on local install
5. bitnami-orangehrm-3.3.2-3-windows
Page 5Classification: Restricted
2. Introduction to Web Driver
• Web Automation framework that allows you to execute tests against
multiple browser
• Main interface for testing
• Creates robust, browser based regression automation suites and tests
• WebDriver has a compact Object Oriented API
• WebDriver overcomes the limitation of Selenium RC
• Provides language support like – Java, C#, Python, Perl, PHP, Ruby
Page 6Classification: Restricted
Selenium IDE Selenium RC Selenium WebDriver
Browser: Firefox Browser: IE, Chrome,
Firefox etc
Browser: IE, Chrome,
Firefox et
Record & Playback No record & playback No record & playback
Server start not needed Server start needed Server start not needed
GUI plug in Java Program Core API
Simple to use Easy & small API Complex & large API
Not object oriented Less Object Oriented Entirely Object
Oriented
Doesn’’t support
moving of mouse cursor
Doesn’’t support
moving of mouse cursor
Supports moving of
mouse cursor
Page 7Classification: Restricted
3. Pre – Requisites to Download
• Java
• Browsers
• IDE – Eclipse or others
• Jar files
For downloading and configuring Selenium Web driver
Refer to the doc
Page 8Classification: Restricted
4. Web Driver Methods
• close ()
• findElement()
• findElements()
• get()
• getCurrentURL()
• getPageSource()
• getTitle()
• getWindowHandle()
• getWindowHandles()
• manage()
• navigate()
• switchTo()
Page 9Classification: Restricted
5. Web Driver Locators
• className
• cssSelector
• Id
• linkText
• Name
• partialLinkText
• tagName
• xPath
Page 10Classification: Restricted
Introduction to Firebug
• The most popular and powerful web development tool
• Inspect HTML and modify style and layout in real time
• Use the most advanced JavaScript debugger available for any browser
• Get the information you need to get it done with firebug
• Download and install firebug from Add-ons in Mozilla Firefox
Page 11Classification: Restricted
Introduction to Firepath
• Firepath is a firebug extension that adds a development tool to edit, inspect
and generate Xpath.
• Download and install fire path
Page 12Classification: Restricted
Challenge 1: Validating message “Invalid Credentials”
• Test Case Steps:
1. Launch the URL for AUT in Firefox
2. Type “admin” in Username text box
3. Type “admin” in Password text box
4. Click on “login” button
• Expected Result
-- Application should display message as “Invalid Credentials”
Page 13Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Challenge1 {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut
h/login");
driver.findElement(By.id("txtUsername")).sendKeys(("admin"));
driver.findElement(By.id("txtPassword")).sendKeys(("admin"));
driver.findElement(By.id("btnLogin")).click();
}
}
Page 14Classification: Restricted
Challenge 2: Validating message “Invalid Credentials”
• Assignment
--Create new java class : LocateById
-- Modify the above script to click on LOGIN button and fetch the error
message and display the same on console
-- Maximize the browser window before visiting the URL
-- Close the browser window after displaying error message on console
--HINT – use ID as locator for all web elements
Page 15Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateById{
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut
h/login");
driver.findElement(By.id("txtUsername")).sendKeys(("admin"));
driver.findElement(By.id("txtPassword")).sendKeys(("admin"));
driver.findElement(By.id("btnLogin")).click();
System.out.println(driver.findElement(By.id("spanMessage")).getText());
driver.close();
}
}
Page 16Classification: Restricted
Challenge 3: Locating By Name
• Assignment :
-- Create new java class: LocateByName
-- Create code for Invalid Login Test Case using Name as Locator for all
applicable WebElements
HINT – use Name as locator for all web elements
Page 17Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByName {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut
h/login");
driver.findElement(By.name("txtUsername")).sendKeys("admin");
driver.findElement(By.name("txtPassword")).sendKeys("admin");
driver.findElement(By.name("Submit")).click();
System.out.println(driver.findElement(By.id("spanMessage")));
driver.close();
}
Page 18Classification: Restricted
Challenge 4: Clicking on a link on a web page
• Test case Steps:
1. Login to Orange HRM
2. Click on Directory link
• Expected Result
-- Directory panel should get displayed
• HINT – use LinkText as locator for clicking link
Page 19Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByLinkText {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login")
;
driver.findElement(By.id("txtUsername")).sendKeys(("admin"));
driver.findElement(By.id("txtPassword")).sendKeys(("seedadmin"));
driver.findElement(By.id("btnLogin")).click();
//driver.findElement(By.id("menu_directory_viewDirectory")).click();
driver.findElement(By.linkText("Directory")).click();
driver.close();
}
}
Page 20Classification: Restricted
Challenge 5: Clicking on a link on a web page
• Test case Steps:
1. Login to Orange HRM
2. Click on Directory link
• Expected Result
-- Directory panel should get displayed
• HINT – use PartialLinkText as locator for clicking link
Page 21Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByPartialLinkText {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut
h/login");
driver.findElement(By.id("txtUsername")).sendKeys(("admin"));
driver.findElement(By.id("txtPassword")).sendKeys(("seedadmin"));
driver.findElement(By.id("btnLogin")).click();
driver.findElement(By.partialLinkText("Dir")).click();
driver.close();
}
}
Page 22Classification: Restricted
Challenge 6: Validating Message “Username cannot be empty”
• Test Case steps
1. Launch Orange HRM
2. Click on Login button
• Expected Result
-- Application should display message as “Username cannot be empty”
Page 23Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut
h/login");
driver.findElement(By.className("button")).click();
String msg= driver.findElement(By.id("spanMessage")).getText();
System.out.println("Message is" + msg);
driver.close();
}
}
Page 24Classification: Restricted
Difference between findElement & findElements
• findElement() findElements()
-Find the first web element - Find all the elements
Using the given method within the current page
using the given
mechanism
- Returns Web Element - Returns List
Page 25Classification: Restricted
Challenge 7: Displaying default text in Login text boxes
• Test Case steps
1. Launch Orange HRM
• Expected Result
-- Default text in Username text box should be Username
-- Default text in Password text box should be Password
Page 26Classification: Restricted
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByTagName {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
List<WebElement> allspans = driver.findElements(By.tagName("span"));
System.out.println("No: of span tags" +allspans.size());
/* for(int i =0; i < allspans.size(); i++) {
System.out.println("Default text:"+allspans.get(i).getText());
} */
for (WebElement we : allspans){
System.out.println(we.getText());
}
driver.close();
}
}
Page 27Classification: Restricted
Challenge 8: Validating message “Password can not be empty
• Test Case steps
1. Launch Orange HRM
2. Type “admin” in the username text box
3. Click on Login button
• Expected Result
-- Application should display message as “Password cannot be empty”
Page 28Classification: Restricted
CSS Selector
• Using single attribute
-- syntax: tagname[attribute=‘value’]
• Using multiple attribute
--syntax: tagname[attribute=‘value’] [attribute=‘value’]
• Special symbols
- . (Dot) for class
- Syntax: tagname.class
- # for name
- Syntax: tagname#id
Page 29Classification: Restricted
Challenge 9: Validating message “Password can not be empty
• Test Case steps
1. Launch Orange HRM
2. Type “admin” in the username text box
3. Click on Login button
• Expected Result
-- Application should display message as “Password cannot be empty
Hint: use By cssSelector: Single Attribute
Page 30Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByCss {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
driver.findElement(By.id("txtUsername")).sendKeys("admin");
driver.findElement(By.cssSelector("input[value='LOGIN']")).click();
String msg = driver.findElement(By.id("spanMessage")).getText();
System.out.println("Message is " +msg);
driver.close();
}
}
Page 31Classification: Restricted
Challenge 10: Validating message “Password can not be empty
• Test Case steps
1. Launch Orange HRM
2. Type “admin” in the username text box
3. Click on Login button
• Expected Result
-- Application should display message as “Password cannot be empty
Hint: use By cssSelector: Multiple Attributes
Page 32Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocateByCss {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login")
;
driver.findElement(By.id("txtUsername")).sendKeys("admin");
driver.findElement(By.cssSelector("input[class=‘button’’][value='LOGIN']")).click();
String msg = driver.findElement(By.id("spanMessage")).getText();
System.out.println("Message is " +msg);
driver.close();
}
}
Page 33Classification: Restricted
XPath
• What is Xpath?
• The XML path language , is a query language for selecting nodes from an
XML document
• Types of Xpath:
1. Absolute : Always starts with html
2. Relative : Always starts with //
Syntax: //tagname[@attribute=‘value’]
Page 34Classification: Restricted
Challenge 11: Validating message “Welcome Admin”
• Test case Steps:
1. Launch the application
2. Login to Orange HRM application
• Expected Result:
- Application should display message as “Welcome Admin”
- Hint: use Absolute Xpath
Page 35Classification: Restricted
Solution: Validating Message: “Welcome Admin” By Xpath Absolute
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AbsolutePath {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login")
;//absolute xpath
driver.findElement(By.xpath("html/body/div/div/div/form/div[2]/input")).sendKeys(
"admin");
driver.findElement(By.xpath("html/body/div/div/div/form/div[3]/input")).sendKeys(
"seedadmin");
driver.findElement(By.xpath("html/body/div/div/div/form/div[5]/input")).click();
System.out.println(driver.findElement(By.xpath("html/body/div/div/a[2]")).getText(
));
}
}
Page 36Classification: Restricted
Challenge 12: Validating message “Welcome Admin”
• Test case Steps:
1. Launch the application
2. Login to Orange HRM application
• Expected Result:
- Application should display message as “Welcome Admin”
- Hint: use Relative Xpath
Page 37Classification: Restricted
Solution: Validating Message: “Welcome Admin” By Xpath Relative
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class RelativePath {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
/*driver.findElement(By.xpath(".//*[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath(".//*[@id='txtPassword']")).sendKeys("seedadmin");
driver.findElement(By.xpath(".//*[@id='btnLogin']")).click();*/
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin")
;
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
String msg = driver.findElement(By.xpath("//a[@id='welcome']")).getText();
//String msg = driver.findElement(By.xpath(".//*[@id='welcome']")).getText();
System.out.println("Message is:" +msg);
}
}
Page 38Classification: Restricted
Web Element Methods
• isDisplayed() : is this element displayed or not? This method avoids the
problem of having to parse an elements “style” attribute.
• isEnabled() : is the element currently enabled or not? This will generally
return true for everything but disabled input elements
• isSelected(): determine whether or not this element is selected or not
• All the above methods returns boolean
Page 39Classification: Restricted
Challenge 13: Add Employee with Create Login details
• Test Case steps:
1. Launch the application
2. Login to Orange HRM application
3. Click on PIM  Add Employee
4. Select create login details option
• Expected result:
Create login details option should get selected
Page 40Classification: Restricted
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class InteractWithChkBox {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin");
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
driver.findElement(By.linkText("PIM")).click();
driver.findElement(By.linkText("Add Employee")).click();
WebElement cb = driver.findElement(By.id("chkLogin"));
//if there is a chkbox with this id and if its displayed and enabled but not selected then click
if (cb.isDisplayed()){
if(cb.isEnabled()){
if(cb.isSelected()==false) {
cb.click();
}}
}driver.close();
Page 41Classification: Restricted
Challenge 14: Employee’s Gender
• Test Case steps:
1. Launch the application
2. Login to Orange HRM application
3. Click on PIM  Add Employee
4. Click on any employee
• Expected result:
- Under personal details Gender should be present as Male and Female
- Both options should be disabled before clicking on Edit button
- Both options should become enabled after clicking on Edit button
Page 42Classification: Restricted
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class InteractWithRadio {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin");
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
driver.findElement(By.linkText("PIM")).click();
driver.findElement(By.linkText("Employee List")).click();
driver.findElement(By.linkText("Charu Anil")).click();
//construct the absolute path from the code
}
Page 43Classification: Restricted
List<WebElement> genderLabel = driver.findElements(By.xpath("//ul[@class='radio_list']/li/label"));
for(WebElement we:genderLabel){
System.out.println(we.getText());
}
List<WebElement> gender= driver.findElements(By.xpath("//ul[@class='radio_list']/li/input"));
System.out.println("Status before clicking on Edit Button");
for(WebElement we:gender){
System.out.println(we.isEnabled());
}
driver.findElement(By.id("btnSave")).click();
System.out.println("Status after clicking on Save Button");
for(WebElement we:gender) {
System.out.println(we.isEnabled());
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.partialLinkText("Welcome")).click();
driver.findElement(By.linkText("Logout")).click();
driver.close();
}
Page 44Classification: Restricted
Challenge 15: Country List
• Test Case steps
1. Launch the application
2. Login to orange HRM
3. Click on PIMEmployee list
4. Click on any Employee
5. Click on edit button
6. Select indian as a nationality
• Expected Result
- Default Selected option should be –Select—
- The Nationality drop down should have 100 countries listed
- India should get selected as a nationality
Page 45Classification: Restricted
Select Class
• Models SELECT tag providing helper methods to select and deselect options
• Parameterized Constructor
• Methods:
- getFirstSelectedOption() : returns first selected option in this Select tag
- selectByIndex(): Select the option at given index
- selectByValue(): Select all options that have a value matching the argument
- selectByVisibleText(): Select all options that display test matching the
argument
- getOptions(): returns all options belonging to this select tag
Page 46Classification: Restricted
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class InteractWithDropDown {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin");
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
driver.findElement(By.linkText("PIM")).click();
driver.findElement(By.linkText("Employee List")).click();
driver.findElement(By.linkText("Charu Anil")).click();
//click on the edit button first to activate it
driver.findElement(By.id("btnSave")).click();
}
Page 47Classification: Restricted
WebElement cmbNation = driver.findElement(By.id("personal_cmbNation"));
Select nationality = new Select(cmbNation);
System.out.println("Default Selection:" + nationality.getFirstSelectedOption().getText());
//Get all count of nationality
List<WebElement> nationalities = nationality.getOptions();
System.out.println("Total no: of Nationalities:" + nationalities.size());
//List all nationality
int i = 1;
for (WebElement we: nationalities) {
System.out.println(i+"."+we.getText());
i++;
}//Select India as Nationality by 3 methods
//select byindex
/*nationality.selectByIndex(82);
System.out.println("New Selection Made by index method:"+nationality.getFirstSelectedOption().getText()); */
//select byvisible text
/*nationality.selectByVisibleText("Indian");
System.out.println("New Selection Made by visible text method:"+nationality.getFirstSelectedOption().getText());
*/
nationality.selectByValue("82");
System.out.println("New Selection Made by value method:" +nationality.getFirstSelectedOption().getText());
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.partialLinkText("Welcome")).click();
driver.findElement(By.linkText("Logout")).click();
driver.close();
}
Page 48Classification: Restricted
Challenge 16: Handling Table
• Test Case Steps
1. Launch the application
2. Login to Orange HRM application
3. Click on PIM Employee list
• Expected Result
- In Employee table eight columns should be present
- Last seven columns should be (Id, first Name , last name, job title,
Employment status, Sub unit, supervisor
- In employee table on single page maximum 10 records should be
present
Page 49Classification: Restricted
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class InteractWithTable {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login");
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin");
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
driver.findElement(By.linkText("PIM")).click();
driver.findElement(By.linkText("Employee List")).click();
Page 50Classification: Restricted
//Check eight columns are present
List<WebElement> tblcolumn =
driver.findElements(By.xpath(".//*[@id='resultTable']/thead/tr/th"));
System.out.println("Table size:" + tblcolumn.size());
//Check for last seven columns
List<WebElement> lastseven =
driver.findElements(By.xpath(".//*[@class='header']"));
System.out.println("Total column" + lastseven.size());
//Table should have maximum number of 10 records
List<WebElement> records =
driver.findElements(By.xpath(".//*[@id='resultTable']/tbody/tr"));
if (records.size() <10) {
System.out.println("Total records within range");
}else {
System.out.println("Total records are out of range");
}
}
}
Page 51Classification: Restricted
Challenge 17: Handling Screen Shots
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetScreenShot {
//Taking a Pic of the webpage
public static void main(String[] args) throws IOException {
WebDriver driver = new FirefoxDriver();
driver.get("https://mail.rediff.com/cgi-bin/login.cgi");
TakesScreenshot ts = (TakesScreenshot)driver;
File src = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("E:venki-
backupSeleniumSeed_SelExSeleniumExScreenShotsrediff.png"));
System.out.println("Screen shot taken");
driver.close();
}
}
Page 52Classification: Restricted
Challenge 18: Handling Java Script Alerts
• To handle alert window in Selenium Web driver we have predefined
Interface known as Alert .
• 1- accept()- Will click on the ok button when an alert comes.
• 2- dismiss()- Will click on cancel button when an alert comes
Test Case Steps:
Step 1-Open Firefox and open rediff mail website.
Step 2- Enter username and Click on Go button.
Step 3- Capture the Alert text.
Step 4- Click on the OK button.
Page 53Classification: Restricted
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://mail.rediff.com/cgi-bin/login.cgi");
driver.manage().window().maximize();
driver.findElement(By.id("login1")).sendKeys("admin");
driver.findElement(By.name("proceed")).click();
//Switch to alert window and capture the text and print
String alertmsg = driver.switchTo().alert().getText();
System.out.println("Alert message displayed is" + alertmsg);
//Click the ok button inside the alert box
driver.switchTo().alert().accept();
//Click the cancel button inside the alert box
//driver.switchTo().alert().dismiss();
driver.close();
}
Page 54Classification: Restricted
Challenge 19: Cookie Management
• WebDriver options():
- addCookie()
- deleteAllCookies()
- deleteCookieNamed()
- getCookieNamed()
- getCookies()
• Cookie Class:
- getDomain()
- getExpiry()
- getName()
- getPath()
- getValue()
Page 55Classification: Restricted
import java.util.Set;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetCookie {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String url =“ http://flipkart.com/”;
driver.navigate().to(url);
//Adding a new cookie
Cookie name = new Cookie(“mycookie”, “123457”);
driver.manage().addCookie(name);
//Getting all the cookie
Set<Cookie> cookiesList = driver.manage().getCookies();
for(Cookie getcookies : cookiesList) {
System.out.println(getcookies);
}
//delete the added cookie
System.out.println(“deleting cookie…”);
driver.manage().deleteCookieNamed(“mycookie”);
Set<cookie> newcookiesList = driver.manage().getCookies();
for(Cookie getcookies: newcookiesList) {
System.out.println(getcookies);
}
driver.quit();
} }
Page 56Classification: Restricted
Launching in Different Browsers
• In Internet Explorer
• In Google Chrome
Page 57Classification: Restricted
Challenge 20: Launch IE
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class LaunchingIE {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","C:AdvancedSeleniumSo
ftwaresIEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.p
hp/auth/login");
}
}
Page 58Classification: Restricted
Challenge 21: Launch Google Chrome
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchingChrome {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C:AdvancedSeleni
umSoftwareschromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.p
hp/auth/login");
}
}
Page 59Classification: Restricted
Challenge 22: Create test case using Mozila firefox, IE, Chrome
• Test case Steps
1. Launch the application “google”
2. Using 3 different browsers -- firefox – IE -- chrome
3. Get the page title from all the browsers.
Page 60Classification: Restricted
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class LaunchBrowsers_for {
public static WebDriver driver;
public static int browser;
public static String browsername;
public static void main(String[] args) {
for (browser=1; browser<=3; browser++) {
if(browser == 1) {
driver = new FirefoxDriver();
browsername = "Mozila Firefox Browser";
}
else if (browser ==2) {
System.setProperty("webdriver.ie.driver", "E:venki-
backupSeleniumSoftwareIEDriverServer.exe");
driver = new InternetExplorerDriver();
browsername = "Internet Explorer Browser";
}
Page 61Classification: Restricted
else if(browser ==3) {
System.setProperty("webdriver.chrome.driver", "E:venki-
backupSeleniumSoftwarechromedriver.exe");
driver = new ChromeDriver();
browsername = "Chrome Browser";
}
driver.get("https://www.google.com");
String pgtitle = driver.getTitle();
if(pgtitle.equals("Google")) {
System.out.println(browsername + "_Google launch passed");
}
else {
System.out.println(browsername + "_Google launch failed");
}
driver.close();
}
}
}
Page 62Classification: Restricted
TestNG Framework
• TestNG is an advance framework designed in a way to leverage the
benefits by both the developers and testers.
• TestNG was created by an acclaimed programmer named as “Cedric Beust”.
• TestNG with WebDriver gives efficient and effective test result format to
generate test reports.
• TestNG has an inbuilt exception handling mechanism which lets the
program to run without terminating unexpectedly.
Page 63Classification: Restricted
Features of TestNG
• Support for annotations
• Support for Data Driven Testing using Dataproviders
• Enables user to set execution priorities for the test methods
• Supports threat safe environment when executing multiple threads
• Readily supports integration with various tools and plug-ins like build tools
(Ant, Maven etc.), Integrated Development Environment (Eclipse).
• Facilitates user with effective means of Report Generation using ReportNG
Page 64Classification: Restricted
Annotations
• @Test: annotated method is part of test case
• @BeforeTest: annotated method will run before any test method belonging
to classes inside the tag is run
• @AfterTest: annotated method will run after all the test methods
belonging to classes inside the tag is run
• @BeforeMethod: annotated method will run before each test method
• @AfterMethod: annotated method will run after each test method
• @BeforeSuite: annoatated method will run before all tests in this suite
have run
• @AfterSuite: annotated method will run after all tests in this suite have run
Page 65Classification: Restricted
Generating Report using TestNG
• TestCase Steps:
1. Launch the applicaton http://newtours.demoaut.com
2. Goto home page verify its page title
3. Close the application
Page 66Classification: Restricted
Import org.testng.Assert;
Import org.openqa.selenium.WebDriver;
Import org.openqa.selenium.firefox.FirefoxDriver;
Import org.testng.annotations.Test;
Import org.testng.annotations.BeforeTest;
Import org.testng.annotations.AfterTest;
Public class TestNG1 {
public String baseurl = http://newtours.demoaut.com;
public WebDriver driver;
@BeforeTest
Public void setBaseurl( ) {
driver = new FirefoxDriver();
driver.get(baseurl);
}
@Test
Public void verifyTitle() {
String expectedtitle = “Welcome Mercury Tours”;
String actualtitle = driver.getTitle();
Assert.assertEquals(actualtitle , expectedtitle);
}
@AfterTest
Public void endSession() {
driver.close();
}
}
Page 67Classification: Restricted
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and SeleniumKarapet Sarkisyan
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with JavaFayis-QA
 
Automated testing using Selenium & NUnit
Automated testing using Selenium & NUnitAutomated testing using Selenium & NUnit
Automated testing using Selenium & NUnitAlfred Jett Grandeza
 
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...Simplilearn
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using seleniumshreyas JC
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesVijay Rangaiah
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automationSrikanth Vuriti
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Edureka!
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introductionPankaj Dubey
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Simplilearn
 
Webinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation UncomplicatedWebinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation UncomplicatedEdureka!
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 

Was ist angesagt? (20)

Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with Java
 
Automated testing using Selenium & NUnit
Automated testing using Selenium & NUnitAutomated testing using Selenium & NUnit
Automated testing using Selenium & NUnit
 
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automation
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium
 
Selenium-Locators
Selenium-LocatorsSelenium-Locators
Selenium-Locators
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introduction
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
 
SELENIUM PPT.pdf
SELENIUM PPT.pdfSELENIUM PPT.pdf
SELENIUM PPT.pdf
 
Webinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation UncomplicatedWebinar: Selenium WebDriver - Automation Uncomplicated
Webinar: Selenium WebDriver - Automation Uncomplicated
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 

Ähnlich wie Here are the steps to validate the message "Password cannot be empty":1. Launch the OrangeHRM application URL2. Enter a valid username 3. Keep the password field empty4. Click on the login button5. Validate that the message "Password cannot be empty" is displayedThe code will be:import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class ValidatePasswordMessage { public static void main(String args) { WebDriver driver = new FirefoxDriver(); driver.get("OrangeHRM URL"); driver.find

Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Rashedul Islam
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousaEmma Armstrong
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterBoni García
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaEr. Sndp Srda
 
Selenium for Tester.pdf
Selenium for Tester.pdfSelenium for Tester.pdf
Selenium for Tester.pdfRTechRInfoIT
 
Selenium Automation in Java Using HttpWatch Plug-in
 Selenium Automation in Java Using HttpWatch Plug-in  Selenium Automation in Java Using HttpWatch Plug-in
Selenium Automation in Java Using HttpWatch Plug-in Sandeep Tol
 
Complete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdfComplete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdframya9288
 
Selenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit PathakSelenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit PathakSoftware Testing Board
 
Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Kazuaki Matsuo
 
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptxTop 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptxAnanthReddy38
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsNick Belhomme
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
Whys and Hows of Automation
Whys and Hows of AutomationWhys and Hows of Automation
Whys and Hows of AutomationvodQA
 

Ähnlich wie Here are the steps to validate the message "Password cannot be empty":1. Launch the OrangeHRM application URL2. Enter a valid username 3. Keep the password field empty4. Click on the login button5. Validate that the message "Password cannot be empty" is displayedThe code will be:import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class ValidatePasswordMessage { public static void main(String args) { WebDriver driver = new FirefoxDriver(); driver.get("OrangeHRM URL"); driver.find (20)

Web driver training
Web driver trainingWeb driver training
Web driver training
 
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousa
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
 
Selenium for Tester.pdf
Selenium for Tester.pdfSelenium for Tester.pdf
Selenium for Tester.pdf
 
Selenium Automation in Java Using HttpWatch Plug-in
 Selenium Automation in Java Using HttpWatch Plug-in  Selenium Automation in Java Using HttpWatch Plug-in
Selenium Automation in Java Using HttpWatch Plug-in
 
Complete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdfComplete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdf
 
Introduction to selenium web driver
Introduction to selenium web driverIntroduction to selenium web driver
Introduction to selenium web driver
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Selenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit PathakSelenium Java for Beginners by Sujit Pathak
Selenium Java for Beginners by Sujit Pathak
 
Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)Chrome Devtools Protocol via Selenium/Appium (English)
Chrome Devtools Protocol via Selenium/Appium (English)
 
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptxTop 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Whys and Hows of Automation
Whys and Hows of AutomationWhys and Hows of Automation
Whys and Hows of Automation
 

Mehr von Rajathi-QA

Core Java for Selenium
Core Java for SeleniumCore Java for Selenium
Core Java for SeleniumRajathi-QA
 
Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)Rajathi-QA
 
Other Testing Types
Other Testing TypesOther Testing Types
Other Testing TypesRajathi-QA
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software TestingRajathi-QA
 
Defects and Categories
Defects and CategoriesDefects and Categories
Defects and CategoriesRajathi-QA
 
Test Execution
Test ExecutionTest Execution
Test ExecutionRajathi-QA
 

Mehr von Rajathi-QA (8)

HP ALM
HP ALMHP ALM
HP ALM
 
JIRA
JIRAJIRA
JIRA
 
Core Java for Selenium
Core Java for SeleniumCore Java for Selenium
Core Java for Selenium
 
Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)
 
Other Testing Types
Other Testing TypesOther Testing Types
Other Testing Types
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Defects and Categories
Defects and CategoriesDefects and Categories
Defects and Categories
 
Test Execution
Test ExecutionTest Execution
Test Execution
 

Kürzlich hochgeladen

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Here are the steps to validate the message "Password cannot be empty":1. Launch the OrangeHRM application URL2. Enter a valid username 3. Keep the password field empty4. Click on the login button5. Validate that the message "Password cannot be empty" is displayedThe code will be:import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class ValidatePasswordMessage { public static void main(String args) { WebDriver driver = new FirefoxDriver(); driver.get("OrangeHRM URL"); driver.find

  • 1. Quality Assurance / Software Testing Training Selenium WebDriver
  • 2. Page 2Classification: Restricted Agenda • Selenium Components • Introduction to Web Driver • Downloading and Configuring Web Driver with Eclipse • Web Driver Methods • Web Driver Locators • Interacting with different UI elements • Synchronization, Alert and multiple window • Dynamic Menus • Cookie Management • Launching different web browsers • Introduction to Test NG
  • 3. Page 3Classification: Restricted 1. Selenium Components Older version Supports multiple browsers New version Supports multiple browsers Record Run tool with UI. Works only on Mozilla Runs parallel test cases on multiple machines and browsers
  • 4. Page 4Classification: Restricted How to install AUT(Orange HRM): • https://www.orangehrm.com/OrangeHRM_Installation 1. Download ampstack for windows 2. Even if its 32 or 64 bit machine use the download win32 itself 3. 2. https://bitnami.com/stack/orangehrm 4. click on local install 5. bitnami-orangehrm-3.3.2-3-windows
  • 5. Page 5Classification: Restricted 2. Introduction to Web Driver • Web Automation framework that allows you to execute tests against multiple browser • Main interface for testing • Creates robust, browser based regression automation suites and tests • WebDriver has a compact Object Oriented API • WebDriver overcomes the limitation of Selenium RC • Provides language support like – Java, C#, Python, Perl, PHP, Ruby
  • 6. Page 6Classification: Restricted Selenium IDE Selenium RC Selenium WebDriver Browser: Firefox Browser: IE, Chrome, Firefox etc Browser: IE, Chrome, Firefox et Record & Playback No record & playback No record & playback Server start not needed Server start needed Server start not needed GUI plug in Java Program Core API Simple to use Easy & small API Complex & large API Not object oriented Less Object Oriented Entirely Object Oriented Doesn’’t support moving of mouse cursor Doesn’’t support moving of mouse cursor Supports moving of mouse cursor
  • 7. Page 7Classification: Restricted 3. Pre – Requisites to Download • Java • Browsers • IDE – Eclipse or others • Jar files For downloading and configuring Selenium Web driver Refer to the doc
  • 8. Page 8Classification: Restricted 4. Web Driver Methods • close () • findElement() • findElements() • get() • getCurrentURL() • getPageSource() • getTitle() • getWindowHandle() • getWindowHandles() • manage() • navigate() • switchTo()
  • 9. Page 9Classification: Restricted 5. Web Driver Locators • className • cssSelector • Id • linkText • Name • partialLinkText • tagName • xPath
  • 10. Page 10Classification: Restricted Introduction to Firebug • The most popular and powerful web development tool • Inspect HTML and modify style and layout in real time • Use the most advanced JavaScript debugger available for any browser • Get the information you need to get it done with firebug • Download and install firebug from Add-ons in Mozilla Firefox
  • 11. Page 11Classification: Restricted Introduction to Firepath • Firepath is a firebug extension that adds a development tool to edit, inspect and generate Xpath. • Download and install fire path
  • 12. Page 12Classification: Restricted Challenge 1: Validating message “Invalid Credentials” • Test Case Steps: 1. Launch the URL for AUT in Firefox 2. Type “admin” in Username text box 3. Type “admin” in Password text box 4. Click on “login” button • Expected Result -- Application should display message as “Invalid Credentials”
  • 13. Page 13Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Challenge1 { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut h/login"); driver.findElement(By.id("txtUsername")).sendKeys(("admin")); driver.findElement(By.id("txtPassword")).sendKeys(("admin")); driver.findElement(By.id("btnLogin")).click(); } }
  • 14. Page 14Classification: Restricted Challenge 2: Validating message “Invalid Credentials” • Assignment --Create new java class : LocateById -- Modify the above script to click on LOGIN button and fetch the error message and display the same on console -- Maximize the browser window before visiting the URL -- Close the browser window after displaying error message on console --HINT – use ID as locator for all web elements
  • 15. Page 15Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateById{ public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut h/login"); driver.findElement(By.id("txtUsername")).sendKeys(("admin")); driver.findElement(By.id("txtPassword")).sendKeys(("admin")); driver.findElement(By.id("btnLogin")).click(); System.out.println(driver.findElement(By.id("spanMessage")).getText()); driver.close(); } }
  • 16. Page 16Classification: Restricted Challenge 3: Locating By Name • Assignment : -- Create new java class: LocateByName -- Create code for Invalid Login Test Case using Name as Locator for all applicable WebElements HINT – use Name as locator for all web elements
  • 17. Page 17Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByName { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut h/login"); driver.findElement(By.name("txtUsername")).sendKeys("admin"); driver.findElement(By.name("txtPassword")).sendKeys("admin"); driver.findElement(By.name("Submit")).click(); System.out.println(driver.findElement(By.id("spanMessage"))); driver.close(); }
  • 18. Page 18Classification: Restricted Challenge 4: Clicking on a link on a web page • Test case Steps: 1. Login to Orange HRM 2. Click on Directory link • Expected Result -- Directory panel should get displayed • HINT – use LinkText as locator for clicking link
  • 19. Page 19Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByLinkText { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login") ; driver.findElement(By.id("txtUsername")).sendKeys(("admin")); driver.findElement(By.id("txtPassword")).sendKeys(("seedadmin")); driver.findElement(By.id("btnLogin")).click(); //driver.findElement(By.id("menu_directory_viewDirectory")).click(); driver.findElement(By.linkText("Directory")).click(); driver.close(); } }
  • 20. Page 20Classification: Restricted Challenge 5: Clicking on a link on a web page • Test case Steps: 1. Login to Orange HRM 2. Click on Directory link • Expected Result -- Directory panel should get displayed • HINT – use PartialLinkText as locator for clicking link
  • 21. Page 21Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByPartialLinkText { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut h/login"); driver.findElement(By.id("txtUsername")).sendKeys(("admin")); driver.findElement(By.id("txtPassword")).sendKeys(("seedadmin")); driver.findElement(By.id("btnLogin")).click(); driver.findElement(By.partialLinkText("Dir")).click(); driver.close(); } }
  • 22. Page 22Classification: Restricted Challenge 6: Validating Message “Username cannot be empty” • Test Case steps 1. Launch Orange HRM 2. Click on Login button • Expected Result -- Application should display message as “Username cannot be empty”
  • 23. Page 23Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByClass { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/aut h/login"); driver.findElement(By.className("button")).click(); String msg= driver.findElement(By.id("spanMessage")).getText(); System.out.println("Message is" + msg); driver.close(); } }
  • 24. Page 24Classification: Restricted Difference between findElement & findElements • findElement() findElements() -Find the first web element - Find all the elements Using the given method within the current page using the given mechanism - Returns Web Element - Returns List
  • 25. Page 25Classification: Restricted Challenge 7: Displaying default text in Login text boxes • Test Case steps 1. Launch Orange HRM • Expected Result -- Default text in Username text box should be Username -- Default text in Password text box should be Password
  • 26. Page 26Classification: Restricted import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByTagName { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); List<WebElement> allspans = driver.findElements(By.tagName("span")); System.out.println("No: of span tags" +allspans.size()); /* for(int i =0; i < allspans.size(); i++) { System.out.println("Default text:"+allspans.get(i).getText()); } */ for (WebElement we : allspans){ System.out.println(we.getText()); } driver.close(); } }
  • 27. Page 27Classification: Restricted Challenge 8: Validating message “Password can not be empty • Test Case steps 1. Launch Orange HRM 2. Type “admin” in the username text box 3. Click on Login button • Expected Result -- Application should display message as “Password cannot be empty”
  • 28. Page 28Classification: Restricted CSS Selector • Using single attribute -- syntax: tagname[attribute=‘value’] • Using multiple attribute --syntax: tagname[attribute=‘value’] [attribute=‘value’] • Special symbols - . (Dot) for class - Syntax: tagname.class - # for name - Syntax: tagname#id
  • 29. Page 29Classification: Restricted Challenge 9: Validating message “Password can not be empty • Test Case steps 1. Launch Orange HRM 2. Type “admin” in the username text box 3. Click on Login button • Expected Result -- Application should display message as “Password cannot be empty Hint: use By cssSelector: Single Attribute
  • 30. Page 30Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByCss { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); driver.findElement(By.id("txtUsername")).sendKeys("admin"); driver.findElement(By.cssSelector("input[value='LOGIN']")).click(); String msg = driver.findElement(By.id("spanMessage")).getText(); System.out.println("Message is " +msg); driver.close(); } }
  • 31. Page 31Classification: Restricted Challenge 10: Validating message “Password can not be empty • Test Case steps 1. Launch Orange HRM 2. Type “admin” in the username text box 3. Click on Login button • Expected Result -- Application should display message as “Password cannot be empty Hint: use By cssSelector: Multiple Attributes
  • 32. Page 32Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class LocateByCss { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login") ; driver.findElement(By.id("txtUsername")).sendKeys("admin"); driver.findElement(By.cssSelector("input[class=‘button’’][value='LOGIN']")).click(); String msg = driver.findElement(By.id("spanMessage")).getText(); System.out.println("Message is " +msg); driver.close(); } }
  • 33. Page 33Classification: Restricted XPath • What is Xpath? • The XML path language , is a query language for selecting nodes from an XML document • Types of Xpath: 1. Absolute : Always starts with html 2. Relative : Always starts with // Syntax: //tagname[@attribute=‘value’]
  • 34. Page 34Classification: Restricted Challenge 11: Validating message “Welcome Admin” • Test case Steps: 1. Launch the application 2. Login to Orange HRM application • Expected Result: - Application should display message as “Welcome Admin” - Hint: use Absolute Xpath
  • 35. Page 35Classification: Restricted Solution: Validating Message: “Welcome Admin” By Xpath Absolute import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class AbsolutePath { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login") ;//absolute xpath driver.findElement(By.xpath("html/body/div/div/div/form/div[2]/input")).sendKeys( "admin"); driver.findElement(By.xpath("html/body/div/div/div/form/div[3]/input")).sendKeys( "seedadmin"); driver.findElement(By.xpath("html/body/div/div/div/form/div[5]/input")).click(); System.out.println(driver.findElement(By.xpath("html/body/div/div/a[2]")).getText( )); } }
  • 36. Page 36Classification: Restricted Challenge 12: Validating message “Welcome Admin” • Test case Steps: 1. Launch the application 2. Login to Orange HRM application • Expected Result: - Application should display message as “Welcome Admin” - Hint: use Relative Xpath
  • 37. Page 37Classification: Restricted Solution: Validating Message: “Welcome Admin” By Xpath Relative import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class RelativePath { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); /*driver.findElement(By.xpath(".//*[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath(".//*[@id='txtPassword']")).sendKeys("seedadmin"); driver.findElement(By.xpath(".//*[@id='btnLogin']")).click();*/ driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin") ; driver.findElement(By.xpath("//input[@id='btnLogin']")).click(); String msg = driver.findElement(By.xpath("//a[@id='welcome']")).getText(); //String msg = driver.findElement(By.xpath(".//*[@id='welcome']")).getText(); System.out.println("Message is:" +msg); } }
  • 38. Page 38Classification: Restricted Web Element Methods • isDisplayed() : is this element displayed or not? This method avoids the problem of having to parse an elements “style” attribute. • isEnabled() : is the element currently enabled or not? This will generally return true for everything but disabled input elements • isSelected(): determine whether or not this element is selected or not • All the above methods returns boolean
  • 39. Page 39Classification: Restricted Challenge 13: Add Employee with Create Login details • Test Case steps: 1. Launch the application 2. Login to Orange HRM application 3. Click on PIM  Add Employee 4. Select create login details option • Expected result: Create login details option should get selected
  • 40. Page 40Classification: Restricted import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class InteractWithChkBox { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin"); driver.findElement(By.xpath("//input[@id='btnLogin']")).click(); driver.findElement(By.linkText("PIM")).click(); driver.findElement(By.linkText("Add Employee")).click(); WebElement cb = driver.findElement(By.id("chkLogin")); //if there is a chkbox with this id and if its displayed and enabled but not selected then click if (cb.isDisplayed()){ if(cb.isEnabled()){ if(cb.isSelected()==false) { cb.click(); }} }driver.close();
  • 41. Page 41Classification: Restricted Challenge 14: Employee’s Gender • Test Case steps: 1. Launch the application 2. Login to Orange HRM application 3. Click on PIM  Add Employee 4. Click on any employee • Expected result: - Under personal details Gender should be present as Male and Female - Both options should be disabled before clicking on Edit button - Both options should become enabled after clicking on Edit button
  • 42. Page 42Classification: Restricted import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class InteractWithRadio { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin"); driver.findElement(By.xpath("//input[@id='btnLogin']")).click(); driver.findElement(By.linkText("PIM")).click(); driver.findElement(By.linkText("Employee List")).click(); driver.findElement(By.linkText("Charu Anil")).click(); //construct the absolute path from the code }
  • 43. Page 43Classification: Restricted List<WebElement> genderLabel = driver.findElements(By.xpath("//ul[@class='radio_list']/li/label")); for(WebElement we:genderLabel){ System.out.println(we.getText()); } List<WebElement> gender= driver.findElements(By.xpath("//ul[@class='radio_list']/li/input")); System.out.println("Status before clicking on Edit Button"); for(WebElement we:gender){ System.out.println(we.isEnabled()); } driver.findElement(By.id("btnSave")).click(); System.out.println("Status after clicking on Save Button"); for(WebElement we:gender) { System.out.println(we.isEnabled()); } driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.findElement(By.partialLinkText("Welcome")).click(); driver.findElement(By.linkText("Logout")).click(); driver.close(); }
  • 44. Page 44Classification: Restricted Challenge 15: Country List • Test Case steps 1. Launch the application 2. Login to orange HRM 3. Click on PIMEmployee list 4. Click on any Employee 5. Click on edit button 6. Select indian as a nationality • Expected Result - Default Selected option should be –Select— - The Nationality drop down should have 100 countries listed - India should get selected as a nationality
  • 45. Page 45Classification: Restricted Select Class • Models SELECT tag providing helper methods to select and deselect options • Parameterized Constructor • Methods: - getFirstSelectedOption() : returns first selected option in this Select tag - selectByIndex(): Select the option at given index - selectByValue(): Select all options that have a value matching the argument - selectByVisibleText(): Select all options that display test matching the argument - getOptions(): returns all options belonging to this select tag
  • 46. Page 46Classification: Restricted import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class InteractWithDropDown { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin"); driver.findElement(By.xpath("//input[@id='btnLogin']")).click(); driver.findElement(By.linkText("PIM")).click(); driver.findElement(By.linkText("Employee List")).click(); driver.findElement(By.linkText("Charu Anil")).click(); //click on the edit button first to activate it driver.findElement(By.id("btnSave")).click(); }
  • 47. Page 47Classification: Restricted WebElement cmbNation = driver.findElement(By.id("personal_cmbNation")); Select nationality = new Select(cmbNation); System.out.println("Default Selection:" + nationality.getFirstSelectedOption().getText()); //Get all count of nationality List<WebElement> nationalities = nationality.getOptions(); System.out.println("Total no: of Nationalities:" + nationalities.size()); //List all nationality int i = 1; for (WebElement we: nationalities) { System.out.println(i+"."+we.getText()); i++; }//Select India as Nationality by 3 methods //select byindex /*nationality.selectByIndex(82); System.out.println("New Selection Made by index method:"+nationality.getFirstSelectedOption().getText()); */ //select byvisible text /*nationality.selectByVisibleText("Indian"); System.out.println("New Selection Made by visible text method:"+nationality.getFirstSelectedOption().getText()); */ nationality.selectByValue("82"); System.out.println("New Selection Made by value method:" +nationality.getFirstSelectedOption().getText()); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.findElement(By.partialLinkText("Welcome")).click(); driver.findElement(By.linkText("Logout")).click(); driver.close(); }
  • 48. Page 48Classification: Restricted Challenge 16: Handling Table • Test Case Steps 1. Launch the application 2. Login to Orange HRM application 3. Click on PIM Employee list • Expected Result - In Employee table eight columns should be present - Last seven columns should be (Id, first Name , last name, job title, Employment status, Sub unit, supervisor - In employee table on single page maximum 10 records should be present
  • 49. Page 49Classification: Restricted import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class InteractWithTable { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.php/auth/login"); driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("admin"); driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("seedadmin"); driver.findElement(By.xpath("//input[@id='btnLogin']")).click(); driver.findElement(By.linkText("PIM")).click(); driver.findElement(By.linkText("Employee List")).click();
  • 50. Page 50Classification: Restricted //Check eight columns are present List<WebElement> tblcolumn = driver.findElements(By.xpath(".//*[@id='resultTable']/thead/tr/th")); System.out.println("Table size:" + tblcolumn.size()); //Check for last seven columns List<WebElement> lastseven = driver.findElements(By.xpath(".//*[@class='header']")); System.out.println("Total column" + lastseven.size()); //Table should have maximum number of 10 records List<WebElement> records = driver.findElements(By.xpath(".//*[@id='resultTable']/tbody/tr")); if (records.size() <10) { System.out.println("Total records within range"); }else { System.out.println("Total records are out of range"); } } }
  • 51. Page 51Classification: Restricted Challenge 17: Handling Screen Shots import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class GetScreenShot { //Taking a Pic of the webpage public static void main(String[] args) throws IOException { WebDriver driver = new FirefoxDriver(); driver.get("https://mail.rediff.com/cgi-bin/login.cgi"); TakesScreenshot ts = (TakesScreenshot)driver; File src = ts.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("E:venki- backupSeleniumSeed_SelExSeleniumExScreenShotsrediff.png")); System.out.println("Screen shot taken"); driver.close(); } }
  • 52. Page 52Classification: Restricted Challenge 18: Handling Java Script Alerts • To handle alert window in Selenium Web driver we have predefined Interface known as Alert . • 1- accept()- Will click on the ok button when an alert comes. • 2- dismiss()- Will click on cancel button when an alert comes Test Case Steps: Step 1-Open Firefox and open rediff mail website. Step 2- Enter username and Click on Go button. Step 3- Capture the Alert text. Step 4- Click on the OK button.
  • 53. Page 53Classification: Restricted public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("https://mail.rediff.com/cgi-bin/login.cgi"); driver.manage().window().maximize(); driver.findElement(By.id("login1")).sendKeys("admin"); driver.findElement(By.name("proceed")).click(); //Switch to alert window and capture the text and print String alertmsg = driver.switchTo().alert().getText(); System.out.println("Alert message displayed is" + alertmsg); //Click the ok button inside the alert box driver.switchTo().alert().accept(); //Click the cancel button inside the alert box //driver.switchTo().alert().dismiss(); driver.close(); }
  • 54. Page 54Classification: Restricted Challenge 19: Cookie Management • WebDriver options(): - addCookie() - deleteAllCookies() - deleteCookieNamed() - getCookieNamed() - getCookies() • Cookie Class: - getDomain() - getExpiry() - getName() - getPath() - getValue()
  • 55. Page 55Classification: Restricted import java.util.Set; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class GetCookie { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); String url =“ http://flipkart.com/”; driver.navigate().to(url); //Adding a new cookie Cookie name = new Cookie(“mycookie”, “123457”); driver.manage().addCookie(name); //Getting all the cookie Set<Cookie> cookiesList = driver.manage().getCookies(); for(Cookie getcookies : cookiesList) { System.out.println(getcookies); } //delete the added cookie System.out.println(“deleting cookie…”); driver.manage().deleteCookieNamed(“mycookie”); Set<cookie> newcookiesList = driver.manage().getCookies(); for(Cookie getcookies: newcookiesList) { System.out.println(getcookies); } driver.quit(); } }
  • 56. Page 56Classification: Restricted Launching in Different Browsers • In Internet Explorer • In Google Chrome
  • 57. Page 57Classification: Restricted Challenge 20: Launch IE import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class LaunchingIE { public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("webdriver.ie.driver","C:AdvancedSeleniumSo ftwaresIEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.p hp/auth/login"); } }
  • 58. Page 58Classification: Restricted Challenge 21: Launch Google Chrome import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class LaunchingChrome { public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("webdriver.chrome.driver","C:AdvancedSeleni umSoftwareschromedriver.exe"); WebDriver driver= new ChromeDriver(); driver.get("http://127.0.0.1:8080/orangehrm/symfony/web/index.p hp/auth/login"); } }
  • 59. Page 59Classification: Restricted Challenge 22: Create test case using Mozila firefox, IE, Chrome • Test case Steps 1. Launch the application “google” 2. Using 3 different browsers -- firefox – IE -- chrome 3. Get the page title from all the browsers.
  • 60. Page 60Classification: Restricted import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class LaunchBrowsers_for { public static WebDriver driver; public static int browser; public static String browsername; public static void main(String[] args) { for (browser=1; browser<=3; browser++) { if(browser == 1) { driver = new FirefoxDriver(); browsername = "Mozila Firefox Browser"; } else if (browser ==2) { System.setProperty("webdriver.ie.driver", "E:venki- backupSeleniumSoftwareIEDriverServer.exe"); driver = new InternetExplorerDriver(); browsername = "Internet Explorer Browser"; }
  • 61. Page 61Classification: Restricted else if(browser ==3) { System.setProperty("webdriver.chrome.driver", "E:venki- backupSeleniumSoftwarechromedriver.exe"); driver = new ChromeDriver(); browsername = "Chrome Browser"; } driver.get("https://www.google.com"); String pgtitle = driver.getTitle(); if(pgtitle.equals("Google")) { System.out.println(browsername + "_Google launch passed"); } else { System.out.println(browsername + "_Google launch failed"); } driver.close(); } } }
  • 62. Page 62Classification: Restricted TestNG Framework • TestNG is an advance framework designed in a way to leverage the benefits by both the developers and testers. • TestNG was created by an acclaimed programmer named as “Cedric Beust”. • TestNG with WebDriver gives efficient and effective test result format to generate test reports. • TestNG has an inbuilt exception handling mechanism which lets the program to run without terminating unexpectedly.
  • 63. Page 63Classification: Restricted Features of TestNG • Support for annotations • Support for Data Driven Testing using Dataproviders • Enables user to set execution priorities for the test methods • Supports threat safe environment when executing multiple threads • Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse). • Facilitates user with effective means of Report Generation using ReportNG
  • 64. Page 64Classification: Restricted Annotations • @Test: annotated method is part of test case • @BeforeTest: annotated method will run before any test method belonging to classes inside the tag is run • @AfterTest: annotated method will run after all the test methods belonging to classes inside the tag is run • @BeforeMethod: annotated method will run before each test method • @AfterMethod: annotated method will run after each test method • @BeforeSuite: annoatated method will run before all tests in this suite have run • @AfterSuite: annotated method will run after all tests in this suite have run
  • 65. Page 65Classification: Restricted Generating Report using TestNG • TestCase Steps: 1. Launch the applicaton http://newtours.demoaut.com 2. Goto home page verify its page title 3. Close the application
  • 66. Page 66Classification: Restricted Import org.testng.Assert; Import org.openqa.selenium.WebDriver; Import org.openqa.selenium.firefox.FirefoxDriver; Import org.testng.annotations.Test; Import org.testng.annotations.BeforeTest; Import org.testng.annotations.AfterTest; Public class TestNG1 { public String baseurl = http://newtours.demoaut.com; public WebDriver driver; @BeforeTest Public void setBaseurl( ) { driver = new FirefoxDriver(); driver.get(baseurl); } @Test Public void verifyTitle() { String expectedtitle = “Welcome Mercury Tours”; String actualtitle = driver.getTitle(); Assert.assertEquals(actualtitle , expectedtitle); } @AfterTest Public void endSession() { driver.close(); } }