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