In a previous blog post, you have seen how to get started with the brand new TestProject Python SDK and add the power of the TestProject platform to your existing Selenium-based tests.
As of version 0.63.13, the Python SDK can also be used with your Appium-based tests. In this blog post, you’ll see exactly how to do that.
🐍 Watch this awesome webinar recording to get started with the TestProject Python OpenSDK! 🐍
The SDK supports both mobile web and native app tests, for Android as well as for iOS. We’re going to take a look at two examples:
- A mobile web test on Android and Chrome, using an emulator
- A native iOS app test, using a real device
Table of Contents
- Getting Started with TestProject Python SDK
- You’re here →Creating Mobile Appium Tests with TestProject Python SDK
- HTML Test Reports for Selenium & Appium Python Test Automation
Running mobile web tests on Android using an emulator
I’m going to assume that you have already downloaded the Python SDK, have configured your Agent and developer token, and that your Agent is running. If not, you can read how to do that in this blog post. Also, I’m going to assume that you already have created and started an emulator running Android.
Let’s take this test as an example:
import pytest from appium import webdriver from tests.pageobjects.web import LoginPage, ProfilePage @pytest.fixture def driver(): desired_capabilities = { "udid": "emulator-5554", "browserName": "chrome", "platformName": "Android", } driver = webdriver.Remote(desired_capabilities=desired_capabilities) yield driver driver.quit() def test_example_on_chrome_on_android(driver): LoginPage(driver).open().login_as("John Smith", "12345") profile_page = ProfilePage(driver) profile_page.update_profile( "United States", "Street name and number", "[email protected]", "+1 555 555 55", ) assert profile_page.saved_message_is_displayed() is True
As you can see from the defined desired_capabilities
, this test runs on an emulator with name emulator-5554
, which runs Android. Specifying a browser name, i.e., chrome
, indicates that we’re running a mobile web test.
To turn this Appium test into a TestProject-powered test, similar to Selenium-based tests, all you need to do is change this import statement:
from appium import webdriver
to
from src.testproject.sdk.drivers import webdriver
and you’re good to go. Plus: you don’t need to run your own Appium server anymore, as the TestProject Agent acts as an Appium server for you!
When you run this test, it will start a Chrome browser on your Android emulator and run the test:
When the test has finished executing, the SDK sends reports to the Agent, which will, in turn, create a new test report on the TestProject platform:
Running native app tests on iOS using a real device
As you’ve read earlier, the TestProject Python SDK supports both Android and iOS. Let’s take a look at an example test that tests a native iOS app running on a real iPhone:
import pytest from src.testproject.sdk.drivers import webdriver from tests.pageobjects.android import LoginPage, ProfilePage @pytest.fixture def driver(): desired_capabilities = { "udid": "<my_device_udid_here>", "deviceName": "iPhone van Bas", "browserName": "", "platformName": "iOS", "bundleId": "io.testproject.Demo", } driver = webdriver.Remote(desired_capabilities=desired_capabilities) yield driver driver.close_app() driver.quit() def test_example_on_native_ios_app(driver): LoginPage(driver).login_as("John Smith", "12345") profile_page = ProfilePage(driver) profile_page.update_profile( "United States", "Street name and number", "[email protected]", "+1 555 555 55", ) assert profile_page.saved_message_is_displayed() is True
There’s no browser specified in the desired_capabilities
, which means that this test is running against a native app. Here’s a screenshot from the actual iOS device used, taken during test execution:
❗ Interesting fact: the iOS device used here was connected to a Windows machine! TestProject enables you to run tests on iOS devices without the need for running macOS or XCode, and without having to run an Appium server yourself.
This test, too, passes, as we can see in the reports that are sent to TestProject:
As you can see, using the TestProject Python SDK (or the Java or C# SDK), you can easily transform your existing Appium-based tests to TestProject-powered tests, no matter if they are for Android or iOS, using an emulator or a real device, testing mobile web or a native app, on macOS, Linux and Windows.
Share your experience in the comments below. Happy PyTesting! 🐍
most awaited 🙂
Hello, I know this is extremely stupid to ask, but can you also include basic/ideal file structure and basic commands to create android/iOS tests from scratch? I know that there is a great collection of documents and with avg developers, it is easy to set up. but I am trying mobile app automation for the first time. and the language I am familiar with is ruby-selenium/watir. thanks in advance, love your works.