Increase Selenium tests stability via JavaScript Igor Khrol http://www.khroliz.com
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
Agenda • Theory and some reasoning • Practical cases
Dependency between testing level and support Support Test count Tech level
UI-tests are unstable
UI-tests are unstable One of the reasons – modern user interfaces: – Complex – Asynchronous
Modern user interfaces are based on prepared and already made components
Modern user interfaces are based on prepared and already made components
Already made components could be less tested by ourselves
Custom components could be tested separately
Majority of modern UI has internal API
API benefits • Build to interact with UI components • Synchronous (or there are methods to sync)
1. UI based on already made components 2. Already made components could be left untested or could be tested separately 3. Components have its own API 4. That API is more reliable thanWebDriver API Use JavaScript API instead of WebDriver
Life example
User interface characteristics: • Lots of frames • ActiveX
Initial solution driver.findElement(By.id(“fancy-id”)).click(); WebDriver API Browser
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
Browser Script API http://docs.oracle.com/cd/B40099_02/books/OI Ref/OIRefBrowseScript.html Browser Script HTTP Server Script
Examples
Final result • Quick • Reliable • Synchronous
Problems
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
window.setTimeout
Lost 100% end user simulation
Other cases for such approach
jQuery based sites - 60%
Synchronization
Convert jQuery objects to WebElement and vise versa
Find elements
Get parent element
Ease interaction with complex elements Calendar Thanks to @barancev
Custom controls
Custom controls
Common schema Web Server Browser HTTP Tests Visible UI Library API Components Core WebDriver API WebDriver API JavaScriptExecutor
Temporary workaround existing WebDriver issues
Workaround wisely • Only temporary workaround • Important to understand why standard approach doesn’t work
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
Thank you! Questions? Igor Khrol http://en.khroliz.com i_khrol@wargaming.net / khroliz@gmail.com

Increase selenium tests stability via java script