Writing reliable end to end tests

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Writing reliable end to end tests"

Transcription

1 Writing reliable end to end tests

2

3 End to end browser tests They take a long time to run. Around 4-12 hours Long feedback cycles Tough to read or modify Flaky Not part of the development life cycle

4 End to End Integration Unit Tests End to end Integration Unit tests are important but they aren t tests they are part of the development process. Unit tests

5 Why is end to end testing important? Tests whether the flow of an application is performing as designed from start to finish.

6 Goal Simulate what a real user scenario looks like from start to finish.

7

8 Whit

9 TLDR; Reasons Solutions

10

11 Research

12 Over Engineering

13 void test() { driver.get( google.com ); WebElement element = driver.findelement(by.name( q )); element.sendkeys("testing frameworks ); element.submit(); }

14 void google(string query) { driver.get("google.com"); WebElement element = driver.findelement(by.name("q")); element.sendkeys(query); element.submit(); } void testone() { } google("automated testing"); void testtwo() { } google( qcon london );

15 class GoogleHomePage { GoogleHomePage(Webdriver driver) { driver.get("google.com"); this.driver = driver; } Not so simple Test void searchfor(string query) { WebElement element = driver.findelement(by.name("q")); element.sendkeys("testing frameworks"); element.submit(); } } Noise void testone() { GoogleHomePage page = new GoogleHomePage(); page.searchfor("testing frameworks") } void testtwo() { GoogleHomePage page = new GoogleHomePage(); page.searchfor("flying foxes") }

16 Page Object Pattern Advanced Page Object Pattern Facade Design Pattern Singleton Design Pattern Fluent Page Object Pattern IoC Container and Page Object Strategy Design Pattern Advanced Strategy Design Pattern Observer Design Pattern Observer Design Pattern via Events and Delegate Observer Design Pattern via IObservable and IObserver

17 Tester s spend close to 50% of the time designing and maintaining test frameworks

18 class GoogleHomePage { GoogleHomePage(Webdriver driver) { driver.get("google.com"); this.driver = driver; } Not so simple Test void searchfor(string query) { WebElement element = driver.findelement(by.name("q")); element.sendkeys("testing frameworks"); element.submit(); } } void testone() { GoogleHomePage page = new GoogleHomePage(); page.searchfor("testing frameworks") } void testtwo() { GoogleHomePage page = new GoogleHomePage(); page.searchfor("flying foxes") }

19

20 Eliminate design Think like a user

21 # Specification ## Scenario * Step

22 # Specification ## Scenario * Step

23 # Search the internet ## Search Google * Goto google.com" * Search for QCon London * Verify Qcon London on the first page

24 # Search the internet ## Search Google * Goto google.com" * Search for QCon London * Verify Qcon London is on the first page ## Search Duck * Goto duck.com * Search for QCon London * Verify Qcon London is on the first page

25

26 @Step("Goto <site>") # Search the internet public void goto(string site) { driver.get(site); ## Search Google * Goto google.com * Search for QCon London Search for <query> ) public void goto(string query) { WebElement element = ## Search Duck * Goto duck.com * Search for QCon London driver.findelement(by.name( q )); element.sendkeys(query); element.submit(); }

27

28 Single binary install Customisable reports Data driven tests Plugins Parallel execution Support for all IDE s and languages

29 Reduced code Readability User empathy Quick feedback

30 Flakiness Selectors Waits Intrusive By.Id( pressme ) Source based By.Name( pressme ) Structural By.xpath( //html/body/button ) Implicit Driver.findElement( ).click() Explicit wait wait = new WebDriverWait(driver, 20); wait.until( ) Fluent wait new FluentWait(WebDriver reference).withtimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS)

31 Smart Locators click( PRESS ME )

32 Smart Locators write( Qcon )

33 Proximity Selectors click(checkbox(near( Accept terms and conditions)))

34

35 step( Go to <website>, (website) => { goto(website): # Search the internet # Search Google }); step( Search for <query>, (query) => { write(query); * Go to "google.com" * Search for qcon * Verify press( Enter ); });

36 gocd.org taiko.gauge.org

37 Gauge is not BDD Non prescriptive syntax Parallel runs out of the box Screenshots on failure First class IDE Support Data stores, external data

38 Concepts # Book <number> tickets * Pick <number> seats * Login in as "John" * Pay using credit card * Check ticket Specification # Search for movies * Set location as "Bangalore" ## Search for blockbusters * Search for theatres playing "Avengers" * Book "2" tickets ## Search 2017 Oscar winners * Search for theaters playing "The shape of water" * Book "2" tickets