Appium with Python: Getting Started with App Automation Testing
On This Page Getting Started with App Testing in Appium Python using Appium-P
Appium with Python: Getting Started with App Automation Testing
Appium is a knock-down open-source instrument for of mobile coating. It supports both. When paired with Python, a versatile and popular programming language, Appium becomes an even more efficient solvent for developers and testers seeking to streamline their testing workflow.
By integrating with BrowserStack App Automate, users can execute tests on real Android device, further enhancing the testing process. This combination allows users to write clear, concise test scripts, harnessing the full potential of Appium ’ s capabilities while leveraging Python ’ s simplicity and the robust features of BrowserStack ’ s cloud-based program.
This article explores getting started with app testing in Appium utilise the Appium-Python-Client and demonstrates how to use Python effectively with Appium. It likewise covers leverage to accomplish examination on existent Android devices.
Getting Started with App Testing in Appium Python utilise Appium-Python-Client
Consider testing the Android app & # 8220; Notes & # 8221; using Appium Python as an example. Testing on real Android devices can be attain by integrate Appium Python trial with BrowserStack App Automate.
How to use Python with Appium?
Follow the Pre-requisite stairs below and downloadAppium Python Clientto use Python with Appium. Once you postdate the below pre-requisite you cando mobile mechanization habituate Appium.
Prerequisites
- Install Python3
- Download the Appium Python guest. Using the pip packet installer would be the most efficient method for this. Simply use the following command:
pip install Appium-Python-Client
- Download Appium Inspectorfor your OS. Previously this was included with the; however, it must now be downloaded severally.
- Download gitfor your OS.
Here are the steps to run your inaugural Appium test using Python & # 8211;
Step 1: Create a and use the free trial, which offers 100 minutes of complimentary automated mobile app testing.
Step 2: For this example, the miui notes apk file (variation 2.3.7) was utilise. The apk file of the app be tested needs to be uploaded to BrowserStack.
The apk file of the app can be uploaded either via the or.
Step 3: Once the app is successfully uploaded, the exploiter will be render with an app_URL which needs to be noted and expend later to set our desired capacity.
Step 4: Open git bash at your desired location and use the following command:
git ringer https: //github.com/BrowserStack/python-appium-app-BrowserStack
This command clones the sample python repository render by BrowserStack and provides an exemplar python code snipping that can be directly edited.
Step 5: Navigate to the android leaflet in the monument and open the BrowserStack_sample.py file.
Step 6: First, import the necessary packages.
from appium import webdriver from appium.webdriver.common.appiumby import AppiumBy import time
Webdriver needs to be imported because speaks the same protocol as, the WebDriver protocol. Following this,AppiumBywill be spell as well since it will be employ afterwards in the programme to locate factor. Time postulate to be imported next in order to execute bid after the app has loaded.
Step 7: Desired capabilities need to be set next. They are key-value pairs encoded into a JSON object. These will be sent by Appium Clients to the server and ply info to it on how you want your test to work.
desired_cap = {# Set your access credentials '' browserstack.user '': “ YOUR_BROWSERSTACK_USERNAME ”, '' browserstack.key '': “ YOUR_BROWSERSTACK_ACCESS_KEY ”, # Use the unequalled URL to specify the app to be downloaded '' app '': `` bs: //ca0b82b855ca2c5157b2b3d36fad5b392b723fbd '', # Provide device specifications '' twist '': `` Xiaomi Redmi Note 8 '', '' os_version '': `` 9.0 '', # grant permissions mechanically and take any pop up alerts '' autoGrantPermissions '': '' true '', '' autoAcceptAlerts '': '' true '', # Specify the project, build, and gens '' labor '': `` Test Python project '', '' build '': `` BrowserStack-build-1 '', '' name '': `` notes_app_test ''}SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
So hither, the exploiter want to provide access credentials and the unique URL supply earlier when theapk filewas uploaded.
Simply click on Access Key in the toolbar at the top of the screen upon lumber into BrowserStack to obtain the user and key values.
Following this, device specifications take to be furnish, and permissions need to be auto grant for any permission or alert pop-ups that may interpose with the test mechanization. For this example, the gimmick specified was Xiaomi Redmi Note 8, and the OS was Android 9.0.
Finally, the project, build, and gens can be specified. Utilize the for ease of use.
Read More:
Step 8: Initialize the WebDriver.
driver = webdriver.Remote (command_executor= '' http: //hub-cloud.BrowserStack.com/wd/hub '', desired_capabilities=desired_cap)
Use the BrowserStack remote URL and the defined desired potentiality to initialise the WebDriver.
Step 9:Find and use locators to navigate and automatise the app in order to test its functionality. Refer to the next section of this guide: “ How to use Appium Inspector to find Element Locators ” for an example of how to use Appium Inspector to find locators for elements.
time.sleep (5) el_createnote = driver.find_element (AppiumBy.ACCESSIBILITY_ID, 'Tap to make a text line. Press and hold to make a voice billet. Release the push to kibosh recording and create the note, or skid up to cancel. ') el_createnote.click () el_notetitle = driver.find_element (AppiumBy.ID, 'com.miui.notes: id/note_title ') el_notetitle.click () el_notetitle.send_keys (`` Watch Later '') el_note = driver.find_element (AppiumBy.ID, 'com.miui.notes: id/rich_editor ') el_note.click () el_note.send_keys (`` Naruto '' + '' \n '' + '' WandaVision '' + '' \n '' + '' The Little Mermaid '') back=driver.find_element (AppiumBy.ID, 'com.miui.notes: id/home ') back.click () driver.quit ()
Give time for the app to initialize and consent any pop-ups. For this example, Accessibility ID and ID feature be used for locators. However, there are several other locators which can be apply.
Read More:
First, the code snipping apply the Accessibility ID of the “ + ” button to create a new tone. Following this, it clicks on the title bar, locating it by ID, and adds a title of “ Watch Later ” to it. It retell this process on the text body and enter a list of shows the user wants to note and watch later. After this, it go back to the home screen of the app, saving the note, and then disconnects from the remote BrowserStack URL.
Step 10:Open bid prompt or Linux shell from the location of the python file. Run the file employ the next command:
python3 BrowserStack_sample.py
Step 11:Navigate back to BrowserStack, and in App Automate underbrowserstack-build-1there will be a notes-app-test.
Clicking on this test will lead to the dashboard.
This window expose the user ’ s tryout results in a video format on the left. A log can be seen to the right of the blind; This shows a log of each case that took spot during the test automation.
Like what you are reading?
You can depart discourse with our discord community
How to use Appium Inspector to find Element Locators in Appium Python: Example
Appium Inspector is an Appium Client which allows the user to colligate to a bombastic variety of cloud Appium platforms. It further allows the user to take and interact with constituent, providing a list of element locator strategies, which can be used in their automation and testing scripts.
Step 1: Unfastened Appium Inspector and select BrowserStack from the cloud provider useable.
Enter your antecedently obtained Username and Access Key, as easily as the desired capabilities in JSON; Start the session.
Step 2: Locate the elements ask to automate and test the app. Note their XPath, IDs, or their accessibility IDs. These locator can be used to bump factor and test/automate an application in Appium with Python.
In the former subdivision “ Testing a Notes app by Integrating with BrowserStack: Example ” a new line was created by using the Accessibility ID locator to discover and click on this element; As demonstrated in the code snippet from the aforementioned example:
el_createnote = driver.find_element (AppiumBy.ACCESSIBILITY_ID, 'Tap to make a text tone. Press and hold to make a voice billet. Release the button to stop recording and make the line, or slew up to cancel. ') el_createnote.click ()
Similarly, other locators used in the example, such as the ID locater for the Title bar, were also found using Appium Inspector.
Test Results
As find in the picture, the tryout automation ran successfully with no errors, indicating that the app is fully functional.
The text logs and app profiling provided by BrowserStack give insight into how the test ran and allow the exploiter to optimize CPU and remembering usage, as well as unearth any errors or number with theapk.
Read More:
Conclusion
Combining Appium with Python provides a powerful, flexible approach to mobile app automation testing. By integrate these test with BrowserStack App Automate, teams can easily execute their test scripts on a blanket range of real Android device without needing an in-house device lab.
This apparatus improves test coverage and dependableness and speed the overall examination process, help teams deliver higher-quality applications faster. With the right instrument and setup, peregrine app testing becomes more scalable, efficient, and effective.
# Ask-and-Contributeabout this topic with our Discord community.
Related Guides
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free