+ All Categories
Home > Software > Build Fail-Proof Tests in Any Browser with Selenium

Build Fail-Proof Tests in Any Browser with Selenium

Date post: 21-Jan-2018
Category:
Upload: techwell
View: 46 times
Download: 0 times
Share this document with a friend
16
BT12 Test Automation 11/17/2016 3:00:00 PM Build Fail-Proof Tests in Any Browser with Selenium Presented by: Kevin Berg Sauce Labs Brought to you by: 350 Corporate Way, Suite 400, Orange Park, FL 32073 888--268--8770 ·904--278--0524 - [email protected] - http://www.stareast.techwell.com/
Transcript
Page 1: Build Fail-Proof Tests in Any Browser with Selenium

BT12 Test Automation 11/17/2016 3:00:00 PM

Build Fail-Proof Tests in Any Browser with Selenium

Presented by:

Kevin Berg

Sauce Labs

Brought to you by:

350 Corporate Way, Suite 400, Orange Park, FL 32073

888-­‐268-­‐8770 ·∙ 904-­‐278-­‐0524 - [email protected] - http://www.stareast.techwell.com/

Page 2: Build Fail-Proof Tests in Any Browser with Selenium

Kevin Berg Sauce Labs

Kevin Berg is a customer automation specialist at Sauce Labs where he works with prospective, new, and existing customers to adapt their tests and frameworks to enhance their parallel and cross browser testing capabilities. Kevin has written test framework examples that exhibit both parallel execution and cross browser testing capability for desktop and mobile platforms. As a proponent of open source materials, these examples are publicly available on GitHub (@KevinMarkVI). A classical musician turned software engineer, Kevin enjoys watching sports, playing video games, and spending time outdoors with his wife and dog.

Page 3: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

1

F a i l P r o o f Te s t s i n A n y B r o w s e r F a i l P r o o f Te s t s i n A n y B r o w s e r w i t h S e l e n i u mw i t h S e l e n i u mw i t h S e l e n i u mw i t h S e l e n i u mK E V I N B E R G , C U S T O M E R A U T O M AT I O N

S P E C I A L I S T

Kevin Berg

A little about me:

D r . K e v i n B e r g , D M A

• Help customers transition from running test manually or on local Selenium grids, to parallel cross-browser testing in the cloud

• Write custom testing frameworks, features, and Selenium scripts

• Selenium/Appium workshops and training

• CI/CD architecture and integrationCI/CD architecture and integration

© Sauce Labs, Inc. 2

Page 4: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

2

Agenda

• Selenium – Quick Overview

• The Problem Statement

• Why Cross Browser Testing is Important

• The Actual Problem(s)

• The Solutions

• Questions

• More Questions? Come by the Sauce Labs booth!

© Sauce Labs, Inc. 3

Selenium – Quick Overview

Browser Automation Framework:

• Open source

• Used mainly for testing purposes

• Automates all the most popular browsers

• Selenium can replicate nearly any user interaction with the browser

• Bindings to all the most commonly use programming languages

• Natural language commands make it simple to start writing tests

© Sauce Labs, Inc. 4

Page 5: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

3

Automat ing wi th Selenium

browser

• get(“www myWebsite com”);• .get( www.myWebsite.com );

• .findElement();

• .click();

• .submit();

• .sendKeys();

• .isDisplayed();

© Sauce Labs, Inc. 5

The Problem

The Usual Story

1. Selenium tests are written in Firefox

2. Tests Pass!

3. Run Same tests in Internet Explorer

4. Tests Fail!

5. Anger

What is Happening?

© Sauce Labs, Inc. 6

Page 6: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

4

Our Problem is Actual ly Two Problems

Browsers

• They are not all the same

Browser Automation Drivers

• Also not the same

© Sauce Labs, Inc. 7

B rowse rs

Page 7: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

5

Why Fi refox?

• Came out of the box with Selenium

• WebDriver driver = new FirefoxDriver();

• Up to Firefox version 47

• Selenium IDE Firefox Plugin

• Open Source

• Dotted lines

Firefox

Chrome

© Sauce Labs, Inc. 9

Chrome

Browsers

Each browser uses a different rendering (or layout) engine:

• WebKit (Safari and iOS)WebKit (Safari and iOS)

• Blink (Chrome, Opera)

• Gecko (Firefox)

• Trident (Internet Explorer)

• EdgeHTML (Microsoft Edge)

HTML and CSS:

• Complex with new features being added and others depreciated

• Errors handled differently

Can lead to elements being covered or not visible.

© Sauce Labs, Inc. 10

Page 8: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

6

Browser Timing Issues

Some rendering engines are faster than others

• Chrome (Fast)

• Internet Explorer (Not as fast… )

AJAX Requests

• DOM is accessed with JavaScript to dynamically display the information presented

© Sauce Labs, Inc. 11

D r i ve r s

Page 9: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

7

Browser Automat ion Dr ivers

Each Browser has its own Native Automation Support

• Firefox Marionette• Firefox - Marionette

• Version 48 moved from FirefoxDriver to Marionette

• Many Selenium methods still being implemented

• https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status

© Sauce Labs, Inc. 13

Browser Automat ion Dr ivers - Cont inued

• Internet Explorer

• Issues with Actions Library

• moveTo

• hover

• Safari

• Recently made Open Source

• JavaScript Execution

• Many of the Actions Library

• Right click

• moveTo

• sendKeys

© Sauce Labs, Inc. 14

Page 10: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

8

The Actual Problem(s)

Locating Elements in Different Browsers

• Page load times can vary• Page load times can vary

• Elements may not be on the page • No Such Element Errors

• Pop-ups and/or Alerts are handled differently by each browser

• Elements can be hidden by other elements

• Element not clickable errors

• Individual browser native automation Selenium implementation• Individual browser native automation Selenium implementation inconsistencies

With today’s access to cloud based Selenium grids, it is easier than ever to test across all the most popular browsers.

© Sauce Labs, Inc. 15

The Solut ions!

Waits

• Built in mechanisms that will allow for variation in website page• Built in mechanisms that will allow for variation in website page loading times and/or dynamically loading elements

• Two different types that work in different ways

• Implicit Waits

• Explicit Waits

• Sleeps

Understanding driver limitations

• Work Arounds

© Sauce Labs, Inc. 16

Page 11: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

9

Wai t i ng S t ra teg ies

Impl ic i t Wai ts

Implicit Wait

Tells the WebDriver to poll the browser DOM for a certain amount• Tells the WebDriver to poll the browser DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

• Applied to the WebDriver instance itself

© Sauce Labs, Inc. 18

Page 12: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

10

Expl ic i t Wai ts

Explicit Waits

• Code you define to wait for a certain condition to occur beforeCode you define to wait for a certain condition to occur before proceeding further in the test.

• E.g. Poll the DOM until the element I’m looking for is visible

• Used with individual elements as opposed to a blanket timeout on the WebDriver instance

• Sleeps

© Sauce Labs, Inc. 19

But wai t… I ’m confused…

They sound similar, and a Sleep is also a type of Explicit Wait?

Ne er se Sleeps• Never use Sleeps

• Don’t use Implicit Waits

• Can cause problems when the element you are trying to interact with is not ready• E.g. Can be found in the browser DOM before it is visible• Hidden/Disabled elements• Use Explicit Waits that Wait for a Condition (Not Time)

• Element to be Enabled, Visible, Clickable, Selected

• Never mix Implicit and Explicit Waits

• Seriously, Never use Sleeps

© Sauce Labs, Inc. 20

Page 13: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

11

Using Expl ic i t Wai ts

Use them any time an element is not immediately available.

• That is a lot of the time

• Page Loads, Form Submissions, Pop-Ups, etc.

• Example of how to implement in a Page Object:

© Sauce Labs, Inc. 21

F luent Wai ts

Fluent Waits

• Build your own Explicit Wait!• Build your own Explicit Wait!

• Configuration

• Timeout

• Polling Rate

• Errors to Ignore

• Use Cases

• Stress on Internal Infrastructure

• Specific Errors

© Sauce Labs, Inc. 22

Page 14: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

12

Dr i ve r Worka rounds

Driver Speci f ic Workarounds

Send Keys Example:

© Sauce Labs, Inc. 24

Page 15: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

13

Driver Speci f ic Workarounds - 2

Executing JavaScript:

• Don’t do it!Don t do it!

• Executing JavaScript within a functional test doesn’t tell you if the UI is functioning

• Work with developers to ensure the page is testable

© Sauce Labs, Inc. 25

Resources

• SeleniumHQ

• http://www.seleniumhq.org/docs/

• The Selenium Guidebook by Dave Haeffner

• https://seleniumguidebook.com/

• ”Implicit Waits vs Explicit Waits” by Siva Dhanamjay

• http://www.aptuz.com/blog/selenium-implicit-vs-explicit-waits/

• “Difference Between Implicit, Explicit & Fluent Wait” by LakshaySharma

• http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/

• “Why don’t web browsers render the same content identically?” by Aaron Boodman

• https://www.quora.com/Why-dont-web-browsers-render-the-same-content-identically/

© Sauce Labs, Inc. 26

Page 16: Build Fail-Proof Tests in Any Browser with Selenium

11/1/2016

14

Thank you f o r a t t end ing t h i s sess ionsess ion .

Please f i l l ou t an eva lua t ion fo rm.


Recommended