Discover How to Setup, Arrange, and Leverage the Most Impactful Features of TestProject Python SDK in this Detailed Guide:
Selenium and Appium have been esteemed open-source examination structures for computer interface and mobile examinations for numerous years.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
The TestProject Python SDK enhances these tools and offers seamless integration with the TestProject platform. It facilitates attractive HTML and PDF reports, auto detection of browsers, driver setup, and more.
The best feature is that both TestProject platform and SDK are absolutely free, perpetually. The SDK is also open-source, so you’re invited to contribute to the project if you wish.
What You Will Learn:
What is TestProject Python SDK?
This guide offers steps on getting started with TestProject Python SDK. It displays how to incorporate the SDK with existing Selenium and Appium examinations and utilize its dynamic features.
Note: If your examinations are written in a language different from Python, TestProject also provides SDKs for Java and C#, with support for more languages forthcoming.
Installation and Configuration
The TestProject Python SDK can be found on PyPI, the Python package index. Assuming you have a functioning Python installation, you can set up the SDK by executing the command below:
pip install testproject-python-sdk
This command will install the SDK and its requirements, encompassing Selenium and the Python Appium client.
Before utilizing the SDK, two additional steps are necessary.
#1) Download and arrange the TestProject Agent:
The TestProject Agent manages the setup of browser drivers and the transmission of reports created by the SDK to the TestProject platform.
After creating a complimentary account on the TestProject platform, you’ll be able to download the Agent.
After it’s downloaded, install and start the Agent. By default, the Agent operates on http://localhost:8585. If you require the Agent to operate on a disparate port or machine, specify the valid Agent address using the environment variable TP_AGENT_URL.
#2) Obtain and configure a developer token:
To interact with the Agent, a developer token is required. After installing the Agent, the developer token can be accessed from the TestProject platform site, as shown in the image below.
Configure the developer token using the environment variable TP_DEV_TOKEN or as a parameter when creating a new driver session.
Once you have installed the SDK, arranged the Agent and set up your developer token, you are prepared to proceed.
Creating Our First TestProject-Powered Selenium Test
Let’s propose we have a Selenium-based examination that navigates to the TestProject demo web app, inputs login credentials, and verifies successful login by inspecting the greetings element. The examination is constructed using the Pytest unit testing framework.
Here is an instance of such an examination:
from selenium import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome() driver.get('https://example.testproject.io/web/') driver.find_element_by_id('name').send_keys('John Smith') driver.find_element_by_id('password').send_keys('12345') driver.find_element_by_id('login').click() assert driver.find_element_by_id('greetings').is_displayed() is True driver.quit()
In this instance, Chrome is utilized as the browser. The TestProject SDK also backs Firefox, Edge, Internet Explorer, and Safari browsers.
Following finishing the installation and configuration steps above, you can transition this examination into a TestProject-fuelled examination by substituting the import statement with the following:
from src.testproject.sdk.drivers import webdriver
That’s it! When running the examination, the SDK will request a driver instance from the TestProject Agent and employ it to conduct the examination. It will also transmit reporting instructions to the TestProject platform for the formation of HTML reports. Let’s examine these reports.
Inspecting Reports on the TestProject Platform
Navigate to the TestProject platform and select the ‘Reports’ option from the menu to view the report fashioned for the examination. Refer to the following image for guidance.
The SDK autonomously assigns project, job, and examination names grounded on popular Python unit examination frameworks. If you want to implement custom names in your reports, this can be achieved in two ways.
#1) Implementing a decorator
The TestProject SDK includes a @report decorator that can be engaged to decorate examination methods and state custom project, job, and examination names. Here is a sample:
from src.testproject.sdk.drivers import webdriver from src.testproject.decorator import report @report(project="Software Testing Guidance", job="SDK Instances", test="Login Examination") def test_login_to_testproject_example_app(): driver = webdriver.Chrome() # rest of the examination method remains unchanged
The produced report will display the stated names rather than the instantly deduced ones.
#2) Specifying project and job names in the driver constructor and detailing an examination manually:
Alternatively, project and job names can be overriden by defining them in the driver object’s constructor. Here is a sample:
from src.testproject.sdk.drivers import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome(projectname='Software Testing Guidance', jobname='SDK Instances') # rest of the examination method remains unchanged
If you desire to override the instantly deduced examination name, you can detail the examination manually at the end of the test. Here is a sample:
from src.testproject.sdk.drivers import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome(projectname='Software Testing Guidance', jobname='SDK Instances') driver.get('https://example.testproject.io/web/') driver.find_element_by_id('name').send_keys('John Smith') driver.find_element_by_id('password').send_keys('12345') driver.find_element_by_id('login').click() assert driver.find_element_by_id('greetings').is_displayed() is True driver.report().test(name='Login Examination', passed=True) driver.quit()
If you prefer to employ manual reporting, you should deactivate automatic reporting of examinations to avoid redundant entries in the report. This can be accomplished by calling the subsequent method:
from src.testproject.sdk.drivers import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome() driver.report().disable_auto_test_reports(disabled=True) # rest of the examination method remains unchanged
This will generate a report resembling the one portrayed in the preceding screenshot.
#3) Disabling Reporting of Driver Commands
You can deactivate automatic reporting of individual driver commands during the examination by employing the following method:
from src.testproject.sdk.drivers import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome() driver.report().disable_command_reports(disabled=True) # rest of the examination method remains unchanged
You can re-activate driver command reporting later in your examinations by calling the exact method with the argument disabled=False.
Intermediate steps can still be reported manually during the examination using custom messages and screenshots. Here is a sample:
from src.testproject.sdk.drivers import webdriver def test_login_to_testproject_example_app(): driver = webdriver.Chrome() driver.report().disable_command_reports(disabled=True) driver.report().step(description="An intermediate step", message="A custom message", passed=True, screenshot=True) # rest of the examination method remains unchanged
Custom screenshots will be incorporated into the HTML report on the TestProject platform.
The TestProject SDK offers additional reporting customization selections. Refer to the formal documentation on the TestProject website, GitHub, or PyPI for further information.
Running Appium-based Examinations Using TestProject
Besides Selenium-based examinations, the TestProject SDK supports conducting examinations on mobile devices utilizing Appium. Here is a sample of running an examination against a native Android app on an emulator:
from appium import webdriver def test_native_android_app(): desired_capabilities = { "appActivity": "io.testproject.demo.MainActivity", "appPackage": "io.testproject.demo", "udid": "", "browserName": "", "platformName": "Android", } driver = webdriver.Remote(desired_capabilities=desired_capabilities) driver.find_element_by_id('name').send_keys('John Smith') driver.find_element_by_id('password').send_keys('12345') driver.find_element_by_id('login').click() assert driver.find_element_by_id('greetings').is_displayed() driver.quit()
To utilize the TestProject platform with Appium examinations, simply swap the import statement as follows:
from src.testproject.sdk.drivers import webdriver
The TestProject Agent functions as the Appium server, removing the need to operate it independently.
All the reporting characteristics detailed before are also available for Appium examinations.
The TestProject SDK backs:
- Android and iOS examinations
- Emulators and genuine devices
- Native apps and mobile interface browsers
Cases for each of these situations can be found in the SDK’s code repository on GitHub.
Conclusion
This guide has shown how TestProject Python SDK can improve current Selenium and Appium examinations by simplifying browser driver and Appium server setup, and by creating exhaustive HTML reports and dashboards on the TestProject platform.
The TestProject Python SDK is accessible completely free.
=> Visit TestProject to give it a try!
About the Author: Bas Dijkstra
The author is an independent educator, advisor, and developer based in the Netherlands. He instructs companies worldwide how to improve their testing endeavors through test automation. In his spare time, he enjoys cycling, running, and reading.