Automated Software Testing With Python

Learn about automated software testing with Python, BDD, Selenium WebDriver, and Postman, focusing on web applications

Last updated 2022-01-10 | 4.5

- Everything you need to know about automated software testing with Python (and how to enjoy testing
- too!)
- Common pitfalls and best practices when writing automated tests
- How to write complete system tests using Python and tools like Postman

What you'll learn

Everything you need to know about automated software testing with Python (and how to enjoy testing
too!)
Common pitfalls and best practices when writing automated tests
How to write complete system tests using Python and tools like Postman
Automate your application testing by setting up a continuous integration pipeline using Travis CI
Browser-based acceptance testing using Behave and Selenium WebDriver

* Requirements

* We'll give you a complete Python refresher
* but some previous knowledge of programming will be helpful
* Some knowledge of how web applications work
* Understanding of REST APIs will be helpful
* but not required

Description

Welcome to the most comprehensive course on Automated Software Testing with Python on Udemy.

Testing automation doesn't have to be painful. Software testing is an essential skill for any developer, and I'm here to help you truly understand all types of test automation with Python.

I'm Jose, a software engineer and founder of Teclado. The focus of this course is on testing for the web—we'll be working with REST APIs and web applications, and technologies such as unittest, Postman, and Selenium WebDriver.

Fear not though, after going through this course, you'll be able to take your new testing knowledge and apply it to any project, even non-web projects!

What will you work with?

This course is jam-packed with all the latest technologies for you to use professionally and in personal projects:

  • The unittest library, Python's standard automated software testing library;

  • Mocking and patching, two essential tools to reduce dependencies when testing;

  • unit, integration, system, and acceptance testing—all types of testing to have you fully covered;

  • Postman for easy collaboration and testing while developing;

  • Selenium WebDriver for automated browser tests;

  • Git and Travis for continuous integration of your project.

Fundamental Software Testing Skills

We will cover every fundamental software testing skill that you need to know in order to get a job testing or to apply these skills in your existing projects.

From things like mocking and patching using the unittest library, which reduce dependencies and turn complex tests to simple ones; to looking at all types of testing: simple unit tests to large system tests and even customer acceptance tests.

The Testing Pyramid

The Testing Pyramid says you should have a lot of unit tests, slightly fewer integration tests, even fewer system tests, and as few acceptance tests as possible.

Throughout the course we work on this concept, making sure that we have full coverage of every component of our system with unit tests. Then we test the dependencies using integration tests. Finally, we cover the entire system and its assumptions using system tests. Of course, we'll also look at what acceptance testing is, how we come up with acceptance tests, and some of the best ways to write acceptance tests for a web application using Behavior-Driven Development and Selenium WebDriver.

Automated Browser Testing with Selenium WebDriver

Selenium WebDriver is extremely powerful, particularly when coupled with the efficient and tried-and-tested approach recommended in this course. We'll design our acceptance tests professionally—just the way you'd do at a software testing job. We'll use page models, locators, and step definitions to structure the automated tests in a reusable way. The customers will be able to come up with acceptance tests that you can easily translate to code.

We'll also learn about implicit and explicit waits with Selenium WebDriver and Python, a key concept to speed up the runtime of your acceptance tests.

Continuous Integration

We also cover how you can take automated testing much further in your projects.

By implementing a Continuous Integration pipeline that runs your tests whenever you make any changes, you'll have much higher quality in your projects and not let any pesky bugs pass you by. We'll look at putting our projects in GitHub and liking the CI pipeline with them.

I'm really excited to guide you through this course!

Join me in this automated testing journey. I'll see you on the inside!

Who this course is for:

  • Advanced students who want to learn about testing their Python applications to build more complete solutions
  • Professionals wanting to learn more about automated software testing in their workplace
  • Automated software testers and software developers

Course content

11 sections • 148 lectures

How to take this course Preview 00:45

This short lecture welcomes you to the course and gives you a few suggestions on how to take the course. Short, but important!

A self-assessment Preview 00:14

This important lecture contains a self-assessment that you can take at the start of the course. It'll help you gauge how much Python you know, and how much of the Python refresher section you can skip.

Installing Python and PyCharm on Windows Preview 00:24

This short guide tells you how to go about installing Python and PyCharm on a Windows computer.

Installing Python and PyCharm on OS X Preview 00:20

This short guide tells you how to go about installing Python and PyCharm on a Mac computer.

Introduction to this section Preview 01:01

Welcome to the Python refresher section! In this video we give a brief introduction to this section.

Access the code for this section here Preview 00:24

This lecture has a link to all the Python code we'll write in this section. Use it to check your code as you write it, or to refresh your memory!

Variables in Python Preview 08:26

In this video we look at variables in Python—the most fundamental building block of the Python language.

Variables

Solution to coding exercise: Variables Preview 02:00

In this video we solve the previous coding exercise. Make sure to attempt the exercise yourself before watching this!

String formatting in Python Preview 06:26

Getting user input Preview 05:16

Writing our first Python app Preview 03:19

Lists, tuples, and sets Preview 06:31

In this video we look at collections in Python: lists, tuples, and sets. These allow us to store multiple values in the same variable.

Advanced set operations Preview 04:39

Lists, tuples, and sets

Solution to coding exercise: lists, tuples, sets Preview 04:40

Booleans in Python Preview 04:59

If statements Preview 08:17

The 'in' keyword in Python Preview 02:02

If statements with the 'in' keyword Preview 08:18

Loops in Python Preview 11:07

Flow control—loops and ifs

Solution to coding exercise: flow control Preview 03:08

List comprehensions in Python Preview 07:24

Dictionaries Preview 08:31

Destructuring variables Preview 08:28

Functions in Python Preview 10:41

In this video we look at methods in Python, which are names for blocks of code. We can then re-use them over and over again without having to re-write the code again.

Function arguments and parameters Preview 07:40

Default parameter values Preview 03:54

Functions returning values Preview 07:19

Functions

Solution to coding exercise: Functions Preview 02:30

In this video we solve the previous coding exercise. Make sure to attempt the exercise yourself before watching this!

Lambda functions in Python Preview 07:52

Dictionary comprehensions Preview 04:01

Dictionaries and students

Solution to coding exercise: dictionaries Preview 06:16

Unpacking arguments Preview 10:24

Unpacking keyword arguments Preview 08:44

Object-Oriented Programming in Python Preview 15:52

Magic methods: __str__ and __repr__ Preview 06:25

Classes and objects

Solution to coding exercise: classes and objects Preview 05:04

@classmethod and @staticmethod Preview 14:03

@classmethod and @staticmethod

Solution to coding exercise: @classmethod and @staticmethod Preview 05:54

Class inheritance Preview 08:32

Class composition Preview 06:08

Type hinting in Python 3.5+ Preview 05:08

Imports in Python Preview 09:33

Relative imports in Python Preview 08:52

Errors in Python Preview 12:47

Custom error classes Preview 05:04

First-class functions Preview 07:52

Simple decorators in Python Preview 07:12

The 'at' syntax for decorators Preview 03:33

Decorating functions with parameters Preview 02:24

Decorators with parameters Preview 04:50

Mutability in Python Preview 06:03

Mutable default parameters (and why they're a bad idea) Preview 04:27

Conclusion of this section Preview 00:37

Introduction to this section Preview 00:24

Access the code for this section here Preview 00:25

Setting up our project Preview 06:42

Writing our first test Preview 11:09

Testing dictionary equivalence Preview 05:25

Writing blog tests and PyCharm run configurations Preview 06:43

The __repr__ method, and intro to TDD Preview 08:48

Integration tests and finishing the blog Preview 11:57

Mocking, patching, and system tests Preview 16:37

Patching the input method and returning values Preview 07:29

Taking our patching further Preview 16:03

The last few patches! Preview 07:07

The TestCase setUp method Preview 04:36

Conclusion of this section Preview 00:27

Introduction to this section Preview 00:26

Access the code for this section here Preview 00:25

Setting our project up Preview 04:38

In this video we set up our Flask project so we can start writing System tests for it. We quickly go over setting up the project structure and installing required libraries.

Creating our Flask app Preview 06:50

In this video we create our Flask app and go over its different parts. A quick overview of Flask and how we'll be testing our very first endpoint!

Our first System test Preview 09:56

In this video we write our first system test, testing the app from end to end—as if we were a user.

System testing is extremely powerful and useful when testing web applications, but it can be dangerous and slow if overused.

Refactoring our System Tests Preview 06:32

In this video we look at refactoring our System tests so that our code is nicer and easier to maintain. Throughout the rest of the course we'll be writing tests in this refactored fashion.

Conclusion of this section Preview 00:33

Introduction to this section Preview 00:35

Access the code for this section here Preview 00:30

A look at a REST API with Flask Preview 18:18

Unit testing a REST API Preview 08:15

Setting up our generic BaseTest Preview 09:36

Integration testing a REST API Preview 06:47

Conclusion of this section Preview 00:25

Introduction to this section Preview 00:20

Access the code for this section here Preview 00:30

Setting up our project Preview 08:45

In this video we look at our more complex REST API with Flask, and explain how it has evolved since the last section. We add Stores and relationships between our various models with SQLAlchemy.

Testing foreign key constraints with Python Preview 05:25

In this video we look at testing foreign key constraints with Python, which is extremely useful when our applications rely on relational data.

Unit testing models and SQLAlchemy mappers Preview 11:03

In this video we look at unit testing a more complex REST API, and how the SQLAlchemy mappers work in a Python application. Avoid some common mistakes!

Finishing our Store tests Preview 11:38

In this video we finish our tests for the Store, and complete the testing of our more complex REST API with Python.

Conclusion of this section Preview 00:24

Introduction to this section Preview 00:28

Access the code for this section here Preview 00:26

Setting project up and creating User model Preview 03:58

Allowing users to log in Preview 04:10

Writing our User tests Preview 04:14

The setUpClass method in the BaseTest Preview 04:59

Testing user registration Preview 06:41

Finalising user System tests Preview 07:31

Writing Store System tests Preview 13:35

Writing our Item System tests and testing authentication Preview 22:35

Conclusion of this section Preview 00:26

Introduction to this section Preview 00:40

Access the code and Postman files here Preview 00:22

Introduction to Postman Preview 09:01

In this video we look at Postman, a great tool we can use to send requests to our API and make some checks and tests on the response.

Our first Posman tests Preview 05:50

In this video we write our first Postman test. These tests are written in JavaScript, but they are straightforward and very powerful.

Setting and clearing environment variables in Postman Preview 07:04

In this video we look at the power of environment variables in Postman to share data across requests and responses. Setting and clearing environment variables programmatically will make our tests much more capable.

Running a test folder in Postman Preview 07:53

In this video we look at running a sequence of tests in Postman. This lets us define a set of requests that make up a User journey, and run the tests pretending to be the user themselves.

Advanced PyCharm run configurations Preview 06:08

In this video we look at advanced PyCharm run configurations and plugins, which are going to let us run our Postman tests directly from PyCharm.

Installing Node and Newman Preview 04:43

In this video we look at installing Node and Newman on OS X. We'll need this to run our tests through the console (and thus through PyCharm). Instructions are also available for Windows on a lecture attachment.

Multirun in PyCharm—Running app and tests together Preview 03:01

In this video we look at running multiple PyCharm run configurations one after another. Since our tests depend on our app being running, we must be able to run the app first and the tests after—in one click.

Conclusion of this section Preview 00:36

Introduction to this section Preview 00:38

The code for this section Preview 00:13

Installing Git Preview 04:12

In this video we look at installing Git in both OS X and Windows. Git is extremely powerful for teamwork, error control, and keeping a history of what's changed in a project.

What is a Git repository? Preview 05:27

In this video we look at what a Git repository is, exactly. This video guides you through the different layers of a repository and what each one does.

A local Git workflow Preview 04:31

In this video we look at a sample Git workflow that we may follow locally.

GitHub and remote repositories Preview 05:17

In this video we look at GitHub, one of the popular repository-hosting sites. We also look at remote repositories, which are hosted in GitHub.

Adding our project to GitHub Preview 04:51

In this video we look at adding our Flask REST API project to GitHub, so that we can then run our tests on the remote repository.

What is Travis CI? Preview 02:29

In this video we look at our Continuous Integration pipeline, Travis CI. It's going to look at our remote repository whenever a commit is pushed, and run our tests on the latest code available.

Adding our repository to Travis Preview 01:38

In this video we look at how we can add our GitHub repository to Travis so that it knows about it and can start looking at the code.

The Travis config file and running tests Preview 10:33

In this video we look at the Travis configuration file—we need it so Travis knows what language to run, and how to run the tests. It's really quite powerful!

Adding our test badge to the Readme Preview 02:47

In this video we look at adding our "Tests Passing" badge to the Readme of our repository. This not only gives readers some information about our project, but also some software engineering kudos by making the fact that we have tests visible.

Conclusion of this section Preview 00:38

Introduction to this section Preview 00:40

Welcome to this section on acceptance testing! Acceptance testing is a very exciting form of testing that encourages customers to write the tests.

Using Behavior-Driven Development (BDD), we can easily model our tests after what customers say. Learn all about it in this section!

What is acceptance testing? Preview 05:08

What is acceptance testing? How do we create acceptance tests? Why do we want to do acceptance tests?

Introduction to our project Preview 03:10

In this section I provide a simple website that we'll test using acceptance testing methods and BDD. This lecture is a guide over what the website does and how it works.

Our first acceptance test step Preview 10:46

In this video we write our first acceptance test step, using Gherkin and Selenium.

Getting the Chrome webdriver Preview 03:38

This video quickly walks you through getting the Chrome webdriver (remember to update your version of Chrome!), and how we can use it from Selenium.

Verifying everything works Preview 05:44

Make sure everything works—if Selenium isn't running, your tests won't run! This video walks us through any fixes we might have to do.

Finishing our first test Preview 14:51

In this video we finish writing our first test using Selenium, which contains navigation and checking the current page URL.

Re-using steps with the regular expression matcher Preview 04:00

In this video we learn about the regular expression matcher in the behave library, which allows us to pass in arguments through the Gherkin steps.

Our first content test Preview 09:18

In this video we write our first test to check some content of an element!

Page locators and models Preview 18:36

This is arguably the most important video—structuring your acceptance tests so that you and your teammates can work efficiently, by splitting them into separate locators and a page model which represents the pages in your application.

The blog page Preview 07:30

In this video we create a page in our page model to represent our blog page.

Using pages in navigation Preview 06:45

In this video we change all our hard-coded navigation into the specific pages, to make tests more readable and less interdependent.

Don't over-generalise tests! Preview 02:25

Just a word of warning in this video! You will not have too many acceptance tests, so don't worry about making everything as efficient and generalised as possible. Often, that will result in poor readability and maintainability.

It's okay to have a small amount of duplication in the pursuit of better maintainability in the long term!

Waits and timeouts with Selenium Preview 07:33

Often, acceptance tests will be slow—be it due to internet speed or JavaScript doing things. Often these tests will include waits, in order to give time for things to load. It's a very bad practice to have explicit waits (such as '5 seconds').

Instead, this video covers implicit waits: waiting for something to happen. As soon as it happens, the test moves on—not wasting any precious time.

Debugging acceptance tests in PyCharm Preview 03:32

In this video we look at how we can debug acceptance tests with PyCharm. It's simple, just as you would any other test!

Our final complex scenario Preview 02:46

In this video we look into our final complex scenario, which will have our Chrome webdriver filling in a form and checking that content is created accordingly.

Filling in forms with Selenium Preview 13:01

Filling in forms with Selenium is really simple, especially when we've structured our page using locators and a page model. Learn how to in this video.

Access the final code of this section here Preview 00:07

Conclusion of this section Preview 00:41

This video concludes this section, and the course!

Bonus lecture: other courses and next steps Preview 00:47

Some extra learning resources, materials, and courses that you can take. Includes some bonus offers!