3. Automated UI Testing with Selenium
Slobodan Lohja
Full stack developer focus on open
source technologies.
Working with Domino since version
4.5.
Fan of enterprise Java, XPages, Spring
and Hibernate.
I learned to enjoy enterprise java
development over the years.
5. • Manual Testers
• Test Engineers
• Managers
• Automation Engineer
Introduction – Who is it for?
Automated UI Testing with Selenium
6. • Tool that covers multiple browsers across
platforms.
• Supports many Programming languages
• Can simulate a user case and validate
check points
• Open Source free of cost
Introduction – Why Selenium
Automated UI Testing with Selenium
7. Selenium IDE
• Record and Play
• Does not scale on large projects
• Only used with Firefox.
Selenium RC
• Supports multiple OS, browsers and languages
• Works on any browser that supports Javascript.
• JavaScript injection can be blocked in some
browsers
• Deprecated by Selenium Web Driver
Introduction – Selenium Components
Automated UI Testing with Selenium
8. Selenium WebDriver
• JavaScript injection removed.
• Supports multiple OS, browsers and languages
• No Server needed
• iOS and Android support
• Interacts with browser native code
Selenium Grid – Parallel/Sequential Execution
• Designed to distribute test cases to many
machines
Introduction – Selenium Components
Automated UI Testing with Selenium
9. Each browser manufacturer produces
a WebDriver
Introduction – WebDriver
WebDriver
Interface
(APIs)
Firefox
Driver
Safari
Driver
Chrome
Driver
Others
User
Code
Automated UI Testing with Selenium
11. • Java SE Development Kit (JDK)
• Eclipse IDE (Maven included)
• WebDrivers for each browser
• Selenium WebDriver Jar libraries
• “Try Xpath” Firefox Add On
Workstation Setup
Automated UI Testing with Selenium
12. • https://www.seleniumhq.org/download/
• Save Selenium Java JARS into c:libsselenium
• Save WebDrivers to a common directory
c:webdrivers
Workstation Setup - WebDriver Links
Automated UI Testing with Selenium
14. package com.xpagesbeast.test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestSuite {
public static void main(String[] args) {
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "/webdrivers/geckodriver.exe");
driver = new FirefoxDriver();
String baseURL = "http://www.google.com";
driver.get(baseURL);
}
}
Project Hands On – Simple proof of concept
Automated UI Testing with Selenium
15. Project Hands On – Simple proof of concept
Find html elements by these attributes:
• Id
• Name
• Class Name
• XPath
• Link Text
• Partial Link Text
• Tag Name
• CSS Selector
Automated UI Testing with Selenium
16. Project Hands On – Advanced CSS Selectors
Find html elements by these attributes:
• Tag[attribute=‘value’]
• .class1.class2.class3 append until we find
an element
Automated UI Testing with Selenium
17. Project Hands On – Advanced CSS Selectors
Find html elements by these wildcards:
“^” represents the starting text
“$” represents the ending text
“*” represents the text contained
Example:
Tag[attribute<wildcard>=‘value’]
Input[class^=‘requiredInput’]
Automated UI Testing with Selenium
18. Project Hands On – Advanced CSS Selectors
Find child html elements:
“>” children
Example:
tag>tag
fieldset>input
Fieldset>input#name
Automated UI Testing with Selenium
19. Project Hands On – XPath Selectors
Find child html elements:
• Sing ‘/’ look inside the parent (relative)
• Double ‘//’ look for any child or nested children element inside
the parent.
//tag[@attribute=‘value’
//tag[text()=‘value’] -> Find based on text in between tag.
Example:
.//*[#id=‘navbar’]
Tip: Once you find the element, replace ‘*’ with proper tag.
Automated UI Testing with Selenium
21. • Selenium WebDriver --‐> 3.0.1
• Gecko Driver --‐>0.11.1
• FF --‐> 49.0.2
• If you get errors, check your versions are
compatible.
Tips
Automated UI Testing with Selenium
Manual Testers = who want to switch to automated testing to become a test engineer
Test Engineers =
Managers = if you manage developers or quality assurance teams.
Career change, want to become a Automation Engineer.
Automate on Mac, Linux, and Windows
Automate in Java, Python, PHP, Ruby (flexibility) – designed for Java, and this demo is on Java
Selenium RC tries to overcome the limitations of Selenium IDE
It’s deprecated by Selenium Web Driver, Javascript injection is blocked in some browsers.
Automate in Java, Python, PHP, Ruby (flexibility) – designed for Java, and this demo is on Java
Future is Selenium Web Driver
Selenium RC tries to overcome the limitations of Selenium IDE
It’s deprecated by Selenium Web Driver, Javascript injection is blocked in some browsers.
Automate in Java, Python, PHP, Ruby (flexibility) – designed for Java, and this demo is on Java
Future is Selenium Web Driver
Java or Python code is written against the API and the driver uses the native browser code to test the UI.
Code written once against all browsers, they follow the API.