Automated UI Testing with
Selenium WebDriver
Automated UI Testing with Selenium
CollabSphere 2018 Sponsors
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.
Agenda
• Introduction
• Workstation Setup
• Project hands on
• Tips
Automated UI Testing with Selenium
• Manual Testers
• Test Engineers
• Managers
• Automation Engineer
Introduction – Who is it for?
Automated UI Testing with Selenium
• 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
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
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
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
Agenda
• Introduction
• Workstation Setup
• Project hands on
• Tips
Automated UI Testing with Selenium
• 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
• 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
Agenda
• Introduction
• Workstation Setup
• Project hands on
• Tips
Automated UI Testing with Selenium
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
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
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
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
Project Hands On – Advanced CSS Selectors
Find child html elements:
“>” children
Example:
tag>tag
fieldset>input
Fieldset>input#name
Automated UI Testing with Selenium
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
Agenda
• Introduction
• Workstation Setup
• Project hands on
• Tips
Automated UI Testing with Selenium
• 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
• java.lang.IllegalStateException:
The path to the driver executable must be set by
the webdriver.gecko.driver system poperty;
Tips
Automated UI Testing with Selenium
System.setProperty("webdriver.gecko.driver",
"/webdrivers/geckodriver.exe");
Every Java program that starts launches its own
JVM instance (process). The System.Property is a
HashMap (key value pair). There is one for every
JVM Instance (one for every Java process).
Tips
Automated UI Testing with Selenium
Driver.findElement(By.tagName(“a”)).click();
Hardly used, finds first <a /> tag and clicks it in
the DOM.
Opposite with the By Id methods gives an error if
there is more than one found.
Tips
Automated UI Testing with Selenium
Slobodan Lohja
Blog: uxdesign.xpagesbeast.com
Email: slohja@hotmail.com
LinkedIn: linkedin.com/in/slobodanlohja/
Twitter: @xpagesbeast
Automated UI Testing with Selenium

Automated ui-testing

  • 1.
    Automated UI Testingwith Selenium WebDriver Automated UI Testing with Selenium
  • 2.
  • 3.
    Automated UI Testingwith 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.
  • 4.
    Agenda • Introduction • WorkstationSetup • Project hands on • Tips Automated UI Testing with Selenium
  • 5.
    • Manual Testers •Test Engineers • Managers • Automation Engineer Introduction – Who is it for? Automated UI Testing with Selenium
  • 6.
    • Tool thatcovers 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 • Recordand 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 • JavaScriptinjection 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 manufacturerproduces a WebDriver Introduction – WebDriver WebDriver Interface (APIs) Firefox Driver Safari Driver Chrome Driver Others User Code Automated UI Testing with Selenium
  • 10.
    Agenda • Introduction • WorkstationSetup • Project hands on • Tips Automated UI Testing with Selenium
  • 11.
    • Java SEDevelopment 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/ • SaveSelenium Java JARS into c:libsselenium • Save WebDrivers to a common directory c:webdrivers Workstation Setup - WebDriver Links Automated UI Testing with Selenium
  • 13.
    Agenda • Introduction • WorkstationSetup • Project hands on • Tips Automated UI Testing with Selenium
  • 14.
    package com.xpagesbeast.test; import org.openqa.selenium.WebDriver; importorg.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
  • 20.
    Agenda • Introduction • WorkstationSetup • Project hands on • Tips 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
  • 22.
    • java.lang.IllegalStateException: The pathto the driver executable must be set by the webdriver.gecko.driver system poperty; Tips Automated UI Testing with Selenium
  • 23.
    System.setProperty("webdriver.gecko.driver", "/webdrivers/geckodriver.exe"); Every Java programthat starts launches its own JVM instance (process). The System.Property is a HashMap (key value pair). There is one for every JVM Instance (one for every Java process). Tips Automated UI Testing with Selenium
  • 24.
    Driver.findElement(By.tagName(“a”)).click(); Hardly used, findsfirst <a /> tag and clicks it in the DOM. Opposite with the By Id methods gives an error if there is more than one found. Tips Automated UI Testing with Selenium
  • 25.
    Slobodan Lohja Blog: uxdesign.xpagesbeast.com Email:slohja@hotmail.com LinkedIn: linkedin.com/in/slobodanlohja/ Twitter: @xpagesbeast Automated UI Testing with Selenium

Editor's Notes

  • #6 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.
  • #7 Automate on Mac, Linux, and Windows Automate in Java, Python, PHP, Ruby (flexibility) – designed for Java, and this demo is on Java
  • #8 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
  • #9 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
  • #10 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.
  • #12 Maven is included in the latest Eclipse
  • #13 Maven is included in the latest Eclipse
  • #22 Maven is included in the latest Eclipse
  • #23 Maven is included in the latest Eclipse
  • #24 Maven is included in the latest Eclipse
  • #25 Maven is included in the latest Eclipse