There are two ways to install and use the Appium Python client.
-
Install from PyPi, as 'Appium-Python-Client'.
pip install Appium-Python-Client
-
Install from source via GitHub.
git clone git@github.com:appium/python-client.git cd python-client python setup.py install
Page Object Model is a design pattern which has become popular in test automation for enhancing test maintenance and reducing code duplication. A page object is an object-oriented class that serves as an interface to a page of your AUT.
We integrated all Selenium upgraded changes, which makes mobile testing easier in python. We are using appium driver to make remote connection. Please refer below code.
# Android environment
import test.functional.pageobjectmodel.util.desired_capabilities as desired_capabilities
class BaseSpecification(unittest.TestCase):
def setUp(self):
desired_caps = desired_capabilities.get_desired_capabilities('android-automation.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
self.driver.quit()
# Returns abs path relative to this file and not cwd
def PATH(p):
return os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
def get_desired_capabilities(app):
return dict(platformName='Android', deviceName='Galaxy Tab S3',
app=PATH('../../../apps/' + app), appPackage='com.jiteshmohite619.androidautomation',
appActivity='.MainActivity', newCommandTimeout=240)
Swipe from one point to another point.
Zoom in on an element, doing a pinch out operation.
Zoom out on an element, doing a pinch in operation.
To check if an application is currently installed on the device, use the device.is_app_installed
method. This method takes the bundle id of the application and return True
or
False
.
assertFalse(self.driver.is_app_installed('test'))
assertTrue(self.driver.is_app_installed('com.example.android.androidautomation'))
To install an uninstalled application on the device, use device.install_app
,
sending in the path to the application file or archive.
assertFalse(driver.is_app_installed('com.example.android.androidautomation'))
driver.install_app('/path/android-automation.apk')
assertTrue(driver.is_app_installed('com.example.android.androidautomation'))
If you need to remove an application from the device, use device.remove_app
,
passing in the application id.
assertTrue(driver.is_app_installed('com.example.android.androidautomation'))
driver.remove_app('com.example.android.apis')
assertFalse(driver.is_app_installed('com.example.android.apis'))
To reset the running application, use driver.reset
.
The driver.start_activity
method opens arbitrary activities on a device.
If the activity is not part of the application under test, it will also
launch the activity's application.
driver.start_activity('com.example.android.androidautomation', '.LoginActivity')
The property method driver.app_strings
returns the application strings from
the application on the device.
strings = driver.app_strings
The property method driver.current_package
returns the name of the current
package running on the device.
package = driver.current_package
assertEquals('com.example.android.androidautomation', package)
The property method driver.current_activity
returns the name of the current
activity running on the device.
activity = driver.current_activity
assertEquals('.LoginActivity', activity)
To shake the device, use driver.shake
.