Skip to main content

Python

info

Replace <server> with the appropriate URL.

Continuous Testing Cloud lets you execute Appium tests on remotely located devices.  This page is the starting line for your Appium tests with Python. It lists requirements, prerequisites and two sample tests hosted in a git repository - one for iOS and one for Android. 

Use of our sample tests in our git repository by cloning them, or use the sample tests below.

Android App Testing with Python Expand source

import unittest
from appium import webdriver
import os


class AndroidAppTest(unittest.TestCase):
test_name = "Android App Test with Python"
dc = {}
# if you have configured an access key as environment variable,
# use the line below. Otherwise, specify the key directly.
accessKey = os.environ['SEETEST_IO_ACCESS_KEY']
driver = None

def setUp(self):
self.dc['testName'] = self.test_name
self.dc['accessKey'] = self.accessKey
self.dc['platformName'] = 'Android'
self.dc['app'] = 'http://d242m5chux1g9j.cloudfront.net/eribank.apk'
self.dc['appPackage'] = 'com.experitest.ExperiBank'
self.dc['appActivity'] = '.LoginActivity'
self.driver = webdriver.Remote('<server>', self.dc)

def testYourAndroidApp(self):
self.driver.find_element_by_xpath("xpath=//*[@id='usernameTextField']").send_keys('company')
self.driver.find_element_by_xpath("xpath=//*[@id='passwordTextField']").send_keys('company')
self.driver.find_element_by_xpath("xpath=//*[@id='loginButton']").click()
self.driver.find_element_by_xpath("xpath=//*[@text='Make Payment']").click()
self.driver.find_element_by_xpath("xpath=//*[@id='phoneTextField']").send_keys('123456')
self.driver.find_element_by_xpath("xpath=//*[@id='nameTextField']").send_keys('Test')
self.driver.find_element_by_xpath("xpath=//*[@id='amountTextField']").send_keys('10')
self.driver.find_element_by_xpath("xpath=//*[@id='countryTextField']").send_keys('US')
self.driver.find_element_by_xpath("xpath=//*[@text='Send Payment']").click()
self.driver.find_element_by_xpath("xpath=//*[@id='button1']").click()

def tearDown(self):
if self.driver is not None:
print(self.driver.capabilities.get("reportUrl"))
self.driver.quit()

if __name__ == '__main__':
unittest.main()

IOS App Testing using Python Expand source

import unittest
from appium import webdriver
import os


class IosAppTest(unittest.TestCase):
test_name = "iOS App Test with Python"
dc = {}
# if you have configured an access key as environment variable,
# use the line below. Otherwise, specify the key directly.
accessKey = os.environ['SEETEST_IO_ACCESS_KEY']
driver = None

def setUp(self):
self.dc['testName'] = self.test_name
self.dc['accessKey'] = self.accessKey
self.dc['app'] = 'http://d242m5chux1g9j.cloudfront.net/EriBank.ipa'
self.dc['bundleId'] = 'com.experitest.ExperiBank'
self.dc['platformName'] = 'ios'
self.dc['autoDismissAlerts'] = True
self.driver = webdriver.Remote('<server>', self.dc)

def testUntitled(self):
self.driver.find_element_by_xpath("xpath=//*[@text='Username']").send_keys('company')
self.driver.find_element_by_xpath("xpath=//*[@text='Password']").send_keys('company')
self.driver.find_element_by_xpath("xpath=//*[@text='loginButton']").click()
self.driver.find_element_by_xpath("xpath=//*[@text='makePaymentButton']").click()
self.driver.find_element_by_xpath("xpath=//*[@text='Phone']").send_keys('123456')
self.driver.find_element_by_xpath("xpath=//*[@text='Name']").send_keys('Test')
self.driver.find_element_by_xpath("xpath=//*[@text='Amount']").send_keys('10')
self.driver.find_element_by_xpath("xpath=//*[@text='Country']").send_keys('US')
self.driver.find_element_by_xpath("xpath=//*[@text='sendPaymentButton']").click()
self.driver.find_element_by_xpath("xpath=//*[@text='Yes']").click()

def tearDown(self):
if self.driver is not None:
print(self.driver.capabilities.get("reportUrl"))
self.driver.quit()

if __name__ == '__main__':
unittest.main()

Chrome on Android Test with Python Expand source

import unittest
from appium import webdriver
import os


class TestWebsiteAndroidChrome(unittest.TestCase):
dc = {}
test_name = 'Test Mobile Website on Android Chrome'
# if you have configured an access key as environment variable,
# use the line below. Otherwise, specify the key directly.
accessKey = os.environ['SEETEST_IO_ACCESS_KEY']
driver = None

def setUp(self):
self.dc['testName'] = self.test_name
self.dc['accessKey'] = self.accessKey
self.dc['platformName'] = 'android'
self.dc['browserName'] = 'chrome'
self.driver = webdriver.Remote('<server>', self.dc)

def testUntitled(self):
self.driver.get('https://amazon.com')
if self.driver.capabilities['device.category'] == 'TABLET':
self.driver.find_element_by_xpath("//*[@name='field-keywords']").send_keys('iPhone')
self.driver.find_element_by_xpath("//*[@text='Go']").click()
else:
self.driver.find_element_by_xpath("//*[@name='k']").send_keys('iPhone')
self.driver.find_element_by_xpath("//*[@value='Go']").click()

def tearDown(self):
if self.driver is not None:
print(self.driver.capabilities.get("reportUrl"))
self.driver.quit()

if __name__ == '__main__':
unittest.main()

Safari on IOS Test with Python Expand source

import unittest
import os
from appium import webdriver


class TestWebsiteiOSSafari(unittest.TestCase):
dc = {}
test_name = 'Test Mobile Website on iOS Safari'
# if you have configured an access key as environment variable,
# use the line below. Otherwise, specify the key directly.
accessKey = os.environ['SEETEST_IO_ACCESS_KEY']
driver = None

def setUp(self):
self.dc['testName'] = self.test_name
self.dc['accessKey'] = self.accessKey
self.dc['platformName'] = 'ios'
self.dc['browserName'] = 'safari'
self.dc['autoDismissAlerts'] = True
self.driver = webdriver.Remote('<server>', self.dc)

def testUntitled(self):
self.driver.get('https://amazon.com')
if self.driver.capabilities['device.category'] == 'TABLET':
self.driver.find_element_by_xpath("//*[@name='field-keywords']").send_keys('iPhone')
self.driver.find_element_by_xpath("//*[@text='Go']").click()
else:
self.driver.find_element_by_xpath("//*[@name='k']").send_keys('iPhone')
self.driver.find_element_by_xpath("//*[@value='Go']").click()

def tearDown(self):
if self.driver is not None:
print(self.driver.capabilities.get("reportUrl"))
self.driver.quit()

if __name__ == '__main__':
unittest.main()






Prerequisites