38
Increase Selenium tests stability via JavaScript Igor Khrol http://www.khroliz.com

Increase selenium tests stability via java script

Embed Size (px)

DESCRIPTION

My speech at Selenium Conf 2014 http://confengine.com/selenium-conf-2014/schedule#session-217-info

Citation preview

Page 1: Increase selenium tests stability via java script

Increase Selenium tests stability via JavaScript

Igor Khrolhttp://www.khroliz.com

Page 2: Increase selenium tests stability via java script

About myself• Igor Khrol• QA Automation Team Lead at

Wargaming• >8 years in test automation• Dozens of projects• Engineer, trainer, consultant,

manager, speaker• Working experience with Selenium

>5 years• My blog: http://en.khroliz.com

Page 3: Increase selenium tests stability via java script

Agenda

• Theory and some reasoning• Practical cases

Page 4: Increase selenium tests stability via java script

Dependency between testing level and support

Support

Test count

Tech level

Page 5: Increase selenium tests stability via java script

UI-tests are unstable

Page 6: Increase selenium tests stability via java script

UI-tests are unstable

One of the reasons – modern user interfaces:– Complex– Asynchronous

Page 7: Increase selenium tests stability via java script

Modern user interfaces are based on prepared and already made components

Page 8: Increase selenium tests stability via java script

Modern user interfaces are based on prepared and already made components

Page 9: Increase selenium tests stability via java script

Already made components could be less tested by ourselves

Page 10: Increase selenium tests stability via java script

Custom components could be tested separately

Page 11: Increase selenium tests stability via java script

Majority of modern UI has internal API

Page 12: Increase selenium tests stability via java script

API benefits

• Build to interact with UI components• Synchronous (or there are methods to sync)

Page 13: Increase selenium tests stability via java script

1. UI based on already made components2. Already made components could be left

untested or could be tested separately3. Components have its own API4. That API is more reliable than WebDriver API

Use JavaScript API instead of WebDriver

Page 14: Increase selenium tests stability via java script

Life example

Page 15: Increase selenium tests stability via java script

User interface characteristics:• Lots of frames• ActiveX

Page 16: Increase selenium tests stability via java script

Initial solution

driver.findElement(By.id(“fancy-id”)).click();

Browser

WebDriver API

Page 17: Increase selenium tests stability via java script

Difficulties

• Interface is very asynchronous, methods work unstably

• Lots of frames (more than five nested) – hard to reach required control

• Impossible to work with ActiveX

Page 19: Increase selenium tests stability via java script

Examples

Page 20: Increase selenium tests stability via java script

Final result

• Quick• Reliable• Synchronous

Page 21: Increase selenium tests stability via java script

Problems

Page 22: Increase selenium tests stability via java script

Synchronous methods and Alert

• Method call is not finished while Alert is not closed

• alert.accept() can’t be called as previous command is not finished yet

Page 23: Increase selenium tests stability via java script

window.setTimeout

Page 24: Increase selenium tests stability via java script

Lost 100% end user simulation

Page 25: Increase selenium tests stability via java script

Other cases for such approach

Page 26: Increase selenium tests stability via java script

jQuery based sites - 60%

Page 27: Increase selenium tests stability via java script

Synchronization

Page 28: Increase selenium tests stability via java script

Convert jQuery objects to WebElement and vise versa

Page 29: Increase selenium tests stability via java script

Find elements

Page 30: Increase selenium tests stability via java script

Get parent element

Page 31: Increase selenium tests stability via java script

Ease interaction with complex elements

Calendar Thanks to @barancev

Page 32: Increase selenium tests stability via java script

Custom controls

Page 33: Increase selenium tests stability via java script

Custom controls

Page 34: Increase selenium tests stability via java script

Common schema

Web Server

Browser

HTTP

Tests

Visible UI

Library

API Components

Core

WebDriver API

WebDriver APIJavaScriptExecutor

Page 35: Increase selenium tests stability via java script

Temporary workaround existing WebDriver issues

Page 36: Increase selenium tests stability via java script

Workaround wisely

• Only temporary workaround• Important to understand why standard

approach doesn’t work

Page 37: Increase selenium tests stability via java script

Summary• Digging into technical details allows writing more

reliable tests• Learning JavaScript and UI-libraries – natural next

step for UI test automation• But we have to understand what we are missing

and find balance