logo logo

Creating Mobile Appium Tests with TestProject Python SDK

main post image

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

  1. Getting Started with TestProject Python SDK
  2. You’re here →Creating Mobile Appium Tests with TestProject Python SDK
  3. 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:

TestProject Python SDK - Chrome browser on your Android emulator

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:

TestProject Python SDK Reports

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:

Appium Tests with Python SDK for iOS

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:

TestProject Reports

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! 🐍

Avatar

About the author

Bas Dijkstra

Bas teaches companies around the world how to improve their testing efforts through test automation. He is an independent trainer, consultant and developer living in the Netherlands. When he’s not working he likes to take his bicycle for a ride, go for a run or read a good book.

Join TestProject Community

Get full access to the world's first cloud-based, open source friendly testing community. Enjoy TestProject's end-to-end test automation Platform, Forum, Blog and Docs - All for FREE.

Join Us Now  

Comments

3 1 comment

Leave a Reply

popup image

Appium for Teams

Sharing and distributing Appium tests has never been so easy! With TestProject's FREE Appium based platform, you can finally create awesome tests with the freedom to collaborate with your team effortlessly.
Sign Up Now right arrow
FacebookLinkedInTwitterEmail