25
Test Automation with Twist and Sahi May 2014 Mattersight Corporation 1 Eric Blackburn, Chris Stanush, Peter Zejda

Test Automation with Twist and Sahi

Embed Size (px)

DESCRIPTION

A brief presentation on Twist, Sahi, and design patterns that assist with GUI Functional Test Automation.

Citation preview

Page 1: Test Automation with Twist and Sahi

Test Automation with Twist and Sahi

May 2014

Mattersight Corporation

1

Eric Blackburn, Chris Stanush, Peter Zejda

Page 2: Test Automation with Twist and Sahi

Agenda

2

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 3: Test Automation with Twist and Sahi

Save Questions Till The End

3

• We will stick around

Page 4: Test Automation with Twist and Sahi

Agenda

4

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 5: Test Automation with Twist and Sahi

Why

5

• Functional Test Automation – hard

• GUI Functional Test Automation - especially hard− DOM changes occur often− Complex HTML controls − Support multiple browsers− Record and playback is fragile – doesn’t support change− Need for separating the “What” from the “How”

• Intent (the “What”) doesn’t change as often as the testing method (the “How”)

• Business side needs to write/maintain scenarios, not developers

• Automated testing needs to be faster than manual

• Testing tools can be expensive

• Need ability to “check in” / version Test Cases with code

• Need a full language and enterprise software architecture / design to create an effective test framework (and make part of ConDel)

Page 6: Test Automation with Twist and Sahi

Agenda

6

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 7: Test Automation with Twist and Sahi

7

What is Sahi

• Sahi is the proxy between Java and the Browser− Java -> Sahi -> Javascript -> Browser− Java <- Sahi <- Javascript <- Browser

• Learn more about Sahi: http://sahi.co.in/

Page 8: Test Automation with Twist and Sahi

Agenda

8

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 9: Test Automation with Twist and Sahi

9

Sahi vs Selenium

• Selenium− Positives

• Run JavaScript directly against the browser• Widely used• Different flavors

− Selenium 2.0− Geb− Helium

− Negatives• Lack of auto-waits for Ajax calls

− http://www.thoughtworks.com/products/docs/twist/current/help/how_do_i_handle_ajax_in_selenium2.html

• Wait for driver updates• For built in functions, different experiences with different drivers.

• Sahi− Positives

• Run JavaScript directly against the browser• Automatically waits for page to load and for any Ajax calls to finish• For built in functions, same experience for all browsers.• Supports concurrent testing (batch runs)

− Negatives• Sometimes proxy doesn’t initiate properly.

Page 10: Test Automation with Twist and Sahi

Agenda

10

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 11: Test Automation with Twist and Sahi

11

Twist http://www.thoughtworks.com/products/twist-agile-testing

• BDD interface built into Eclipse

• Cost − $100 a year per developer

• Free updates

− Able to export libraries and run on test harness systems/servers for free, as many test harness servers as desired.

Page 12: Test Automation with Twist and Sahi

12

Twist - Behavior-driven Development BDD [1]

• Domain Specific Language (DSL)• Business can write tests

− Non-formal English− Specify intent− Abstracted step from how it is implemented

• Code changes, but the sentence (intent) remains the same.

− Prior to code being implemented• BDT

[1] http://en.wikipedia.org/wiki/Behavior-driven_development

Page 13: Test Automation with Twist and Sahi

13

Twist

• GUI and Non-GUI functional testing• Contexts

− Setup and Teardown steps always run, when added to a scenario

• Tags− Used to organize scenarios− “Not IE7”, “Disabled”, “Active”

• Steps from multiple Classes• Comments• Manual steps• Table driven steps• No browser focus needed• Auto snapshots for failures• Auto generated HTML result reports• Jenkins slave runs tests via ANT or Maven

− Windows needs VNC service running (browser needs GUI rendering). Real VNC free edition works fine.

− Reportedly Linux can run headless

Page 14: Test Automation with Twist and Sahi

14

Twist

• Table driven steps−Can fail sections of the table using Asserts

• Run results as HTML Report• More info about how to use various features is available at

− http://www.thoughtworks.com/products/docs/twist/current/help/whats_new.html

Page 15: Test Automation with Twist and Sahi

Agenda

15

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 16: Test Automation with Twist and Sahi

16

Design Suggestions – Browser Adapter

• Problem− Dependency on the web interaction

tool (Sahi)

• Solution− Abstract browser interaction

• Portability• Identify elements via JavaScript

chaining (pass around strings)

− Browser Adapter class • All of code inherits added or changed

classes • Doesn’t help when a class is removed

− Create own API• Not a big deal

− 15 methods for Action− 7 methods for State

• Better API than original

Page 17: Test Automation with Twist and Sahi

17

Design Suggestions – Control Object Pattern

• Problem− Many web controls

• Each with specialized find, set and verify functionality

− Control interfaces can be very complicated

− Control interfaces do change

• Solution− Follow the “Information Expert”

design pattern[1] • Encapsulate logic for

− Find and Set methods − Verify state of control

[1] http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)#Information_Expert

Page 18: Test Automation with Twist and Sahi

18

Design Suggestions – Pre-build JavaScript/jQuery

• Problem− Calls to the browser are

slow

• Solution− Move logic into JavaScript

• Browser is able to process complex logic fast

• Sometimes the algorithm needs to be next to the data

Page 19: Test Automation with Twist and Sahi

19

Design Suggestions – Jsoup http://jsoup.org/

• Problem− Need for complex inspection of DOM and calls to the browser are

slow.

• Solution− Use Jsoup to cache the DOM

• Return DOM content as a String and parse directly in code• Complex processing of the DOM is fast • Syntax is easy to use

Page 20: Test Automation with Twist and Sahi

20

Design Suggestions – Find Elements

• Problem− Identify web content based on what the scenario writer can see

• Solution− public String findNthVisibleElement(FieldTypeEnum fieldType, String

parentSelectorValue, String elementIdentifier, int index)

• A central function that is able to find elements. Elements can be identified by their text content, id, name, aria-label, etc.

− Identify an element by passing around a String that can be used to scope up and down• Use JavaScript or jQuery syntax

Page 21: Test Automation with Twist and Sahi

21

Design Suggestions – Find Elements – Helper Methods

• List out what controls can exist as

• List out what identifies are used for each HTML element type

Page 22: Test Automation with Twist and Sahi

22

Design Suggestions – Find Elements – Helper Methods

• Build comma delimited selector using the identifier and the list of element types− e.g. “#userinput, .userinput, [aria-label=‘userinput’]”

Page 23: Test Automation with Twist and Sahi

23

Design Suggestions – Find Elements – Helper Methods

• ContainsExact(Case) – Find element that only contains• Problem - :Contains(‘some of text’) doesn’t work

• Matches both− <span>some of text</span>− <span>text and some of text and more text</span>

• Solution - :ContainsExact(Case)(‘some of text’) works• Matches only

− <span>some of text</span>

Page 24: Test Automation with Twist and Sahi

Agenda

24

• Why• Sahi• Sahi vs Selenium• Twist• Design Suggestions• Demo Video• Questions

Page 25: Test Automation with Twist and Sahi

• Concerns, Ideas, Requests, Champagne?

Questions?