Like many things in life, the toughest part of a test automation project can be getting started. That's why the Solution Architects and Information Developers are working hard to produce good materials for anyone getting started with test automation and Sauce Labs.
To help this effort, we've reworked some Python example code, which can be found in the Sauce Labs Training Demo Python repository. This project contains:
Onboarding modules for training novice users new to Python and Sauce Labs, and
Appium and Selenium samples for experienced users who want to see how to connect to Sauce Labs in a mainstream Python test tool.
Code in the Appium-Examples and Selenium-Examples in particular has been revamped to provide concise, helpful pieces of code for how to start using Sauce Labs virtual devices (desktop browsers and emulator/simulators) and real devices. We chose to provide examples using two Python tools: Pytest and Robot Framework.
While both of these tools are popular, we carefully chose these tools for specific reasons that we think are beneficial to Sauce Python users.
Overall, Pytest is the most widely used testing tool in the Python community. It is also one of the most active testing projects in the Python world, with contributions from major organizations such as Mozilla. Based on this, Pytest is our preferred choice of test tooling with Python today.
Pytest also provides both test writing utilities for writing and organizing test code and a command-line test runner for executing test code. Providing the test runner separately from test writing is actually a superpower of Pytest. This allows Pytest to become a drop-in replacement for other test tools. If you’ve previously written Selenium- or Appium-based tests with the test tool Nose for example, you can use Pytest to execute those tests with little to no changes in your test code. Since the Nose project is now dead, previously written Nose test code can be migrated to the very much alive Pytest project without a lot of overhead to get started. The same approach can be used to migrate to Pytest from tests written with unittest. Instead of a daunting re-write, Pytest allows older test frameworks to be migrated carefully over time, which is a big win for test maintenance and long-term success.
While Pytest is an excellent tool, another popular testing tool in the Python community is Robot Framework. This is a keyword-based tool which allows tests to be written in a English language format for collaboration with non-developers. To implement the test logic, keywords can be developed in either Python code or using a keyword library that contains defined keywords for executing common tasks. There are several keyword libraries to choose from, including Selenium and Appium libraries. Robot Framework also provides reporting by default in the form of XML and HTML files which can be shared or posted for cross-team communication.
Robot is growing in popularity, particularly with working with Appium, which is a main reason why we decided to include samples of it here. And crucially, while Pytest has integration with several other Python test tools, it does not integrate with Robot.
Overall, Python is a great choice for any team starting a test automation project. Python is relatively easy to learn and has the resources to build a sustainable project. Sauce Labs loves Python, and your team might love it too!