Web UI test automation instruments

  • 7,005 views
Uploaded on

Main instruments used for Web UI test automation. …

Main instruments used for Web UI test automation.
Drivers: Selenium WebDriver, Sikuli X.
Frameworks: PageFactory, TestNG.
Other tools: Apache Ant, Jenkins CI.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,005
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
141
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Web UI Test Automationby Artem NagornyiDrivers: Selenium WebDriver, Sikuli XFrameworks: PageFactory, TestNGOther 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. LocatorsSelenium WebDriver finds elements in browser via DOMusing 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 PageSelenium WebDriver simulates all userinteractions 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 applicationsWhen 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 JSTesting CSS properties:● webElement.getCssValue("height")● webElement.getCssValue("background-image")JavaScript execution: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("your_js_function();");
  • 8. Frames and AlertsTargetLocator target = webDriver.switchTo();//Switching to a frame identified by its nametarget.frame("name");//Switching back to main contenttarget.defaultContent();//Switching to alertAlert alert = target.alert();//Working with alertalert.getText();alert.accept();alert.dismiss();alert.sendKeys("text");
  • 9. Browser NavigationNavigation nav = webDriver.navigate();//Emulating browser Back buttonnav.back();//Forward buttonnav.forward();//Open URLnav.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" substringassertTrue(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 Lookupwebdriver().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 tableList<WebElement> rows = table.findElements(By.tagName("tr"));System.out.println("Table rows count: " + rows.size());//print the value of each cell using the rows handlerint 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 screenpublic static void elementWait (String elementImagePath, inttimeOut) throws Exception { regionImagePath = image_folder + elementImagePath; screen.exists(elementImagePath, timeOut);}//Click element on the screenpublic 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 butintroducing some new functionalities that make it more powerfuland 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 AntApache Ant is a Java build and configurationtool that we use for:1. Compilation of Selenium WebDriver test classes2. Execution of tests3. Passing parameters from command line to test automation framework (used for selective execution of test suite and test case)
  • 21. Jenkins Continuous IntegrationServerJenkins is a popular open-source continuousintegration server that we use for:1. Scheduled execution or on-demand execution of Selenium WebDriver tests2. Integration with source control repository (SVN, GIT)3. Shared online dashboard with test results4. Keeping history of test results5. 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
  • 23. Questions