Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web application testing with Selenium - Ірина Г...

Web application testing with Selenium - Ірина Гаврилюк

GDG Ternopil

November 23, 2016
Tweet

More Decks by GDG Ternopil

Other Decks in Programming

Transcript

  1. HELLO! My name is Iryna Havryliuk. I am QA engineer.

    You can find me at https://ua.linkedin.com/in/iryn a-havryliuk-692917a0 [email protected] 2
  2. WHAT IS SELENIUM ? Selenium is a suite of tools

    to automate web browsers across many platforms. Selenium… ▸ runs in many browsers and operating systems; ▸ can be controlled by many programming languages and testing frameworks. 3
  3. Selenium Components ▸ Selenium IDE ▸ Selenium RC (Remote Control)

    ▸ Selenium Web Driver ▸ Selenium Grid 4
  4. 1. Selenium IDE Firefox add-on that will do simple record-and-playback

    of interactions with the browser. 5 C#, Java, Ruby, Python etc.
  5. 6

  6. 7 A command tells Selenium what to do. Selenium commands

    come in three “flavors”: Actions, Accessors, and Assertions. All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and ” waitFor”. Locators: • id=id • name=name • xpath=xpathExpression • css=cssSelectorSyntax • link=textPattern Selenium Commands – “Selenese”
  7. 8 Benefits • Easy to install and use. • No

    prior experience of programming required. • Tests can be exported in usable formats for selenium WebDriver and RC. • Has in-built help and module for reporting test results.
  8. 2. Selenium RC Selenium RC is a test tool that

    allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. 9
  9. ▸ A server which automatically launches and kills browsers, and

    acts as a HTTP proxy for web requests from them. Selenium RC comes in two parts. ▸ Client libraries for your favorite computer language. 10
  10. Benefits 11 • It has simple and complete API •

    It can easily be used in cross-platform and cross-browser environment. • It can perform conditional operations and looping. • It supports data driven testing • New browsers can easily be supported • Its execution is faster than IDE.
  11. 3. Selenium WebDriver If you want to: ❏ create robust,

    browser-based regression automation suites and tests ❏ scale and distribute scripts across many environments 12
  12. 13

  13. Example 1. Create Webdriver: WebDriver driver = new ChromeDriver(); 2.

    Open test App driver.get("http://mycompany.site.com"); 3. Interaction with element WebElement element = driver.findElement(By.id("#element_id"))); element.click(); 4. Assertion assertEquals("Webpage expected title", driver.getTitle()); 5. Close Webdriver driver.quit(); 16
  14. Example of Complex interaction @Test public void testDoubleClick() throws Exception

    { WebDriver driver = new ChromeDriver(); driver.get("http://dl.dropbox.com/u/55228056/DoubleClickDemo.html"); WebElement message = driver.findElement(By.id("message")); //Verify color is Blue assertEquals("rgb(0, 0, 255)", message.getCssValue("background-color").toString()); Actions builder = new Actions(driver); builder.doubleClick(message).build().perform(); //Verify Color is Yellow assertEquals("rgb(255, 255, 0)", message.getCssValue("background-color").toString()); driver.close(); } 17
  15. WebDriver wait commands 19 public void waitForElementPresence(final WebDriver driver, final

    By locator) { Wait<WebDriver> wait = new WebDriverWait(driver, 900); try { wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(locator); } }); } catch (Throwable error) { } }
  16. WebDriver vs Selenium RC ▸ They both allow you to

    use a programming language in designing your test scripts. ▸ They both allow you to run your tests against different browsers. 20
  17. Benefits 22 ❏ Installation is simple than Selenium RC ❏

    Communicates directly with browser ❏ More realistic browser interaction ❏ No need of separate component as required in RC Server ❏ Fast execution time than Selenium RC and IDE
  18. 4. Selenium Grid Grid is used to run test cases

    parallel on multiple machines and browsers. 23
  19. 24

  20. Installing Selenium Grid Hub settings: ▸ Download Selenium Standalone Server

    (you need only one JAR file ) Node Settings: ▸ Download Selenium Standalone Server ▸ Download drivers for browsers (Google Chrome, IE, Edge) 25
  21. Usage cases 26 Start Hub: java -jar selenium-server-standalone-<version>.jar -role hub

    Start Node: java -jar selenium-server-standalone-<version>.jar -role node -hub http://<hub address>:<hub port>/grid/register -port <node port>
  22. Usage cases 27 Start Hub: DesiredCapabilities capability = DesiredCapabilities.firefox(); WebDriver

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
  23. If everything works, you should see the IP address of

    the node you just started and registered in the hub console view: 28
  24. Benefits 29 • Multiple tests can be executed simultaneously in

    different browsers and environments. • It usually saves time. • It employ hub-nodes concept. For each connected node, hub acts as main source of Selenium commands.
  25. Conclusion 30 Because of Selenium features and easy to use

    APIs, Selenium testing suit becoming the first choice for automation testers to test GUI and functionality of web based application.