Code Monkey home page Code Monkey logo

tau-pytest-bdd's Introduction

tau-pytest-bdd

This repository contains example code for the Behavior-Driven Python with pytest-bdd course from Test Automation University. There is a branch for each chapter of the course showing the state of the code at the completion of the chapter.

Repository Purpose

The best way to learn pytest is through hands-on coding. In the first lesson of the course, you will create a new Python project for test cases. (That project will not be the same as this repository.) Each chapter then introduces new concepts and provides coding instructions for your project. If you code along with each chapter, then you will have a complete, functioning test automation project by the end of the course.

This repository provides all example code for the project. If you get stuck while building your own project, compare your code to the example code in this repository. However, try to avoid blindly copying code from the repository into your project. Take the time to learn the concepts and code presented in each chapter.

Repository Branches

  • Each chapter/* branch contains the state of the code for each chapter
  • The main branch contains the final state of the code at the end of the course

Python Setup

Python setup can be complicated. This section documents how to set up your machine for Python test automation development.

Python Installation and Tools

You can complete this course using any OS: Windows, macOS, Linux, etc.

This course requires Python 3. You can download the latest Python version from Python.org. Follow the appropriate installation instructions for your operating system.

You should have basic Python programming skills before attempting this course. Learning the language is always a prerequisite for learning automation. If you need help learning Python, check out this article: How Do I Start Learning Python?

You should also have a good Python editor/IDE. Good choices include PyCharm and Visual Studio Code.

You will also need Git if you want to clone this repository locally. If you are new to Git, try learning the basics.

For Web UI tests, install the appropriate browser and WebDriver executable. These tests use Firefox and geckodriver.

Python Installation Troubleshooting

Unfortunately, installing Python properly can be complicated, especially if Python was previously installed on your machine. To verify your Python installation, enter python --version at the command line. You should see the proper version printed.

If the python command doesn't work or doesn’t print the expected version number, then try using the python3 command instead. If that still doesn't work, then the correct Python installation might not be included in your system path. Find the directory into which Python was installed, manually add it to the system path, relaunch the command line, and try running Python again.

Python Packages

This course will use a handful of third-party packages that are not part of the Python Standard Library. They must be installed separately using pip, the standard Python package installer. You can install them all before you create your test project, or you can install them as you complete each chapter in the course.

To install each package, enter pip install <package-name> at the command line. For example: pip install pytest. If you already have a package installed but need to upgrade its version, run pip install --upgrade <package-name>.

Please note that if you need to use the python3 command to run Python, then you might also need to use the pip3 command in lieu of pip.

Virtual Environments

Running pip install will install the pytest package globally for the whole system. Installing Python packages globally is okay for this course, but it typically isn't a best practice in the "read world." Instead, each project should manage its own dependencies locally using a virtual environment. Virtual environments let projects avoid unnecessary dependencies and version mismatches.

For simplicity, this course will not use or teach virtual environments. If you would like to learn virtual environments on your own, then RealPython's article Python Virtual Environments: A Primer is an excellent place to start.

Package Versions

The requirements.txt file contains the versions for each package used in this course.

Running Tests

To run the example tests from the command line, run python -m pytest from the project root directory. This command will discover and run all tests in the project.

You can also run tests using the shorter pytest command. However, I recommend always using the lengthier python -m pytest command. The lengthier command automatically adds the current directory to sys.path so that all modules in the project can be discovered.

The pytest command has several command line options. Course material will cover many of them. Check out the Usage and Invocations page for complete documentation.

Warning: If you attempt to run tests from this example project, make sure to checkout the correct branch first!

Additional Resources

Python links:

Books:

Related TAU courses:

About the Author

This course was written and delivered by Andrew Knight (aka Pandy), the "Automation Panda". Andy is a Pythonista who specializes in testing and automation.

tau-pytest-bdd's People

Contributors

andylpk247 avatar automationpanda avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tau-pytest-bdd's Issues

target_fixture now has to be explicitly defined

In the first example of 'given' there is no reference to target_fixture. In modern versions of pytest-bdd you have to state this:

@given("the basket has 2 cucumbers", target_fixture='basket')
def basket():
    return CucumberBasket(initial_count=2)

In the above example, without the target_fixture='basket', the test will fail saying that basket is not defined. Basically given decorators no longer automatically produce fixtures without specifically stating their name using the target.

It's a bit annoying to make the changes and I realise your guides, repos were based on a previous version, but seeing as you're basically THE go to resource on the internet for pytest-bdd learning, it would be very helpful for new learners, if you updated.

I don't want to do a PR because you have video content referencing the original syntax etc.

(BTW, thanks for the great content.)

target_fixture='basket' doesn't seem to be working when introducing parametrize.

In Chapter 4 - Parametrizing Steps I seem to be having issues incorporating target_fixture='basket' to work alongside the changes.

Unsure if this is an issue, or because I am a total newbie and not quite grasped things all that well as yet.
I did have this working in the Chapter 3 Tutorials.

I am essentially stuck at 4 Mins 36 Seconds where you run the tests for the first time, are you able to confirm if this is an issue, or i am doing things incorrectly in the @given step.

Some variations I have tried:
@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers', extra_types=dict(Number=int), target_fixture='basket')) def basket(initial): return CucumberBasket(initial_count=initial)

@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers', target_fixture='basket' extra_types=dict(Number=int))) def basket(initial): return CucumberBasket(initial_count=initial)

After watching further into the video things change a bit, but the same doesn't seemingly work either
@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers', target_fixture='basket', extra_types=EXTRA_TYPES)) def basket(initial): return CucumberBasket(initial_count=initial)

@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers', extra_types=EXTRA_TYPES, target_fixture='basket')) def basket(initial): return CucumberBasket(initial_count=initial)

Hi sir

Can you guide me to do this project...

Unable to run chapter 6 on Python 3.10 installed

When running rest API tests from chapter 6 there is an error that all tests are failed due to the second argument "example_converters" can't be found in scenarios function.
The same problem appears when completing this chapter by myself on my own training repo.
Error output log is attached.
Reproduced on:
Arch Linux
Python 3.10
pytest 7.1.2
pytest-bdd 6.0.1.
VSCode Insiders version 1.65.
error_output.log

TAU - Behavior Driven Python with pytest-bdd - Ch.7 - images

Hi Andrew,

I do not know if it is already mentioned but in TAU - Behavior Driven Python with pytest-bdd (https://testautomationu.applitools.com/behavior-driven-python-with-pytest-bdd/chapter7.html#test-web-steps-py) I see that the definition of files with the releated images in Transcripted Summary, Chapter 7, "test_web_steps.py" comes with the screenshot of "web.feature" and "web.feature" with the one of "test_web_steps.py". Please check.
issue_screenshot_2
issue_screenshot_1

Hope this is the right way to declare this issue. ( I am new in this :-) )

Best Regards,
Nikos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.