Automated Browser Testing

22
Automated Browser Testing Darren Hickling September 2014

Transcript of Automated Browser Testing

Page 1: Automated Browser Testing

AutomatedBrowser Testing

Darren Hickling September 2014

Page 2: Automated Browser Testing

Overview

Page 3: Automated Browser Testing

3 / 22Automated Browser Testing Darren Hickling

In a Nutshell

• Automate browsers to create repeatable integration and regression tests

• Those tests can be run in parallel on different browsers on different hardware to more efficiently ensure consistent behaviour

Page 4: Automated Browser Testing

4 / 22Automated Browser Testing Darren Hickling

The Tech

• Selenium emerged as the obvious choice• Installed and managed via NuGet for C#• Supports all major browsers, including mobile

• Uses the same API for each• Makes direct calls to the browser where possible

• To provide e.g. file downloading• Easy to learn and very powerful

Page 5: Automated Browser Testing

Examples

Page 6: Automated Browser Testing

6 / 22Automated Browser Testing Darren Hickling

Browser Switching

Download a browser driver from NuGet and load it

using OpenQA.Selenium.Chrome;using OpenQA.Selenium.IE;

// Setup...RemoteWebDriver driver = new InternetExplorerDriver();

// Later...Driver = new ChromeDriver();

Page 7: Automated Browser Testing

7 / 22Automated Browser Testing Darren Hickling

Element Selection

Select and filter elements by their tags and attributes

var tableContentRows = WebDriver .FindElements(By.TagName("table")) .FirstOrDefault(e => e.GetAttribute("media") == "screen") .FindElements(By.TagName("tr")) .Skip(1);

Page 8: Automated Browser Testing

8 / 22Automated Browser Testing Darren Hickling

Actions

Queue and perform a set of actions fluently

new Actions(WebDriver) .ClickAndHold(firstListItem) .MoveToElement(secondListItem) .MoveByOffset(0, 5) .Release() .Perform();

Page 9: Automated Browser Testing

Impressions

Page 10: Automated Browser Testing

10 / 22Automated Browser Testing Darren Hickling

Patterns Rock

• Two useful patterns have already emerged• Use a Page to interact with the elements of a page

• Fill forms• Click buttons

• Build a Navigator to perform a user journey• Take the name a problem domain• Chain many Page interactions

Page 11: Automated Browser Testing

11 / 22Automated Browser Testing Darren Hickling

Problems

• Complex element selection can be convoluted• Finding a parent element, then filtering its

descendants• Using XPath• jQuery selector plugins are also available!• However, you might be masking the fact that this is

unnecessarily difficult?• No other complaints so far

Page 12: Automated Browser Testing

12 / 22Automated Browser Testing Darren Hickling

Act as Documentation

• Watching a full integration test suite in action is surprisingly magical and enlightening!

• Make a change here, watch it impact that thing there, understand the domain more

• Great for new engineers and those unfamiliar with a product/concept

Page 13: Automated Browser Testing

13 / 22Automated Browser Testing Darren Hickling

Theme and Resize Testing

• Selenium can take a screenshot of the browser• Pick specific screens, screenshot them and compare to

the originals• Resize the browser and screenshot at the different

sizes for responsive testing• Store a hotspot overlay of the failed comparison to

quickly identify the problem• No drawing red ovals in Paint!

Page 14: Automated Browser Testing

14 / 22Automated Browser Testing Darren Hickling

Project Workflow Changes

• QA write/evolve test plans from:• High-level project goals• Diagrams/wireframes• Experience!

• SE create automated tests from the plans• Code-reviewed with their BI logic and unit tests

• QA review:• By manually following their test plans

• Checking recordings via supported cloud VM service

Page 15: Automated Browser Testing

15 / 22Automated Browser Testing Darren Hickling

Bug Workflow Changes

Triage an issue

QA test and release

Add or update unit tests

Fix the problem!

Ensure browser test now pass

Replicate with browser tests

Code review all changes

Page 16: Automated Browser Testing

16 / 22Automated Browser Testing Darren Hickling

Cross-Browser Testing

• Browsers limited to those available on the box used for testing

• At a minimum, use installed browsers on the build server

• Will slow down other builds, though• Not parallelised, either• VMs seem a better and recommended option• Kick off the move to Azure now? Or use…

Page 17: Automated Browser Testing

17 / 22Automated Browser Testing Darren Hickling

Sauce Labs

• Provide 359 device/OS/browser platforms via VMs• Used by EventBrite, Yelp, Mozilla and others• Free to evaluate at a very small scale• Automated tests capped per subscription• Unlimited manual tests• C# sample project on Github• Integrates with TeamCity and Bamboo

Page 18: Automated Browser Testing

18 / 22Automated Browser Testing Darren Hickling

Test Dashboard

Page 19: Automated Browser Testing

19 / 22Automated Browser Testing Darren Hickling

Profile the Test Server

• Run a profiler on the box that the tests hit• Pick from one of four contenders, such as ANTS• Provide consistent, historical profile trends

• Have our changes affected performance?• Automated performance issue alerts

• Including advertising huge improvements!• Could mostly prevent (lucky?) devs with a profiler

license from needing to help others

Page 20: Automated Browser Testing

In Conclusion

Page 21: Automated Browser Testing

21 / 22Automated Browser Testing Darren Hickling

Selling Points

• Confidently assert the product functions effectively on many platforms

• Resolved issues are less likely to reappear• Worth the investment for this alone?

• Identify and fix performance problems before they reach clients

• Advertise significant performance gains

Page 22: Automated Browser Testing

22 / 22Automated Browser Testing Darren Hickling

More Selling Points

• Reduce the time taken for engineers to understand a issue/product/concept

• Reduce the likelihood that large changes will adversely affect existing functionality

• Clients do/will expect this level of testing