Web App Testing

With Python Selenium

Arvind Padmanabhan

Testing

Frameworks

doctest, Hypothesis, nose, pytest, testtools, unittest, unittest.mock, zope.testing

RedwoodHQ, Robot Framework, Katalon Studio, Selenium, TestComplete, UFT

RedwoodHQ, Robot Framework, UFT

pytest-cov, python-coveralls, coverage

Unit Testing

Web Testing

Coverage

Acceptance

Testing

Approaches to Testing

Model Based

Library Based

Data Driven

Keyword Driven

Behaviour Driven

Hybrid

Selenium Architecture

Selenium

WebDriver

Source: https://www.emaze.com/@AZOIQRR/Selenium---Introduction (Slide 13)

Devopedia Test Architecture

My Test Environment

 

 

  • Windows 10,
    version 1703

OS

 

 

  • Firefox 53.0.2
  • Chrome 60.0.3112.90

Browsers

 

 

  • Version 3.5.2
  • Modules
    • pymysql 0.7.11
    • records 0.4.3
    • selenium 3.4.3
    • pytest 3.1.2

Python

 

 

  • Firefox: geckodriver 0.18.0
  • Chrome: chromedriver 2.31

Web Drivers

Types of Content

Static

Pages

Dynamic Content

JavaScript

Animation

AJAX Content

Interactive Design

Common APIs

 

 

  • find_element_by_id
  • find_element_by_ css_selector
  • find_element_by_ xpath
  • find_element_by_ link_text
  • Plural forms of the above

 

 

 

Locators

 

 

  • click
  • send_keys
  • move_to_element
  • move_to_element_ with_offset
  • perform
  • execute_script
  • Can chain multiple actions with perform

 

 

 

 

Actions

 

 

  • get_attribute
  • value_of_css_property
  • is_displayed
  • is_selected
  • Select.options
  • Select.all_selected_ options

 

 

 

Inspection

Waiting for Content

IMPLICIT WAITS

Default 0 secs

Global value

Default polling 500 ms

Expected Conditions

 

 

  • presence_of_ element_located

 

 

 

 

 

 

 

Presence

 

 

  • visibility_of
  • visibility_of_element_ located
  • invisibility_of_element_ located

  • staleness_of

  • element_to_be_clickable

 

 

 

State

 

 

  • text_to_be_present_ in_element
  • title_contains

  • title_is

 

 

 

 

 

Content

Tips & Tricks

Checking Color

CSS :parent

XPATH vs CSS class

text() XPATH

XPATH

Text vs innerHTML

Use DOM for AJAX tests

Give JS time to run

Reuse Browser

Reuse Test

Gecko

Chrome

Size as given in set_window_size() but Chrome's get_window_size() is right

Screenshot of element works but can't follow a JS scroll

Size smaller than as given in set_window_size()

Screenshot of element doesn't work, so capture viewport and crop

WebDriver Differences

Allows move_to_element outside the viewport

Clicking on element is inconsistent due to position or tooltip

Disallows move_to_element outside the viewport

Clicking on element is consistent even if tooltip is displayed

Intrusive Testing
(Not Recommended)

  • Modify the database
    • Can use to revert data before repeating tests

Data

  • Modify DOM
    • Only when testing framework has limitations

UI

  • Access assets directly instead of loading full web pages

Speed

Q & A

Web App Testing With Python Selenium

By Arvind Padmanabhan

Web App Testing With Python Selenium

Automated testing of web apps using Python Selenium.

  • 1,096
Loading comments...

More from Arvind Padmanabhan