SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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)
 

Semelhante a 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
 

Semelhante a 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
 
Automated Testing ADF with Selenium
Automated Testing ADF with SeleniumAutomated Testing ADF with Selenium
Automated Testing ADF with Selenium
 
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 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
 

Último

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Último (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

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