Package: tauk
Tauk Python Package for WebDriver-based TestsThe Tauk Python Package allows you to easily report and monitor your Appium and Selenium automation tests on the Tauk platform.Installation$pipinstalltaukUsageImport the Tauk and TaukConfig classes from the package in your test suite.fromtauk.tauk_webdriverimportTaukfromtauk.configimportTaukConfigInitialize Tauk with your driver,API TOKEN, andPROJECT ID.You only have to initialize the Tauk class once for the entire execution.
You can retrieve yourAPI TOKENandPROJECT IDfrom the Tauk Web UI.
Your tokens can be generated and retrieved from theUser Settings > API Accesssection.
Each of your project cards will have their associated Project ID's in the#section.Tauk(TaukConfig(api_token="API-TOKEN",project_id="PROJECT-ID"))Additionally, if you are running tests in parallel and each test runs in a different process,
you should include themulti_process_run=Trueflag when initializing Tauk
so that it can tie multiple processes with the same execution.Tauk(TaukConfig(api_token="API-TOKEN",project_id="PROJECT-ID",multiprocess_run=True))Alternatively, you can also pass these argument inputs through environment variables instead of through theTaukConfigclass.
In your local environment, you can set the following variables:TAUK_API_TOKEN=YOUR-API-TOKENTAUK_PROJECT_ID=YOUR-PROJECT-ID# If you have a multiprocess runTAUK_MULTI_PROCESS=true# Useful if you running multiple instances of you project.# Tauk will automatically use the process ID to create the execution context,# but you can override this behavior and provide an explicit execution dir if neededTAUK_EXEC_DIR=/tmp/tauk/smoke_runsIf you're passing these inputs through environment variables,
you conveniently don't need to explicitly initialize the Tauk class in your code.
Instead, the Tauk class will check your environment variables on invocation.
In other words, if you have the inputs as environment variables you can just import Tauk.Decorate your individual test case methods with@Tauk.observe.Add the@Tauk.observedecorator above the test case methods you want Tauk to watch. For example:@Tauk.observe(custom_test_name='Add New Contact',excluded=False)deftest_Contacts_AddNewContact(self):print("Clicking on the [Add] Button")self.wait.until(expected_conditions.presence_of_element_located((MobileBy.ID,"com.android.contacts:id/floating_action_button"))).click()For WebDriver based tests Tauk can collect useful information such as the screenshot,
view hierarchy, etc. from the application. In order to support that you can simply register the driver instance
at the beginning of the test usingTauk.register_driver().deftest_Contacts_AddNewContact(self):print("Clicking on the [Add] Button")Tauk.register_driver(self.driver)self.wait.until(expected_conditions.presence_of_element_located((MobileBy.ID,"com.android.contacts:id/floating_action_button"))).click()Alternatively if the driver object is constructed in a base class (Ex: in thesetUp()method),
you also have to pass theselfobject asunittestcaseargument.
This will allow Tauk to collect details about the test.defsetUp(self)->None:self.driver=webdriver.Chrome()Tauk.register_driver(self.driver,unittestcase=self)For sample code, please take a look at thee2e/custom_integration_test.pytest case in thetestsdirectory of the repository.Tauk ListenersIf you are usingunittestfor structuring your tests, Tauk comes packaged with a test listener which can hook onto the test lifecycle and extract test information. When using a test listener you no longer have to decorate the test method withTauk.observe()You can use Tauk listener as follows:importunittestfromtauk.listeners.unittest_listenerimportTaukListenerif__name__=='__main__':...suite=unittest.TestSuite()suite.addTest(AndroidContactsTest('test_Contacts_AddNewContact'))unittest.TextTestRunner(resultclass=TaukListener).run(suite)...Excluding testsIf you want to exclude a test case from analysis you can pass in as an argumentexcluded=Truetoobserve()method. For example:@Tauk.observe(custom_test_name='Add New Contact',excluded=True)For tests written using unittest framework you can skip tauk reporting by setting an instance variable
either in the base class that extendsunittest.TestCaseor directly in the testcase that extendsunittest.TestCaseimportunittestclassTestDataTest(unittest.TestCase):tauk_skip=True...Installing and using the Tauk Assistant for Selenium TestsTo use the Tauk Assistant in conjunction with the Tauk Python Package, you will first need to install the binary. The Tauk Python Package provides a built-in module for making this simple and straightforward. Simply run:python-mtaukassistant-i-t<Your-API-Token>-iflag indicates that you would like to install-tflag is for you to provide your API TokenThis will download the Tauk Assistant binary to your.taukdirectory, which will be in~/.taukby default, unless you have specified a custom path.To use the Tauk Assistant as part of a test execution you can configure it in yourTaukConfig. You can specify the location of the Tauk Assistant binary from yourTaukConfigor provide it as an environment variable. If the Tauk Python Package does not find your Tauk Assistant binary in either of these two locations, it will check if the Tauk Assistant exists in yourPATH.Configuring the Tauk Assistant inTaukConfigconfig=TaukConfig(api_token="API-TOKEN",project_id="PROJECT-ID")config.assistant_config=AssistantConfig.default()# Providing the Tauk Assistant path in codeconfig.assistant_config.executable_path='/Users/example/.tauk/binaries/tauk-assistant'Tauk(config)The example above shows the default option, which at this moment of time will capture the Browser Logs (errorlevel), Exception Logs, and Console Logs (errorlevel). This can be customized with theAssistantConfig. For example, if you wanted to capture the Console Logs with anwarnlevel:config.capture_console_logs(True,log_level='warning')Providing the Tauk Assistant as an Environment VariableTAUK_ASSISTANT_EXECUTABLE=/Users/example/.tauk/binaries/tauk-assistant