Slide 1

Slide 1 text

Simplifying Test Automation of Web Applications Using Visual Inspection and Page Objects Daniel Gallo Senior Solutions Architect Sencha, Inc. [email protected]

Slide 2

Slide 2 text

Overview • The problems and complexities of testing dynamic web apps • Overview of Sencha Test and how it helps • Locating elements on the page and generating meaningful locators • Creating page objects for robust and maintainable tests • Writing end-to-end tests • Automating tests by integrating with Jenkins and JIRA

Slide 3

Slide 3 text

Problems and Complexities of Testing Web Apps

Slide 4

Slide 4 text

Permissive Open Source Test Frameworks • A typical web testing project would utilize multiple solutions • Wikipedia: • 40+ listed on the ‘List of Unit Testing Frameworks’ • Selenium • Automates browsers, and works in tandem with all test frameworks • Limited on its own though

Slide 5

Slide 5 text

Open Source Testing Pain Points • Customers have to spend a lot of time to get the barebones structure in place • Reports are available only in HTML files at best. Customers have to do the heavy lifting to render it in a more readable format • Don’t have capabilities such as visual screen comparison • Lots of choices • Dependency on 3rd party contributors

Slide 6

Slide 6 text

Dynamic Web Apps • JavaScript web app frameworks can abstract the HTML layer away from the developer • This can mean the rendered HTML differs across browsers and form factors • Because of these dynamic web apps, IDs of elements may change between each test run • There needs to be a more stable way of referencing components on a page

Slide 7

Slide 7 text

How Sencha Test can help

Slide 8

Slide 8 text

Sencha Test: Cross-Browser Unit and End-to-End Functional Testing for Ext JS Apps Accelerate the testing of complex web applications for improved quality and enhanced developer productivity • Unit test and end-to-end functional testing • Author and execute tests • Record and playback tests • Review and archive results • Review and report on code coverage

Slide 9

Slide 9 text

Sencha Test Components Test Studio Test Authoring Test Runner Test Execution Test CLI Test Automation Test Archiver Results Reporting And Archiving

Slide 10

Slide 10 text

Test Authoring: Sencha Test Studio • Write unit and end-to-end functional tests in JavaScript (Jasmine) by using built-in test editor, or in a separate IDE • Store tests in your SCM • Quickly and easily write and execute tests while coding • See all test results in a grid/matrix • Access the Inspect utility, to generate reliable locators

Slide 11

Slide 11 text

Test Execution: Test Runner • Run select tests on any or all browsers on local machine or browser farm • Dramatically reduce testing time by executing tests simultaneously on multiple browsers through integration with leading browser farms such as Sauce Labs and BrowserStack

Slide 12

Slide 12 text

Test Automation: Sencha Test CLI (Command Line Interface) • Maximize the efficiency of your testing through automated test runs • Launch tests within the CI system as soon as application changes and tests are checked into the source control repository • Out of the box integration with TeamCity and Jenkins code test review

Slide 13

Slide 13 text

Test Execution: Test Archiver • Review results from automated and manual test runs • Summary level results & drill into the detail of failed tests • Out of the box integration with Istanbul enables users to identify and rectify code coverage gaps • View % coverage at the Statements, Branches, Functions and Lines levels

Slide 14

Slide 14 text

Visual Screen Comparison: Test Archiver • Minimize the time spent verifying images on hundreds of screens • Screenshot tests are flagged as failures if there’s a difference between baseline and latest screenshot • Review images that are captured from previous test runs and compare to each subsequent test run

Slide 15

Slide 15 text

Out Of The Box Integrations Jasmine Test Framework Browser Farms Jenkins / TeamCity Istanbul Code Coverage Istanbul

Slide 16

Slide 16 text

Demo Sencha Test Studio Sample App

Slide 17

Slide 17 text

How Tests Are Run Two Methods

Slide 18

Slide 18 text

Sencha Test: How tests are run • Two ways of executing tests: • In-browser mode – web app is proxied through Sencha Test • WebDriver mode – browser directly accesses app

Slide 19

Slide 19 text

Sencha Test: How tests are run (Proxy) • Sencha Test Studio will include the Jasmine library inside of a customized index.html page, along with references to your app’s code files and test files • Tests can then be executed in the context of that page • Sencha Test hosts the app using its own built-in reverse proxy to facilitate all requests to the app • So this app URL: • Will show as this URL in the browser: https://local.sencha.com/MyApp/ http://127.0.0.1:8700/MyApp/?orionAgentId=1

Slide 20

Slide 20 text

Sencha Test: How tests are run (WebDriver) • Sencha Test Studio will leverage WebDriver to establish a connection to the browser • Browser launches the application directly • Tests run separately from the browser • Requires configuration of WebDriver add-on for each browser • This approach supports multi-page app testing (navigability between pages during test runs)

Slide 21

Slide 21 text

Demo WebDriver scenario

Slide 22

Slide 22 text

Futures API

Slide 23

Slide 23 text

Make asynchronous tests simple and reliable (like synchronous tests)

Slide 24

Slide 24 text

Sencha Test - Futures API • Testing dynamic web apps is difficult, because tests may try and reference elements in the page before they’re fully rendered, or have data • Many Integration and App tests are asynchronous. They wait on: • Loading data • Rendering • Animations • Layouts • Asynchronous tests • Harder to write • Harder to maintain • Sometimes fail sporadically (race conditions)

Slide 25

Slide 25 text

A future is an object used to describe a sequence of actions to take in the future.

Slide 26

Slide 26 text

Futures API – Sencha Ext JS Example ST.grid('#mygrid') // locate the grid .rowAt(1000) // interact with a row .cell('firstName') // now with a cell .reveal() // scroll into view .click(10, 10); // click at offset

Slide 27

Slide 27 text

Futures API – Generic HTML Table Example ST.table('@mytable') // locate the table .rowAt(1000) // interact with a row .cellAt(2) // now with a cell .reveal() // scroll into view .click(); // click the cell

Slide 28

Slide 28 text

Sencha Test - Futures API • Futures API enables chainable methods • These methods are added to an internal queue, and processed in order • Won’t proceed until the previous method succeeds • If any of the methods fails, it causes the containing test/spec to fail, along with an appropriate error ST.grid('#mygrid') // locate the grid .rowAt(1000) // interact with a row .cell('firstName') // now with a cell .reveal() // scroll into view .click(10, 10); // click at offset

Slide 29

Slide 29 text

Futures: Locator • Futures are fetched using ST.Locator selector syntax • At-path • Xpath • DOM Query • Component Query • Composite query (component query plus a DOM selector) • You can also run ST.Locator.find() directly, in which case a DOM element is returned

Slide 30

Slide 30 text

Futures: Locator // At-path ST.Locator.find('@businessdetail-1025'); // Xpath ST.Locator.find('//div[@id="businessdetail-1025"]'); // DOM query ST.Locator.find('>>#businessdetail-1025 img'); // Component query -- returns the component's
ST.Locator.find('businessdetail'); // Combined component query plus DOM query ST.Locator.find('businessdetail => img');

Slide 31

Slide 31 text

Inspect Elements and Create Page Objects

Slide 32

Slide 32 text

Sencha Test – Inspect • Sencha Test features an Inspect tool, to help inspect elements in the page, and generate stable locators for them • These locators can either be inserted directly in to the test, along with the applicable API, or added to a reusable Page Object

Slide 33

Slide 33 text

Sencha Test – Page Objects • A Page Object is simply an object that contains a central list of all the locators required by the test suites • Rather than duplicate usage of locators in multiple tests, across multiple test suites, a Page Object acts as a central lookup for these locators • Page Objects can either be defined directly in the test suite as a simple JavaScript object, or added as a separate JS file for use across all test suites in the scenario

Slide 34

Slide 34 text

Demo Inspect Elements Page Objects Run Tests

Slide 35

Slide 35 text

Automating Tests

Slide 36

Slide 36 text

Automating Tests - Jenkins • Sencha Test features a Command Line utility • This helps to automate test runs, by enabling integration with Jenkins and TeamCity, or any other CI environment that allows custom shell scripts • Sencha Test CLI outputs the results to Text and JUnit formats that can be read by the CI environment

Slide 37

Slide 37 text

Automating Tests - JIRA • When tests fail, these failures can be easily pushed to JIRA as new issues • After a test run, the results can be reviewed, and all issues can be pushed to JIRA – you choose which project to publish the issues • For screenshot failures, the screenshots associated with the failure are attached to the JIRA ticket • Browser/OS/Version details are also logged against the ticket • If needed, certain issues can be excluded from the push to JIRA

Slide 38

Slide 38 text

Demo Automating Tests - Jenkins and JIRA Integration

Slide 39

Slide 39 text

Tip: Browser Farms

Slide 40

Slide 40 text

Browser Farms • If you don’t have the infrastructure internally, an external browser farm can be a great choice • Sauce Labs is a good example • Can select multiple combinations of Operating System, Browser, and Browser Version • Instances are quickly started on Sauce Labs infrastructure when you commence a test run • No need to maintain lots of different internal VMs

Slide 41

Slide 41 text

Demo Browser Farms

Slide 42

Slide 42 text

Tip: Dealing with data

Slide 43

Slide 43 text

Dealing with data • For any test, you need a known starting state • For screenshot comparison to work effectively, the same base data is required on each test run • In the case of end-to-end testing, you often need the database to be in a known initial state • You could have a backend service that initializes the database, and the test suite would call that before running any tests • Another technique is to define hardcoded data

Slide 44

Slide 44 text

Dealing with data: Ext.ux.ajax.SimManager • Sencha Ext JS provides a SimManager class that enables a way to serve hardcoded data for the URLs used by your proxies • Data is provided by Ext.ux.ajax.Simlet objects • Each defined URL maps to a Simlet config object containing the hardcoded data • Requires the ux package (require this in app.json) Ext.ux.ajax.SimManager.register({ "some/url/": { type: 'json', // The simlet alias data: [] // The data -- it is a hard-coded version of what would be in the feed }, "https://itunes.apple.com/us/rss/topmovies/limit=5/json": { type: 'json', data: {feed: {entry: [{},{}]}} } });

Slide 45

Slide 45 text

Questions?

Slide 46

Slide 46 text

Daniel Gallo Senior Solutions Architect Sencha, Inc. [email protected]