SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Web UI Test Automation
by Artem Nagornyi

Drivers: Selenium WebDriver, Sikuli X
Frameworks: PageFactory, TestNG
Other tools: Apache Ant, Jenkins CI
What is Selenium WebDriver?
● Open-source, multi-platform, multi-browser
  tool for browser automation
● Collection of bindings for multiple languages
  (Java, C#, Python, Ruby, Perl, PHP)
● Can be used with different frameworks:
  JUnit, NUnit, TestNG, unittest, RSpec, Test::
  Unit, Bromine, Robot, and many others.
● Has the biggest and strongest community.
  De facto standard in the world of Web UI test
  automation
Locators
Selenium WebDriver finds elements in browser via DOM
using these locators:
● webdriver.findElement(By.id("logo"))
● webdriver.findElement(By.name("q"))
● webdriver.findElement(By.tagName("H1"))
● webdriver.findElements( By.className
   ("sponsor_logos"))
● webdriver.findElement( By.cssSelector("section.
   roundbutton div#someid"))
● webdriver.findElement( By.xpath("//section
   [@id='miniconfs']/a[2]"))
● webdriver.findElements(By.linkText("about"))
● webdriver.findElement(By.partialLinkText("canberra"))
Interactions With Page
Selenium WebDriver simulates all user
interactions with browser:
● webElement.click()
● webElement.sendKeys("type some text")
● webElement.submit()
Actions class -> Mouse events, Drag and Drop
   Actions builder = new Actions(driver);
   Action dragAndDrop = builder.clickAndHold(someElement)
         .moveToElement(otherElement)
         .release(otherElement)
         .build();
   dragAndDrop.perform();
There are many ways ...
To simulate right-click:
new Actions(driver).contextClick(element).perform();


Or you can use WebDriverBackedSelenium:
Selenium selenium = new WebDriverBackedSelenium(webDriver,
"http://sample.com")
selenium.fireEvent("//tr[@id[contains(.,'Equipment')]]",
"blur");


To generate virtually any JS event use JavaScriptExecutor:
((JavascriptExecutor)driver).executeScript("document.
getElementById('element ID').blur()")
AJAX applications
When elements are loaded asynchronously,
Selenium can wait either unconditionally:
  webdriver().manage().timeouts()
     .implicitlyWait(30, TimeUnit.SECONDS)


or conditionally:
  Boolean expectedTextAppeared =
  (new WebDriverWait(driver, 30))
  .until(ExpectedConditions.
  textToBePresentInElement(By.cssSelector
  ("div#projects div.value"), "expected
  value"));
Testing Styles and Executing JS
Testing CSS properties:
● webElement.getCssValue("height")
● webElement.getCssValue("background-image")

JavaScript execution:
  JavascriptExecutor js = (JavascriptExecutor)
  driver;
  js.executeScript("your_js_function();");
Frames and Alerts
TargetLocator target = webDriver.switchTo();

//Switching to a frame identified by its name
target.frame("name");
//Switching back to main content
target.defaultContent();

//Switching to alert
Alert alert = target.alert();
//Working with alert
alert.getText();
alert.accept();
alert.dismiss();
alert.sendKeys("text");
Browser Navigation
Navigation nav = webDriver.navigate();

//Emulating browser Back button
nav.back();

//Forward button
nav.forward();

//Open URL
nav.to("http://www.sut.com");
Migration from Selenium I (RC)
Selenium selenium =
new WebDriverBackedSelenium(webDriver, "http:
//sample.com")

selenium.open("http://sample.com/home");
selenium.click("id=follow_twitter");
selenium.waitForPageToLoad("10000");

WebDriver webDriver = ((WebDriverBackedSelenium)
selenium)
   .getUnderlyingWebDriver();
PageFactory and Page Objects
●   Each page is encapsulated in its own Page class where methods represent
    page-specific actions and instance variables represent elements bound to
    locators via annotations
●   Behavior that is not page-specific is encapsulated in a Site class, and all
    Page classes are derived from Site class

    public class GoogleSearchPage extends GoogleSite {
        @FindBy(id = "q")
        private WebElement searchBox;
        public GoogleResultsPage searchFor(String text) {
            searchBox.sendKeys(text);
            searchBox.submit();
            return PageFactory.initElements(driver,
    GoogleResultsPage.class);
        }
    }
Working with Regular Expressions
@FindBy(css = "a.mylink")
private WebElement mylink;
//This checks that the text of a link equals to "Yahoo"
assertEquals(mylink.getText(), "Yahoo");
//This checks that the text of a link contains "ho" substring
assertTrue(checkRegexp("ho", mylink.getText()));


       ===================Helpers.java===================
public static boolean checkRegexp(String regexp, String text)
{
    Pattern p = Pattern.compile(regexp);
    Matcher m = p.matcher(text);
    return m.find();
}
Asynchronous Text Lookup
webdriver().manage().timeouts()
    .implicitlyWait(30, TimeUnit.SECONDS)
isTextPresent("sometext"); isTextNotPresent("othertext");


       ===================Helpers.java===================
public static void isTextPresent(String text) {
    wd.findElement(By.xpath("//*[contains(.,""+text+"")]")); }
public static void isTextNotPresent(String text) {
    boolean found = true;
    try {
    wd.findElement(By.xpath("//*[contains(.,""+text+"")]"));
    } catch(Exception e) {
    found = false;
    } finally { assertFalse(found); } }
Working with Tables
@FindBy(css = "table#booktable")
private WebElement table;
//getting the handler to the rows of the table
List<WebElement> rows = table.findElements(By.tagName("tr"));
System.out.println("Table rows count: " + rows.size());
//print the value of each cell using the rows handler
int rown; int celln; rown = 0;
for(WebElement row: rows) {
rown ++;
List<WebElement> cells = row.findElements(By.tagName("td"));
celln = 0;
for(WebElement cell: cells) {
    celln ++;
    System.out.println("Row number: " + rown + ". Cell number: "
    + celln + ". Value: " + cell.getText());
} }
What is Sikuli X?
● Open-source, multi-platform visual
  technology to automate graphical user
  interfaces using images of objects on the
  screen.
● Tests are developed in Jython or Java.
● Images of objects are captured in Sikuli IDE.
● You can import and use Java classes to
  extend your framework.
Sikuli Java API Wrappers
//Wait for element on the screen
public static void elementWait (String elementImagePath, int
timeOut) throws Exception {
    regionImagePath = image_folder + elementImagePath;
    screen.exists(elementImagePath, timeOut);
}

//Click element on the screen
public static void elementWaitAndClick (String elementImagePath)
throws Exception {
    regionImagePath = image_folder + elementImagePath;
    screen.click(elementImagePath, 0);
}
Why Sikuli?
1. Automation of non-standard interfaces,
   where more native UI automation is
   impossible or will require much larger efforts.
2. Image comparison testing.
3. As a helper tool in scope of a larger test
   automation framework.
What is TestNG?
TestNG is a testing framework inspired from JUnit and NUnit but
introducing some new functionalities that make it more powerful
and easier to use, such as:
 ● Annotations.
 ● Run your tests in arbitrarily big thread pools with various
    policies available (all methods in their own thread, one thread
    per test class, etc...).
 ● Flexible test configuration.
 ● Support for data-driven testing (with @DataProvider).
 ● Support for parameters.
 ● Powerful execution model (no more TestSuite).
 ● Supported by a variety of tools and plug-ins (Eclipse, IDEA,
    Maven, etc...).
TestNG Code Example
@Test(groups = {"regression", "inprogress"})
public void testSearch() { // test implementation }

@Parameters({"browser"})
@BeforeMethod(alwaysRun = true)
public void startDriver(){
driver = new FirefoxDriver(); }

@AfterClass(alwaysRun = true)
public void stopDriver() {
driver.close(); }
Apache Ant
Apache Ant is a Java build and configuration
tool that we use for:
1. Compilation of Selenium WebDriver test
   classes
2. Execution of tests
3. Passing parameters from command line to
   test automation framework (used for
   selective execution of test suite and test
   case)
Jenkins Continuous Integration
Server
Jenkins is a popular open-source continuous
integration server that we use for:
1. Scheduled execution or on-demand
   execution of Selenium WebDriver tests
2. Integration with source control repository
   (SVN, GIT)
3. Shared online dashboard with test results
4. Keeping history of test results
5. Email notifications about failed builds
Online Resources
● http://seleniumhq.org/docs/03_webdriver.html -
  Selenium WebDriver official page and tutorial
● http://selenium.googlecode.
  com/svn/trunk/docs/api/java/index.html - Selenium
  WebDriver API (Java bindings)
● http://code.google.com/p/selenium/wiki/PageFactory -
  PageFactory
● http://testng.org/doc/documentation-main.html - TestNG
  documentation
● http://sikuli.org/docx/ - Sikuli X Documentation
● http://ant.apache.org/manual/index.html - Apache Ant
  documentation
● https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
  - Jenkins Wiki
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

Web Test Automation with Selenium
Web Test Automation with SeleniumWeb Test Automation with Selenium
Web Test Automation with Seleniumvivek_prahlad
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Mehdi Khalili
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Yuriy Gerasimov
 
Automation framework using selenium webdriver with java
Automation framework using selenium webdriver with javaAutomation framework using selenium webdriver with java
Automation framework using selenium webdriver with javaNarayanan Palani
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011hugs
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorFlorian Fesseler
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 
Test Automation Using Python | Edureka
Test Automation Using Python | EdurekaTest Automation Using Python | Edureka
Test Automation Using Python | EdurekaEdureka!
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewDisha Srivastava
 
Python selenium
Python seleniumPython selenium
Python seleniumDucat
 

Was ist angesagt? (20)

Web Test Automation with Selenium
Web Test Automation with SeleniumWeb Test Automation with Selenium
Web Test Automation with Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)
 
Selenium
SeleniumSelenium
Selenium
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Selenium
SeleniumSelenium
Selenium
 
Selenium WebDriver FAQ's
Selenium WebDriver FAQ'sSelenium WebDriver FAQ's
Selenium WebDriver FAQ's
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
 
Automation framework using selenium webdriver with java
Automation framework using selenium webdriver with javaAutomation framework using selenium webdriver with java
Automation framework using selenium webdriver with java
 
Selenium
SeleniumSelenium
Selenium
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 
Test Automation Using Python | Edureka
Test Automation Using Python | EdurekaTest Automation Using Python | Edureka
Test Automation Using Python | Edureka
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiew
 
Selenium presentation
Selenium presentationSelenium presentation
Selenium presentation
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
 
Python selenium
Python seleniumPython selenium
Python selenium
 

Andere mochten auch

UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance CostsUI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs🐾 Jim Sibley 🐾
 
UI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UIUI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UIyaevents
 
Introduction to UI Automation Framework
Introduction to UI Automation FrameworkIntroduction to UI Automation Framework
Introduction to UI Automation FrameworkPriya Rajagopal
 
Effectively Using UI Automation
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI AutomationAlexander Repty
 
Challenges faced in UI automation
Challenges faced in UI automationChallenges faced in UI automation
Challenges faced in UI automationSrinivas Kantipudi
 
Coded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the FieldCoded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the FieldClemens Reijnen
 
UI Automation Quirks
UI Automation QuirksUI Automation Quirks
UI Automation QuirksLucas Pang
 
UI Test Automation Effectiveness
UI Test Automation EffectivenessUI Test Automation Effectiveness
UI Test Automation EffectivenessSQALab
 
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)Gáspár Nagy
 

Andere mochten auch (9)

UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance CostsUI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
 
UI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UIUI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UI
 
Introduction to UI Automation Framework
Introduction to UI Automation FrameworkIntroduction to UI Automation Framework
Introduction to UI Automation Framework
 
Effectively Using UI Automation
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI Automation
 
Challenges faced in UI automation
Challenges faced in UI automationChallenges faced in UI automation
Challenges faced in UI automation
 
Coded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the FieldCoded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the Field
 
UI Automation Quirks
UI Automation QuirksUI Automation Quirks
UI Automation Quirks
 
UI Test Automation Effectiveness
UI Test Automation EffectivenessUI Test Automation Effectiveness
UI Test Automation Effectiveness
 
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
 

Ähnlich wie Web UI test automation instruments

Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with exampleshadabgilani
 
Component Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumComponent Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumRichard Olrichs
 
Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Abhijeet Vaikar
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance testBryan Liu
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answerskavinilavuG
 
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
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideMek Srunyu Stittri
 
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
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developersAnton Udovychenko
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Roberto Franchini
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest servicesIoan Eugen Stan
 
What is the taste of the Selenide
What is the taste of the SelenideWhat is the taste of the Selenide
What is the taste of the SelenideRoman Marinsky
 

Ähnlich wie Web UI test automation instruments (20)

Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Component Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumComponent Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with Selenium
 
Automated Testing ADF with Selenium
Automated Testing ADF with SeleniumAutomated Testing ADF with Selenium
Automated Testing ADF with Selenium
 
Automated testing by Richard Olrichs and Wilfred vd Deijl
Automated testing by Richard Olrichs and Wilfred vd DeijlAutomated testing by Richard Olrichs and Wilfred vd Deijl
Automated testing by Richard Olrichs and Wilfred vd Deijl
 
Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...
 
Gwt.create
Gwt.createGwt.create
Gwt.create
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
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
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
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
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developers
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
What is the taste of the Selenide
What is the taste of the SelenideWhat is the taste of the Selenide
What is the taste of the Selenide
 

Kürzlich hochgeladen

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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
[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
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Kürzlich hochgeladen (20)

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
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Web UI test automation instruments

  • 1. Web UI Test Automation by Artem Nagornyi Drivers: Selenium WebDriver, Sikuli X Frameworks: PageFactory, TestNG Other tools: Apache Ant, Jenkins CI
  • 2. What is Selenium WebDriver? ● Open-source, multi-platform, multi-browser tool for browser automation ● Collection of bindings for multiple languages (Java, C#, Python, Ruby, Perl, PHP) ● Can be used with different frameworks: JUnit, NUnit, TestNG, unittest, RSpec, Test:: Unit, Bromine, Robot, and many others. ● Has the biggest and strongest community. De facto standard in the world of Web UI test automation
  • 3. Locators Selenium WebDriver finds elements in browser via DOM using these locators: ● webdriver.findElement(By.id("logo")) ● webdriver.findElement(By.name("q")) ● webdriver.findElement(By.tagName("H1")) ● webdriver.findElements( By.className ("sponsor_logos")) ● webdriver.findElement( By.cssSelector("section. roundbutton div#someid")) ● webdriver.findElement( By.xpath("//section [@id='miniconfs']/a[2]")) ● webdriver.findElements(By.linkText("about")) ● webdriver.findElement(By.partialLinkText("canberra"))
  • 4. Interactions With Page Selenium WebDriver simulates all user interactions with browser: ● webElement.click() ● webElement.sendKeys("type some text") ● webElement.submit() Actions class -> Mouse events, Drag and Drop Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(someElement) .moveToElement(otherElement) .release(otherElement) .build(); dragAndDrop.perform();
  • 5. There are many ways ... To simulate right-click: new Actions(driver).contextClick(element).perform(); Or you can use WebDriverBackedSelenium: Selenium selenium = new WebDriverBackedSelenium(webDriver, "http://sample.com") selenium.fireEvent("//tr[@id[contains(.,'Equipment')]]", "blur"); To generate virtually any JS event use JavaScriptExecutor: ((JavascriptExecutor)driver).executeScript("document. getElementById('element ID').blur()")
  • 6. AJAX applications When elements are loaded asynchronously, Selenium can wait either unconditionally: webdriver().manage().timeouts() .implicitlyWait(30, TimeUnit.SECONDS) or conditionally: Boolean expectedTextAppeared = (new WebDriverWait(driver, 30)) .until(ExpectedConditions. textToBePresentInElement(By.cssSelector ("div#projects div.value"), "expected value"));
  • 7. Testing Styles and Executing JS Testing CSS properties: ● webElement.getCssValue("height") ● webElement.getCssValue("background-image") JavaScript execution: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("your_js_function();");
  • 8. Frames and Alerts TargetLocator target = webDriver.switchTo(); //Switching to a frame identified by its name target.frame("name"); //Switching back to main content target.defaultContent(); //Switching to alert Alert alert = target.alert(); //Working with alert alert.getText(); alert.accept(); alert.dismiss(); alert.sendKeys("text");
  • 9. Browser Navigation Navigation nav = webDriver.navigate(); //Emulating browser Back button nav.back(); //Forward button nav.forward(); //Open URL nav.to("http://www.sut.com");
  • 10. Migration from Selenium I (RC) Selenium selenium = new WebDriverBackedSelenium(webDriver, "http: //sample.com") selenium.open("http://sample.com/home"); selenium.click("id=follow_twitter"); selenium.waitForPageToLoad("10000"); WebDriver webDriver = ((WebDriverBackedSelenium) selenium) .getUnderlyingWebDriver();
  • 11. PageFactory and Page Objects ● Each page is encapsulated in its own Page class where methods represent page-specific actions and instance variables represent elements bound to locators via annotations ● Behavior that is not page-specific is encapsulated in a Site class, and all Page classes are derived from Site class public class GoogleSearchPage extends GoogleSite { @FindBy(id = "q") private WebElement searchBox; public GoogleResultsPage searchFor(String text) { searchBox.sendKeys(text); searchBox.submit(); return PageFactory.initElements(driver, GoogleResultsPage.class); } }
  • 12. Working with Regular Expressions @FindBy(css = "a.mylink") private WebElement mylink; //This checks that the text of a link equals to "Yahoo" assertEquals(mylink.getText(), "Yahoo"); //This checks that the text of a link contains "ho" substring assertTrue(checkRegexp("ho", mylink.getText())); ===================Helpers.java=================== public static boolean checkRegexp(String regexp, String text) { Pattern p = Pattern.compile(regexp); Matcher m = p.matcher(text); return m.find(); }
  • 13. Asynchronous Text Lookup webdriver().manage().timeouts() .implicitlyWait(30, TimeUnit.SECONDS) isTextPresent("sometext"); isTextNotPresent("othertext"); ===================Helpers.java=================== public static void isTextPresent(String text) { wd.findElement(By.xpath("//*[contains(.,""+text+"")]")); } public static void isTextNotPresent(String text) { boolean found = true; try { wd.findElement(By.xpath("//*[contains(.,""+text+"")]")); } catch(Exception e) { found = false; } finally { assertFalse(found); } }
  • 14. Working with Tables @FindBy(css = "table#booktable") private WebElement table; //getting the handler to the rows of the table List<WebElement> rows = table.findElements(By.tagName("tr")); System.out.println("Table rows count: " + rows.size()); //print the value of each cell using the rows handler int rown; int celln; rown = 0; for(WebElement row: rows) { rown ++; List<WebElement> cells = row.findElements(By.tagName("td")); celln = 0; for(WebElement cell: cells) { celln ++; System.out.println("Row number: " + rown + ". Cell number: " + celln + ". Value: " + cell.getText()); } }
  • 15. What is Sikuli X? ● Open-source, multi-platform visual technology to automate graphical user interfaces using images of objects on the screen. ● Tests are developed in Jython or Java. ● Images of objects are captured in Sikuli IDE. ● You can import and use Java classes to extend your framework.
  • 16. Sikuli Java API Wrappers //Wait for element on the screen public static void elementWait (String elementImagePath, int timeOut) throws Exception { regionImagePath = image_folder + elementImagePath; screen.exists(elementImagePath, timeOut); } //Click element on the screen public static void elementWaitAndClick (String elementImagePath) throws Exception { regionImagePath = image_folder + elementImagePath; screen.click(elementImagePath, 0); }
  • 17. Why Sikuli? 1. Automation of non-standard interfaces, where more native UI automation is impossible or will require much larger efforts. 2. Image comparison testing. 3. As a helper tool in scope of a larger test automation framework.
  • 18. What is TestNG? TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as: ● Annotations. ● Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc...). ● Flexible test configuration. ● Support for data-driven testing (with @DataProvider). ● Support for parameters. ● Powerful execution model (no more TestSuite). ● Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).
  • 19. TestNG Code Example @Test(groups = {"regression", "inprogress"}) public void testSearch() { // test implementation } @Parameters({"browser"}) @BeforeMethod(alwaysRun = true) public void startDriver(){ driver = new FirefoxDriver(); } @AfterClass(alwaysRun = true) public void stopDriver() { driver.close(); }
  • 20. Apache Ant Apache Ant is a Java build and configuration tool that we use for: 1. Compilation of Selenium WebDriver test classes 2. Execution of tests 3. Passing parameters from command line to test automation framework (used for selective execution of test suite and test case)
  • 21. Jenkins Continuous Integration Server Jenkins is a popular open-source continuous integration server that we use for: 1. Scheduled execution or on-demand execution of Selenium WebDriver tests 2. Integration with source control repository (SVN, GIT) 3. Shared online dashboard with test results 4. Keeping history of test results 5. Email notifications about failed builds
  • 22. Online Resources ● http://seleniumhq.org/docs/03_webdriver.html - Selenium WebDriver official page and tutorial ● http://selenium.googlecode. com/svn/trunk/docs/api/java/index.html - Selenium WebDriver API (Java bindings) ● http://code.google.com/p/selenium/wiki/PageFactory - PageFactory ● http://testng.org/doc/documentation-main.html - TestNG documentation ● http://sikuli.org/docx/ - Sikuli X Documentation ● http://ant.apache.org/manual/index.html - Apache Ant documentation ● https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins - Jenkins Wiki