Skip to content

Commit 258fb9e

Browse files
authored
Merge pull request #4 from CiscoTestAutomation/mobile_app_pyats
Mobile App Automation using PyATS+Appium
2 parents 4b064d6 + 0b76704 commit 258fb9e

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

mobile_app/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Overview
2+
3+
This check connects to AppiumSerice using Appium-Python-Client
4+
and perform Mobile App Automation. Desired capabilities can
5+
be changed as per requirement and can help us test Mobile Applications(Android/iOS) using pyATS.
6+
7+
Make sure appium is installed 'npm install -g appium'
8+
Make sure python client is installed "pip install Appium-Python-Client"
9+
10+
# Running
11+
12+
```
13+
pyats run job android_job.py
14+
```

mobile_app/android_job.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
from pyats.easypy import run
3+
def main():
4+
test_path = os.path.dirname(os.path.abspath(__file__))
5+
testscript = os.path.join(test_path, 'pyats_android.py')
6+
run(testscript=testscript)

mobile_app/pyats_android.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
import logging
3+
import time
4+
from pyats import aetest
5+
from appium import webdriver
6+
from selenium.webdriver.common.by import By
7+
from appium.webdriver.appium_service import AppiumService
8+
log = logging.getLogger(__name__)
9+
10+
11+
###################################################################
12+
### TESTCASES SECTION ###
13+
###################################################################
14+
15+
class tc_android_calculator(aetest.Testcase):
16+
@aetest.setup
17+
def prepare_testcase(self, section):
18+
""" Testcase Setup section """
19+
log.info("Preparing the test")
20+
# Make sure python client is installed "pip install Appium-Python-Client"
21+
# Make sure appium is installed 'npm install -g appium'
22+
self.appium_service = AppiumService()
23+
# By default appium starts server at port 4723.
24+
# You can pass port as argument in AppiumService to change it.
25+
self.appium_service.start()
26+
log.info(self.appium_service.is_running)
27+
28+
# Following is desired capabilities for Android app
29+
desired_caps = {}
30+
desired_caps['platformName'] = 'Android'
31+
desired_caps['platformVersion'] = '6.0'
32+
desired_caps['automationName'] = 'androidautomator'
33+
desired_caps['deviceName'] = 'Android Emulator'
34+
desired_caps['appPackage'] = 'com.android.calculator2'
35+
desired_caps['appActivity'] = 'com.android.calculator2.Calculator'
36+
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
37+
38+
# Following is example of testing iOS app
39+
# desired_caps['platformName'] = 'iOS'
40+
# desired_caps['platformVersion'] = '11.0'
41+
# desired_caps['automationName'] = 'iosautomator'
42+
# desired_caps['deviceName'] = 'iPhone 7'
43+
# desired_caps['app'] = '/path/to/my.app'
44+
45+
# First test section
46+
@ aetest.test
47+
def pass_check(self):
48+
no_7 = self.driver.find_element(value="digit_7", by=By.ID)
49+
no_7.click();
50+
plus = self.driver.find_element(value="op_add", by=By.ID)
51+
plus.click();
52+
no_4 = self.driver.find_element(value="digit_4", by=By.ID)
53+
no_4.click();
54+
equalTo = self.driver.find_element(value="eq", by=By.ID)
55+
equalTo.click();
56+
results = self.driver.find_element(value="formula", by=By.ID)
57+
result_value = results.get_attribute('text')
58+
if result_value == '11':
59+
self.passed('Value is 11')
60+
else:
61+
self.failed('Value is not 11')
62+
63+
# Second test section
64+
@ aetest.test
65+
def failure_check(self):
66+
no_7 = self.driver.find_element(value="digit_7", by=By.ID)
67+
no_7.click();
68+
plus = self.driver.find_element(value="op_add", by=By.ID)
69+
plus.click();
70+
no_4 = self.driver.find_element(value="digit_4", by=By.ID)
71+
no_4.click();
72+
equalTo = self.driver.find_element(value="eq", by=By.ID)
73+
equalTo.click();
74+
75+
results = self.driver.find_element(value="formula", by=By.ID)
76+
result_value = results.get_attribute('text')
77+
if result_value == '12':
78+
self.passed('Value is 12')
79+
else:
80+
self.failed('Value is not 12')
81+
82+
@aetest.cleanup
83+
def clean_testcase(self):
84+
log.info("Pass testcase cleanup")
85+
# Close app
86+
self.driver.quit()
87+
# Stop Appium Service
88+
self.appium_service.stop()
89+
90+
if __name__ == '__main__': # pragma: no cover
91+
aetest.main()

0 commit comments

Comments
 (0)