Talking testing, automation... and anything else.



06
Nov 18

Selenium Testing in Python and Pytest

My experiences with Python have always been amicable (if not brief). It’s for just this reason that I’ve always wanted to try out Selenium Webdriver’s Python bindings. **SPOILER**: I did just that and you are now reading about it!

When learning a new language (or tool or job or…), I try and keep my opinions to myself. It’s funny how often something that seems weird/silly/stupid at first, will eventually have a reasonable explanation (except you, PYTHONPATH… I still think you’re pretty silly).

Pytest is a good example of this. Where other bindings generally offer a number of helper-frameworks that smooth out the rough bits, Python folks seem to embrace the vanilla bindings. This puzzled me a bit… until I discovered Pytest.

Pytest is a bit of a Swiss Army knife for Selenium testing in Python. It’s a test runner; uses fixtures to handle setup/teardown (and a ton more); handles test discovery; has detailed reporting; makes excuses for unwanted lipstick on your collar. It does most of the heavy lifting for tests.

Ultimately, I found Python’s concise syntax and explicit code conventions make it a great language for functional testing. I’ll cover more details in upcoming blog posts.

Take a peek at the code up on GitHub…