Integrating Tauk into your Appium Python tests
Tauk enables developers and test engineers to track, resolve, and optimize their automation tests. Using Tauk, you can more effectively catch user experience issues before releasing app changes. In my previous blog post, I discussed the basics of integrating Tauk with an Appium TypeScript project, structured using a Behavior Driven Development (BDD) style test framework. This time I will focus on using the Tauk Python package to showcase the integration process from a different test environment. Specifically, I will demonstrate integration with an Appium Python test suite structured using theunittest
framework.
Update (May 9, 2022): We recently updated our Python package to version 2.X. In this new update we’ve added a convenience unittest listener and multiprocess support. To learn how to use and integrate with the package, please checkout our GitHub:
https://github.com/thetauk/tauk-webdriver-python
Requirements
The Tauk package is simple to install and straightforward to use. Using pip
, you can install it in your Python environment.
This command will download the latest version of the tauk
package (v1.0.7 at time of writing) for Python and allow you to integrate your suite with the Tauk platform.
In this example, since I’m starting a new project, I will also download the Appium Python Client. If you’re new to using Appium or Selenium, please check out our previous blog posts to help you get started.
To allow the package to detect your test runs and integrate them with the Web UI, you will need to do the following:
- Import the
tauk
package in your test - Initialize the package with the
driver
,API_TOKEN
andPROJECT_ID
that you want the test run to be associated with - Decorate the test case with
@Tauk.observe
decorator to mark its beginning and end - Upload the test data after quitting the driver using
Tauk.upload()
Importing the tauk
package
To import the Tauk package, you can add this import statement to your test case.
Initialize the package with the driver
After your test has initialized the WebDriver driver object, you’re ready to initialize the Tauk class that was imported in the previous step. There’s just two additional bits of information we’ll need: an API Token and Project ID. You can generate an API_TOKEN
on the Tauk Web UI from the User Settings page. Under the API Access tab, you can either generate a new token or click on the Show button to reveal your previous token.
If you don’t have access to Tauk Web UI, we currently have an ongoing beta program for users to try it and if you want an invitation you can join the waitlist here. Just click on “Request an Invite.”
Lastly, you can go to the Tauk dashboard, and grab the PROJECT_ID
from the corresponding project card. The Tauk PROJECT_ID
is a unique string that you can associated your tests executions to. For example, if you want the test runs to be associated with the “Espresso Tests” Project in the below screenshot, you would copy the 9 character string from its project card, which would be: q9OSPWkdQ.
Once you have the API_TOKEN
and the PROJECT_ID
, you can go ahead and initialize Tauk using the Tauk.initialize()
method.
NOTE: It is important that your driver object is created before this step.
Decorate the test case with @Tauk.observe
For the test cases you want observe, add the @Tauk.observe
decorator above your test case methods.
NOTE: It is vital to initialize to have already initialized the Tauk class. If for some reason, the API_TOKEN or PROJECT_ID is invalid, or the initialization fails, the observe step will be ignored.
Upload the test data
Finally, after you have initialized and observed test runs, you can go ahead and share the data with the Web UI using the Tauk.upload()
method.
Writing a sample test suite using Python
At this point, we understand how to use the package and the basic setup. This gives us the ability to integrate the Tauk package with a Python unit testing framework. To illustrate this, we will now write a simple test suite using unittest
and integrate it with Tauk.
Let’s go ahead and breakdown the above code into smaller pieces:
- We import
Tauk
alongside the necessary appium packages and unittest package in the top. - We extend the
unittest.TestCase
object within our custom test case type. Extending this object gives you the capability to use thesetUp()
andtearDown()
hooks. - Within the
setUp()
hook, we call thepre_launch()
method to execute any setup conditions listed within the test case. - This is followed by driver creation using the
Remote()
method exported by theAppium-Python-Client
package. Once the driver creation is completed, we initialize Tauk withTauk.initialize()
. - Finally, in the
tearDown()
hook, we quit the driver and upload the data to Tauk usingTauk.upload()
.
The key points to look out for are: importing Tauk, initializing it and then uploading test data to the Web UI. If you have any questions, you can reach out to us on our Discord server or comment below.
Discussing interesting topics in automation testing is precisely why we created our Discord server! If you find this blog post helpful, or learned something new, consider joining our community today 👋:
After we have setup a basic test skeleton, we will go ahead and write one simple test case.
The main thing to look out for here is the Tauk decorator. In the unittest
framework, we have test cases which always begin with the test_
prefix in their method name. We’ll add the Tauk decorator above the test methods we define. If you are using any other decorators, you can go ahead and add them in the line between the @Tauk.observe
statement and the function definition. At this point you are ready to run your test suite! After you run your test suite a report should have been generated within the Web UI, under the Project view. This will be the same project whose PROJECT_ID
was passed in the initialize step. If you want to learn more about the Tauk Web UI, you can go ahead and read this post detailing some of the key features.
Conclusion
This quick guide illustrated how to integrate your Python unit test suite with Tauk. If you want to learn how to do the same for other environments, you can go and read the associated package documentation from your Tauk account. In a future blog post, I will illustrate how Android Espresso tests can be linked with Tauk. 📲
If you are excited about keeping up with new developments at Tauk or want to learn about best practices for test automation, you should join our Discord server and join the beta program waitlist here!