Program 1: Installation of selenium: Setting up selenium RC.and Selenium Web Driver.
Installation of Selenium: Setting Up Selenium RC and Selenium WebDriver
Selenium is a widely used tool for web automation testing. It has evolved over time, and currently, Selenium
WebDriver is the most commonly used version, replacing Selenium RC.
1. Selenium RC (Remote Control) [Deprecated]
Selenium RC is outdated and no longer recommended. It required a separate Selenium server to be installed
and had many limitations, so Selenium WebDriver replaced it. However, if you need to work with Selenium RC
for legacy systems, follow these steps:
Steps to Install Selenium RC
1. Download Selenium Server
o Download selenium-server-standalone.jar from the Selenium official website.
2. Run Selenium Server
o Open the command prompt and navigate to the folder where the .jar file is saved.
o Run the following command:
o java -jar selenium-server-standalone.jar
o This will start the Selenium RC server.
3. Write and Execute Test Scripts
o Selenium RC scripts were written using languages like Java, Python, and Ruby.
o Example in Java (Not recommended for new projects):
o Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://example.com");
o selenium.start();
o selenium.open("/");
o selenium.click("id=submit");
o selenium.stop();
⚠ Note: Selenium RC is deprecated, and you should use Selenium WebDriver instead.
2. Installing Selenium WebDriver (Recommended)
Selenium WebDriver is the modern way to automate browsers. It directly communicates with browsers without
needing a separate server.
Step 1: Install Python (For Python Users)
Download and install Python from python.org.
Verify installation by running:
python --version
Step 2: Install Selenium WebDriver
Install Selenium using pip:
pip install selenium
Step 3: Download WebDriver for Your Browser
Each browser requires a specific driver:
Browser Driver
Chrome ChromeDriver
Firefox GeckoDriver
Edge EdgeDriver
Place the driver in a known directory (e.g., C:\drivers\ or /usr/local/bin/).
Set up the path (optional for some OS).
Step 4: Write a Selenium WebDriver Script
🔹 Example: Open a website using Selenium in Python
from selenium import webdriver
# Set up the WebDriver (Example: Chrome)
driver = webdriver.Chrome()
# Open a website
driver.get("https://www.google.com")
# Close the browser
driver.quit()
Selenium WebDriver Setup in Other Languages
Java Setup
1. Install Java and set JAVA_HOME.
2. Install Selenium WebDriver:
o Download the Selenium Java Client Library from here.
o Add .jar files to your project.
3. Use the following Java code:
4. import org.openqa.selenium.WebDriver;
5. import org.openqa.selenium.chrome.ChromeDriver;
6.
7. public class SeleniumTest {
8. public static void main(String[] args) {
9. System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
10. WebDriver driver = new ChromeDriver();
11. driver.get("https://www.google.com");
12. driver.quit();
13. }
14. }
Conclusion
Use Selenium WebDriver instead of Selenium RC.
Install Selenium using pip (Python) or download the necessary libraries for Java.
Download and set up the correct WebDriver for your browser.
Write a simple automation script to test the installation.
Program 2: Automation Modes in Katalon Studio: Katalon Studio record mode,Katalon
Studio manual mode, Katalon Studio keywords and Katalon Studio script mode.
Katalon Studio provides different automation modes to suit various testing needs and skill levels. Here’s an
overview of the four main automation modes:
1. Katalon Studio Record Mode
o This mode allows users to record test actions as they interact with an application.
o The recorded steps are automatically converted into test cases.
o Best for beginners and those who want to create test cases quickly.
o Supports both Web UI and Mobile testing.
2. Katalon Studio Manual Mode
o In this mode, users can manually create test cases by selecting built-in keywords from a list.
o No need to write code; users can drag and drop keywords to build test scripts.
o Useful for testers with little to no programming knowledge.
3. Katalon Studio Keywords
o Katalon provides built-in and custom keywords for common testing actions (e.g., clicking a
button, entering text).
o Testers can create their own custom keywords for reusable test actions.
o Helps in making tests more modular and maintainable.
4. Katalon Studio Script Mode
o Allows testers to write Groovy-based test scripts for more advanced automation.
o Provides flexibility to customize test logic, handle complex scenarios, and integrate with
external systems.
o Best suited for testers with programming knowledge.
Program 3: Exploring Katalon Recorder Tool : Recorder for Chrome browser, Firefox,
Explorer, Play test cases in recorder
Title: Exploring Katalon Recorder Tool
Objective:
To understand the functionality of Katalon Recorder.
To learn how to record and play test cases in Katalon Recorder.
To explore test automation in different browsers like Chrome, Firefox, and Internet Explorer.
Software Requirements:
Google Chrome / Mozilla Firefox / Internet Explorer
Katalon Recorder (Chrome or Firefox extension)
Sample test website (e.g., https://www.demoqa.com, https://the-internet.herokuapp.com/)
Pre-requisites:
Basic understanding of web applications.
Knowledge of browser extensions.
Experiment Steps
Step 1: Install Katalon Recorder
1. Open Google Chrome or Mozilla Firefox.
2. Navigate to the Chrome Web Store or Firefox Add-ons.
3. Search for Katalon Recorder.
4. Click Add to Chrome (or Add to Firefox) and confirm the installation.
5. Once installed, open the extension by clicking the Katalon Recorder icon in the browser toolbar.
Step 2: Record a Test Case
1. Open Katalon Recorder.
2. Click on Create a new test case, give it a name, and click OK.
3. Click the Record button.
4. Perform actions on the test website (e.g., open a page, enter text in a form, click a button).
5. Click Stop Recording after completing the steps.
6. Review the recorded steps in the test case.
Step 3: Play the Test Case
1. Select the recorded test case from the list.
2. Click the Run button to execute the recorded steps.
3. Observe the browser actions as per the recorded sequence.
4. Check for errors in the Log section.
Step 4: Export the Test Case
1. Click on the Export option.
2. Choose a suitable format (e.g., Selenium WebDriver, Python, Java, C#).
3. Save the exported script.
Step 5: Execute in Different Browsers
1. Open the browser where Katalon Recorder is installed.
2. Load the saved test case.
3. Run the test case in different browsers (Chrome, Firefox, Internet Explorer).
Observations:
Record the test case steps executed.
Capture any errors encountered.
Note the browser compatibility for recorded test cases.
Conclusion:
Successfully recorded and executed test cases using Katalon Recorder.
Automated web testing without writing complex scripts.
Verified compatibility of test cases across different browsers.
Program 4: Exploring Web Spy and Web Object Repository: web spy & object
repository, spy on a web object in a browser, Object locator and strategies
Exploring Web Spy and Web Object Repository
When working with automated web testing, tools like Web Spy and Web Object Repository help in identifying
and managing web elements. These concepts are commonly used in test automation frameworks like Selenium,
UFT (Unified Functional Testing), and TestComplete.
1. Web Spy & Object Repository
Web Spy:
Web Spy tools are used to inspect web elements within a browser.
They allow testers to view an element’s properties like ID, Name, Class, XPath, and CSS Selectors.
Examples of Web Spies:
o Selenium DevTools
o UFT (Micro Focus UFT One) Object Spy
o Katalon Spy Web Utility
o TestComplete Object Spy
Web Object Repository:
A centralized storage that maintains element locators.
Instead of hardcoding locators in scripts, the Object Repository allows for easy management and
updates.
Helps in reusability and maintainability of test scripts.
2. Spying on a Web Object in a Browser
To inspect and spy on a web object, follow these steps:
Using Browser Developer Tools (Manual Approach)
1. Open the webpage in a browser (Chrome, Firefox, Edge).
2. Right-click on the element and select Inspect.
3. View the HTML and identify properties like:
o id
o name
o class
o tag
o aria-label
o xpath
o css-selector
Using Web Spy Tools
1. Selenium WebDriver:
o Use browser DevTools (Ctrl + Shift + I or F12 in Chrome).
o Use findElement(By.ID("elementID")) in Selenium scripts.
2. UFT Object Spy:
o Open UFT and navigate to Object Spy.
o Click on "Spy" and hover over the web element to capture its properties.
3. TestComplete Object Spy:
o Open TestComplete and select the Object Spy tool.
o Capture elements and store them in the Object Repository.
3. Object Locators & Strategies
When automating web testing, locating elements accurately is crucial. Below are common locator strategies:
Locator Strategy Description Example
ID Finds elements by their unique ID. By.ID("username")
Name Finds elements by the name attribute. By.Name("email")
Class Name Finds elements by class name. By.ClassName("btn-primary")
Tag Name Finds elements by tag (e.g., <button>, <input>). By.TagName("input")
XPath Finds elements using XML path expressions. By.XPath("//input[@id='search']")
CSS Selector Finds elements using CSS rules. By.CssSelector("#login > input")
Link Text Finds elements by anchor text. By.LinkText("Click here")
Partial Link Text Finds elements using partial text in links. By.PartialLinkText("Sign Up")
Conclusion
Web Spy tools help inspect and identify web elements efficiently.
Object Repositories store element locators for better test script maintainability.
Using appropriate locator strategies improves test reliability and execution speed.
Program 5: Exploring the Predefined pre- Defined Web UI keyboards : browser
keywords, windows keywords , checkbox keywords , combo box, textbox , file upload,
screenshot , scroll down and scroll up button related , alert frames , mouse hover, drag
and drop and keystroke keywords.
Exploring the Predefined Web UI Keywords in Test Automation
Web UI testing tools like Selenium, Katalon Studio, and UFT provide predefined keywords to interact with
web elements efficiently. These keywords help automate browser actions, handle UI components, and simulate
user interactions.
1. Browser Keywords
These keywords control browser actions.
Keyword Description
Open Browser Opens a browser session (Chrome, Firefox, Edge, etc.).
Close Browser Closes the current browser session.
Navigate To URL Navigates to a specific webpage.
Refresh Refreshes the current page.
Maximize Window Maximizes the browser window.
Switch to Window Switches between browser tabs or windows.
🔹 Example (Selenium in Python)
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com") # Open URL
driver.maximize_window() # Maximize browser
driver.refresh() # Refresh page
driver.quit() # Close browser
2. Windows Keywords
Used for handling browser pop-ups and multiple windows.
Keyword Description
Switch Window Switch between multiple browser windows.
Close Window Close the current window.
Switch to Window Index Switch to a window by index.
Switch to Window Title Switch using the window title.
3. Checkbox Keywords
Used to interact with checkboxes.
Keyword Description
Select Checkbox Checks a checkbox.
Unselect Checkbox Unchecks a checkbox.
Verify Checkbox Selected Checks if a checkbox is selected.
🔹 Example (Selenium - Checkbox Interaction)
checkbox = driver.find_element(By.ID, "accept_terms")
checkbox.click() # Select checkbox
4. Combo Box (Dropdown) Keywords
Used to interact with dropdown elements.
Keyword Description
Select Option By Value Selects an option by its value.
Keyword Description
Select Option By Label Selects an option by visible text.
Select Option By Index Selects an option using an index.
🔹 Example (Selenium - Dropdown Interaction)
from selenium.webdriver.support.ui import Select
dropdown = Select(driver.find_element(By.ID, "dropdown"))
dropdown.select_by_visible_text("Option 1")
5. Textbox Keywords
Used for interacting with text input fields.
Keyword Description
Set Text Inputs text into a textbox.
Clear Text Clears text from a textbox.
Verify Text Present Checks if a text is present.
🔹 Example (Selenium - Textbox Interaction)
textbox = driver.find_element(By.NAME, "username")
textbox.send_keys("TestUser") # Enter text
textbox.clear() # Clear text
6. File Upload Keywords
Used to automate file upload dialogs.
Keyword Description
Upload File Uploads a file by providing the file path.
🔹 Example (Selenium - File Upload)
file_upload = driver.find_element(By.ID, "upload")
file_upload.send_keys("C:\\Users\\file.pdf")
7. Screenshot Keywords
Used to capture browser screenshots.
Keyword Description
Take Screenshot Captures a screenshot of the browser window.
🔹 Example (Selenium - Screenshot)
driver.save_screenshot("screenshot.png")
8. Scroll Up & Scroll Down Keywords
Used to scroll inside a web page.
Keyword Description
Scroll Down Scrolls down on a webpage.
Scroll Up Scrolls up on a webpage.
🔹 Example (Selenium - Scroll Down & Up)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Scroll Down
driver.execute_script("window.scrollTo(0, 0);") # Scroll Up
9. Alert & Frames Keywords
Used for handling pop-up alerts and iframes.
Keyword Description
Accept Alert Clicks OK on an alert.
Dismiss Alert Clicks Cancel on an alert.
Switch to Frame Switches to an iframe.
Exit Frame Returns to the main page.
🔹 Example (Selenium - Alert Handling)
alert = driver.switch_to.alert
alert.accept() # Accept alert
🔹 Example (Selenium - Switch to Frame)
frame = driver.find_element(By.TAG_NAME, "iframe")
driver.switch_to.frame(frame) # Switch to iframe
10. Mouse Hover Keywords
Used to simulate hovering over elements.
Keyword Description
Mouse Over Hovers over an element.
🔹 Example (Selenium - Mouse Hover)
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element(By.ID, "menu")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
11. Drag and Drop Keywords
Used for simulating drag-and-drop actions.
Keyword Description
Drag and Drop Moves an element from one place to another.
🔹 Example (Selenium - Drag and Drop)
source = driver.find_element(By.ID, "drag-source")
target = driver.find_element(By.ID, "drop-target")
actions = ActionChains(driver)
actions.drag_and_drop(source, target).perform()
12. Keystroke Keywords
Used to simulate keyboard actions.
Keyword Description
Press Key Presses a specific key (e.g., Enter, Tab).
Type Text Types text into a field.
🔹 Example (Selenium - Simulating Keystrokes)
from selenium.webdriver.common.keys import Keys
textbox = driver.find_element(By.NAME, "search")
textbox.send_keys("Selenium" + Keys.ENTER) # Press Enter
Conclusion
Predefined Web UI keywords simplify automation by handling elements like browsers, checkboxes,
dropdowns, alerts, and more. These keywords improve efficiency in tools like Selenium, Katalon Studio, and
UFT.
Program 6: Installation of selenium: Setting up selenium RC.and Selenium Web Driver.
Installation of Selenium: Setting Up Selenium RC and Selenium WebDriver
Selenium is a widely used tool for web automation testing. It has evolved over time, and currently, Selenium
WebDriver is the most commonly used version, replacing Selenium RC.
1. Selenium RC (Remote Control) [Deprecated]
Selenium RC is outdated and no longer recommended. It required a separate Selenium server to be installed
and had many limitations, so Selenium WebDriver replaced it. However, if you need to work with Selenium RC
for legacy systems, follow these steps:
Steps to Install Selenium RC
1. Download Selenium Server
o Download selenium-server-standalone.jar from the Selenium official website.
2. Run Selenium Server
o Open the command prompt and navigate to the folder where the .jar file is saved.
o Run the following command:
o java -jar selenium-server-standalone.jar
o This will start the Selenium RC server.
3. Write and Execute Test Scripts
o Selenium RC scripts were written using languages like Java, Python, and Ruby.
o Example in Java (Not recommended for new projects):
o Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://example.com");
o selenium.start();
o selenium.open("/");
o selenium.click("id=submit");
o selenium.stop();
⚠ Note: Selenium RC is deprecated, and you should use Selenium WebDriver instead.
2. Installing Selenium WebDriver (Recommended)
Selenium WebDriver is the modern way to automate browsers. It directly communicates with browsers without
needing a separate server.
Step 1: Install Python (For Python Users)
Download and install Python from python.org.
Verify installation by running:
python --version
Step 2: Install Selenium WebDriver
Install Selenium using pip:
pip install selenium
Step 3: Download WebDriver for Your Browser
Each browser requires a specific driver:
Browser Driver
Chrome ChromeDriver
Firefox GeckoDriver
Edge EdgeDriver
Place the driver in a known directory (e.g., C:\drivers\ or /usr/local/bin/).
Set up the path (optional for some OS).
Step 4: Write a Selenium WebDriver Script
🔹 Example: Open a website using Selenium in Python
from selenium import webdriver
# Set up the WebDriver (Example: Chrome)
driver = webdriver.Chrome()
# Open a website
driver.get("https://www.google.com")
# Close the browser
driver.quit()
Selenium WebDriver Setup in Other Languages
Java Setup
1. Install Java and set JAVA_HOME.
2. Install Selenium WebDriver:
o Download the Selenium Java Client Library from here.
o Add .jar files to your project.
3. Use the following Java code:
4. import org.openqa.selenium.WebDriver;
5. import org.openqa.selenium.chrome.ChromeDriver;
6.
7. public class SeleniumTest {
8. public static void main(String[] args) {
9. System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
10. WebDriver driver = new ChromeDriver();
11. driver.get("https://www.google.com");
12. driver.quit();
13. }
14. }
Conclusion
Use Selenium WebDriver instead of Selenium RC.
Install Selenium using pip (Python) or download the necessary libraries for Java.
Download and set up the correct WebDriver for your browser.
Write a simple automation script to test the installation.
Program 7: Designing Test Cases: Test case design and Conversion of Mapping and
Templates using selenium tool and Manual test cases mapping with Selenium test cases
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class aaa {
public static void main(String[] args) { WebDriver driver = new
ChromeDriver(); driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).click(); //just for the click function
driver.manage().window().maximize();
driver.findElement(By.id("user- name")).sendKeys("standard_user");
driver.findElement(By.id("password")).sendKeys("secret_sau ce1");
driver.findElement(By.className("submit-button")).click();
boolean flag = driver.findElement(By.xpath("//button[text()=\"Open Menu\"]")).isDisplayed();
if (flag == true)
{System.out.println("Successfully logged in! hurRAY ");}
/*driver.close(); // terminate test window only
driver.quit(); //to Terminate all windows and test window */ }
Program – 8 Using Selenium IDE
Develop a test suite containing minimum 4 test cases.
Test Suite: test suite is a collection of multiple test cases grouped together for execution. It
allows testers to run multiple tests sequentially or in parallel to validate different
functionalities of a web application.
How to Do:
Step 1: Install Selenium IDE
1. Open Google Chrome.
2. Go to the Chrome Web Store and search for Selenium IDE.
3. Click "Add to Chrome" and install the extension.
Step 2: Create a New Project
1. Open Selenium IDE from your Chrome extensions.
2. Click "Create a New Project" and give it a suitable name.
Step 3: Record a Test Case
1. Click on the red record button (top right corner).
2. A new Chrome tab will open – browse normally and perform actions.
3. Close the tab when done; Selenium IDE will automatically save the recorded steps.
Step 4: Create Four Test Cases
Perform any four different actions while recording, such as:
Login – Enter credentials and sign in.
Search – Use a search bar to find an item.
Add to Cart – Select a product and add it to the cart.
Logout – Sign out of the application
Step 5: Run the Test Suite
1. Click "Run All" in Selenium IDE to execute all test cases sequentially.
2. Verify that each step passes without errors.
Now we setup testing:
For simple setup follow these:
1.Navigate to https://mvnrepository.com/artifact/org.testng/testng/7.11.0
2.Copy the maven dependency
3.In eclipse, copy this under dependencies tag after selenium dependency inside pom.xml
4.Right click on the project --> Maven --> Update project --> Save
Same as how we did for adding selenium.
Below is the hard way ( Manual way )
Finally
Just a Side note: Always create a java class for each test case.
TEST CASE – Example ( Just to check )
package seleniumDay3;
import org.testing.annotations.Test;
public class testNGFramework {
@Test(priority=1)
void openBrowser(){
System.out.println("Open browser");
@Test(priority=2)
void login(){
System.out.println("Login");
@Test(priority=3)
void close(){
System.out.println("Close browser");
Program – 9 Test suite
Conduct a test suite for any two websites.
All the rest of the programs will be done in testing environment.
TEST CASE - 1
package seleniumDay3;
import org.testing.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class loginWithTestNG {
WebDriver driver;
@Test(priority=1)
void openBrowser(){
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com");
driver.manage().window().maximize();
}
@Test(priority=2)
void login(){
driver.findElement(By.id("user-name")).click();
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.name("login-button")).click();
boolean flag driver.findElement(By.xpath("//button[text()- \"Open
Menu\"]")).isDisplayed(); if(flag==true){
System.out.println("User is successfully logged in");
else{
System.out.println("User is not logged in successfully");
@Test(priority=3)
void close(){
driver.close();
}
TEST CASE - 2
package seleniumDay3;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LoginDemoBlaze {
WebDriver driver;
@BeforeTest
void openBrowser() {
driver = new ChromeDriver();
driver.get("https://www.demoblaze.com/");
driver.manage().window().maximize();
}
@Test(priority = 1)
void login() throws InterruptedException {
driver.findElement(By.id("login2")).click();
Thread.sleep(2000); // Wait for the login modal to appear
driver.findElement(By.id("loginusername")).sendKeys("testuser");
driver.findElement(By.id("loginpassword")).sendKeys("testpassword");
driver.findElement(By.xpath("//button[text()='Log in']")).click();
Thread.sleep(3000); // Wait for login to process
WebElement logoutButton = driver.findElement(By.id("logout2"));
if (logoutButton.isDisplayed()) {
System.out.println("User is successfully logged in");
} else {
System.out.println("User login failed");
@AfterTest
void closeBrowser() {
driver.quit();
Beforetest and Aftertest not actually needed, can be replaced to test(priority = some number)
Now you can run the test cases individually or select multiple test cases to run as a suite.
For that select the above two test cases, select TestNG and select convert to TestNG.
It creates a xml file for the suite automatically.
You can use test case-1 for another website and that would make another test suite for
program-9, the same can be done using program-8 using selenium ide, just add two proper
testcases for different websites and that would make a test suite but the difference will be that
it will be in selenium IDE.
Program -10 Test Scripts
Develop and test a program to login a specific web pade using selenium test
scripts
Use the test case-1 from previous prog to check for login or just use prog 7’s code. All do
same thing. Still the code is below.
package seleniumDay3;
import org.testing.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class loginWithTestNG {
WebDriver driver;
@Test(priority=1)
void openBrowser(){
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com");
driver.manage().window().maximize();
@Test(priority=2)
void login(){
driver.findElement(By.id("user-name")).click();
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.name("login-button")).click();
boolean flag driver.findElement(By.xpath("//button[text()- \"Open
Menu\"]")).isDisplayed(); if(flag==true){
System.out.println("User is successfully logged in");
}
else{
System.out.println("User is not logged in successfully");
@Test(priority=3)
void close(){
driver.close();
Program -11 Test Scripts
Develop and test a program to provide total number of objects present
available on the web page using selenium test scripts.
package seleniumDay3;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import java.util.List;
public class CountObjects {
WebDriver driver;
@Test(priority = 1)
void openBrowser() {
driver = new ChromeDriver();
driver.get("https://www.demoblaze.com/");
driver.manage().window().maximize();
}
@Test(priority = 2)
void countObjects() {
List<WebElement> elements = driver.findElements(By.xpath("//*"));
System.out.println("Total number of elements on the page: " + elements.size());
@Test(Priority = 3)
void closeBrowser() {
driver.quit();
Program -12 Practical exercise and wrap-up
Build test suite with suitable application and complete end to end
automation process, discussion on best practices and Q&A.
Just use the same program as prog 10
package seleniumDay3;
import org.testing.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class loginWithTestNG {
WebDriver driver;
@Test(priority=1)
void openBrowser(){
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com");
driver.manage().window().maximize();
@Test(priority=2)
void login(){
driver.findElement(By.id("user-name")).click();
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.name("login-button")).click();
boolean flag driver.findElement(By.xpath("//button[text()- \"Open
Menu\"]")).isDisplayed(); if(flag==true){
System.out.println("User is successfully logged in");
else{
System.out.println("User is not logged in successfully");
}
}
@Test(priority=3)
void close(){
driver.close();
If you want to add log out functionality, you can do so. Nearly all prog 9, 10, 11, 12 can be
done using simple open browser, login and close browser in saucedemo website or
demoblaze.