Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automating GUI testing with Selenium WebDriver, Java and Eclipse

Similar presentations


Presentation on theme: "Automating GUI testing with Selenium WebDriver, Java and Eclipse"— Presentation transcript:

1 Automating GUI testing with Selenium WebDriver, Java and Eclipse
Selenium Basics Automating GUI testing with Selenium WebDriver, Java and Eclipse Tom Wimsatt, CTAL Columbia Software Test Meetup December 1, 2016 1

2 Selenium Basics - Agenda
Introduction to Selenium Eclipse JUnit Selenium Environments IDE WebDriver Browsers – IE and FF 2 ©2013 Sotera Defense Solutions, Inc. All Rights Reserved. 2

3 Selenium Basics - Agenda
Test Formatting Test Case, Test Suite, Test Runner Design Patterns Making the Most of Test Automation Handling Errors and Exceptions Object Identification - Locators Resources 3 ©2013 Sotera Defense Solutions, Inc. All Rights Reserved. 3

4 Selenium Basics - Introduction
Selenium is for browser automation FireFox Internet Explorer Chrome Etc. Supports many languages Java Python Ruby 4 ©2013 Sotera Defense Solutions, Inc. All Rights Reserved. 4

5 Selenium Basic - Introduction
Selenium leverages JUnit and is supported by Eclipse: Asserts TestCase, TestSuite, TestRunner 5 ©2013 Sotera Defense Solutions, Inc. All Rights Reserved. 5

6 Selenium Basics - Environments
Selenium IDE FireFox Browser plug-in Includes formatters for Ruby, Python, Java, C# Useful for debugging – Locating objects in particular Quick scripting of tests Not recommended for long term or serious test development – inflexible (no looping, etc).

7 Selenium Basics - Environments
Selenium WebDriver Works with Eclipse through jars Step toward Selenium Grid – multiple machine and environment automation. Ultimate in flexibility

8 Selenium Basics - Environments
Browsers Internet Explorer – simple but somewhat inflexible browser for testing. Tips Object ID – F12 for Developer Tools Compatibility View pre-IE 11

9 Selenium Basics - Environments
Browsers FireFox – very flexible. Profiles give the tester options for setting up the browser for different purposes. Object ID – Developer Tools > Inspector FireBug plug-in for older FF versions Disable all add-ins for a clean profile for testing. Use that as the default. firefox.exe -p

10 Selenium Basics - Environments
Browsers FireFox (cont'd) Create profiles or rename them for specific purposes firefox.exe -p Older versions of Selenium required separate FF jar To get all FF preferences: about:config in the address bar

11 Selenium Basics – Test Formatting
JUnit Classes Test Case – Individual or collected tests @Before or setUp – execute this method before every test Initialize the browser with default timing Navigate to initial home page to begin testing

12 Selenium Basics – Test Formatting
JUnit Classes Test Case (cont'd) @Test or testName – the actual test One or more tests in a test class @Before are executed for each test @After or tearDown executed after each test method Close the browser

13 Selenium Basics – Test Formatting
JUnit Classes Test Suite – collection of Test Cases Test Runner – Execution of test cases (main)

14 Selenium Basics – Test Formatting
Design Patterns Classes for browser initialization Include default timing parameters for page loads, object appearances, failure waits. Default settings e.g. default certificate handling Object Repositories Repository class for each page Collect in a separate package

15 Selenium Basics – Making the Most of Automated Testing
The keys to GUI test automation are: Handling errors – when the test fails. Handling dynamic object names – the code may name the objects on the page as it loads or after compiling.

16 Selenium Basics – Making the Most of Automated Testing
Handling errors – capture the error and continue testing. Define your initial condition for all tests All tests in a suite begin at the same place Return to the initial condition at the end of each test – reset to default. Carefully plan tests that may have to build on one another

17 Selenium Basics – Making the Most of Automated Testing
Handling errors (cont'd) If testing for errors, know what the possible errors could be: Runtime exceptions Error dialog – modal? Browser crashing

18 Selenium Basics – Making the Most of Automated Testing
Object Identification – Locators By ID, By Name, By Xpath – Not as widely supported. IE and FF support Xpath. By CSS Selector Native support in most browsers. Faster than Xpath

19 Selenium Basics – Making the Most of Automated Testing
Object Identification – Locators (cont'd) The findElement() method Locate a single element on a page Perform actions on elements click clear getAttribute and getText sendKeys

20 Selenium Basics – Making the Most of Automated Testing
Object Identification - Locators (cont'd) The findElements() method Locate a list of similar elements on a page Use to navigate down to the element you need Narrows down the elements Select the Nth element in a set Example: List<WebElement> elements = driver.findElements(By.cssSelector(“div.button”));

21 Selenium Basics – Making the Most of Automated Testing
Object Identification - Locators (cont'd) The trick to locators is in the wildcarding: Element div attribute id begins with 't' by.cssSelector(“div[id^='t']”) Element div attribute id ends with 't' by.cssSelector(“div[id$='t']”)

22 Selenium Basics – Making the Most of Automated Testing
Object Identification - Locators (cont'd) Combine attributes to better locate the element: Element div attribute id and class ends with 't' by.cssSelector(“div[id^='t'][class$='t']”)

23 Selenium Basics – Making the Most of Automated Testing
Object Identification - Locators (cont'd) Iterate through a list using attributes: List<WebElement> elements = driver.findElements(by.cssSelector... for(WebElement element : elements) { String attrib = element.getAttribute(“value”); }

24 Selenium Basics – Making the Most of Automated Testing
Object Identification - Locators (cont'd) Iterate through a list using containing text: List<WebElement> elements = driver.findElements(by.cssSelector... for(WebElement element : elements) { String attrib = element.getText(); }

25 Selenium Basics – Making the Most of Automated Testing
Selection When presented with a list of options: Select(WebElement).selectByVisibleText(“This One”); Switching Windows Set<String> handles = driver.getWindowHandles(); Driver.switchTo().window(handle);

26 Selenium Basics - Resources
Selenium HQ - Rosetta Stone for Locators: Selenium 2 Testing Tools Selenium Testing Tools Cookbook Selenium WebDriver Practical Guide Packt Publishing: 2626 ©2014 Sotera Defense Solutions, Inc. All Rights Reserved. 26

27 Selenium Basics - Resources
Robert T. (Tom) Wimsatt, CTAL Sotera Defense Solutions, Inc. 2727 ©2014 Sotera Defense Solutions, Inc. All Rights Reserved. 27


Download ppt "Automating GUI testing with Selenium WebDriver, Java and Eclipse"

Similar presentations


Ads by Google