Created
August 3, 2015 15:06
-
-
Save sholfen/62b8b6a0778b33b55e59 to your computer and use it in GitHub Desktop.
Appium Demo with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from appium import webdriver | |
from selenium.common.exceptions import WebDriverException | |
import os | |
#import os.path | |
import traceback | |
dic_localtion = {} | |
dic_localtion['touch0'] = (715, 1173) | |
dic_localtion['touch1'] = (314, 800) | |
dic_localtion['touch2'] = (1120, 911) | |
dic_localtion['touch3'] = (357, 1176) | |
dic_localtion['touch4'] = (1144, 1325) | |
dic_localtion['touch5'] = (738, 2064) | |
def handle_commands(commands): | |
first = commands[0] | |
count = int(commands[1]) | |
(x, y) = dic_localtion[first] | |
print 'start' | |
for i in range(0,count): | |
print i | |
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": x, "y": y }) | |
print 'end' | |
success = True | |
desired_caps = {} | |
desired_caps['appium-version'] = '1.0' | |
desired_caps['platformName'] = 'Android' | |
desired_caps['platformVersion'] = '5.0.1' | |
desired_caps['deviceName'] = 'SM-N910U' | |
desired_caps['appPackage'] = 'tokyo.seec.RestraintGIRL' | |
desired_caps['noReset'] = True | |
desired_caps['fullReset'] = False | |
wd = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) | |
wd.implicitly_wait(60) | |
try: | |
time.sleep(3) | |
loop_flag = True | |
while loop_flag: | |
try: | |
user_input = raw_input('please input command:') | |
commands = user_input.split(' ') | |
if len(commands) == 2: | |
handle_commands(commands) | |
else: | |
if commands[0] == 'exit': | |
loop_flag = False | |
break | |
elif commands[0] == 'loop100': | |
for i in range(0,100): | |
wd.execute_script("mobile: tap", {"tapCount": 1, "touchCount": 1, "duration": 0.5, "x": 715, "y": 1173 }) | |
except Exception, e: | |
print e | |
print 'has error.' | |
finally: | |
pass | |
pass | |
print 'end' | |
except: | |
print 'error' | |
finally: | |
wd.quit() | |
print 'exit' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment