Session 1
Objectives
- Ice Breaker!
- Intro to Selenium
- Download Chrome Driver
- Build a Simple JUnit-Maven Project with Dependencies and Driver
- Organization and Explanation of Various Packages
- Creating test classes
- Setting Driver Properties and Launching Chrome Browser
- Elements, Chrome Developer Tool, DOM, Nodes, Tags, Attributes, and Types of Locators.
- Automate TestCase: Login to TechFios
- JUnit Report Explanation (pass/fail)
Intro to Selenium
intro_to_selenium.pptx |
Building a Maven Project
Prerequisite: a. Installed Java,
b. Installed JDK, JRE, followed by setting environment variables,
c. Installed Maven followed by setting environment variables.
Step 1: Create a Maven Project:
a. Click File > New > Project > Maven > Maven Project > Next
b. Select Project name and location: Check - Use default Workspace location
c. Select an Archetype: Default is Quickstart, click Next
d. Provide Group ID: com.techfios and Artifact ID: techfios-test
e. Click Finish
Step 2: Delete the Maven provided main and test packages,
Step 3: Search and add dependencies from google for : a. Selenium-java, b. Selenium-server, and c. JUnit
in the POM file,
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
Step 4: Create a folder called "driver". Download and save the chromedriver.exe file in that
folder. https://chromedriver.chromium.org/downloads
Step 5: Make sure JDK and Maven are configured appropriately with eclipse,
Step 6: Right Click on the project > Run As > Maven Build > Type "clean install" for the goals > Run,
Wait for console output "BUILD SUCCESS".
Step 7: Create a package called "test" inside the TEST folder: Right click on the test folder > New > Package
Class Notes
DOM: The inspect view of the page
Document Object Model
Elements: Are the objects on the front-end/UI (User Interface)
Nodes: Each strand of code in the DOM
Attributes: The values inside each node.
Document Object Model
Elements: Are the objects on the front-end/UI (User Interface)
Nodes: Each strand of code in the DOM
Attributes: The values inside each node.
Automation Example
Test Case
Scenario:Valid user should be able to login
Steps #StepsExpected ResultActual ResultStatus
1Open Chrome BrowserBrowser launched
2Go to TechFios Website
3Type username in the username field
4Type password in the password field
5Click on the submit button
6Dashboard page title should display
CODE
@Test
public void validUsersShouldBeAbleToLogIn() {
//Set Chrome as default browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
//Open Chrome Browserd
WebDriver driver = new ChromeDriver();
//Go to TechFios Website
driver.get("http://techfios.com/test/billing/?ng=admin/");
//Type username in the username field
driver.findElement(By.id("username")).sendKeys("[email protected]");
//Type password in the password field
driver.findElement(By.name("password")).sendKeys("abc123");
//Click on Sign In button
driver.findElement(By.name("login")).click();
}
@Test
public void invalidUsersShouldBeAbleToLogIn() {
//Set Chrome as default browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
//Open Chrome Browser
WebDriver driver = new ChromeDriver();
//Go to TechFios Website
driver.get("http://techfios.com/test/billing/?ng=admin/");
//Type username in the username field
driver.findElement(By.id("username")).sendKeys("[email protected]");
//Type password in the password field
driver.findElement(By.name("password")).sendKeys("abc123");
//Click on Sign In button
driver.findElement(By.name("login")).click();
}
Scenario:Valid user should be able to login
Steps #StepsExpected ResultActual ResultStatus
1Open Chrome BrowserBrowser launched
2Go to TechFios Website
3Type username in the username field
4Type password in the password field
5Click on the submit button
6Dashboard page title should display
CODE
@Test
public void validUsersShouldBeAbleToLogIn() {
//Set Chrome as default browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
//Open Chrome Browserd
WebDriver driver = new ChromeDriver();
//Go to TechFios Website
driver.get("http://techfios.com/test/billing/?ng=admin/");
//Type username in the username field
driver.findElement(By.id("username")).sendKeys("[email protected]");
//Type password in the password field
driver.findElement(By.name("password")).sendKeys("abc123");
//Click on Sign In button
driver.findElement(By.name("login")).click();
}
@Test
public void invalidUsersShouldBeAbleToLogIn() {
//Set Chrome as default browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
//Open Chrome Browser
WebDriver driver = new ChromeDriver();
//Go to TechFios Website
driver.get("http://techfios.com/test/billing/?ng=admin/");
//Type username in the username field
driver.findElement(By.id("username")).sendKeys("[email protected]");
//Type password in the password field
driver.findElement(By.name("password")).sendKeys("abc123");
//Click on Sign In button
driver.findElement(By.name("login")).click();
}
Homework 1
Automate Test Case: Valid users should be able to login to Mercury Tour Site
Steps:
1. Go to http://newtours.demoaut.com/mercurywelcome.php
2. Verify title match: Welcome: Mercury Tours
2. Enter username: mercury
3. Enter password: mercury
4. Click sign-in (Hint: Incorporate implicit wait or Thread.sleep)
5. Verify SIGN-OFF button displayed
Interview Questions
1. What is Selenium?
2. What is QTP/UFT?
3. What is an element?
4. What does DOM stand for?
5. Give examples of element locators?
6. What is the code to create a Chrome Driver object?
7. What Selenium method is used to open a specific website?
8. What Selenium method is used to type something in a text box?
9. What Selenium method is used to click a button?
10. What JUnit annotation is used to run a test?
2. What is QTP/UFT?
3. What is an element?
4. What does DOM stand for?
5. Give examples of element locators?
6. What is the code to create a Chrome Driver object?
7. What Selenium method is used to open a specific website?
8. What Selenium method is used to type something in a text box?
9. What Selenium method is used to click a button?
10. What JUnit annotation is used to run a test?
Shortcuts/Tricks:
“Ctrl + Shift + F + O” - Align and remove unused imports.
“Ctrl + Alt + Down" - Duplicate the row where is the cursor is.
"Alt + Left" - Navigate back.
"Alt + Right" - Navigate forward.
“Ctrl + Alt + Down" - Duplicate the row where is the cursor is.
"Alt + Left" - Navigate back.
"Alt + Right" - Navigate forward.