Open KeepInLove1006 opened 5 years ago
利用了查找元素,滑动屏幕,强制等待的基础功能实现的一个登录与退出功能。
# coding=utf-8 import unittest from appium import webdriver import time class artisan_login(unittest.TestCase): def test_login(self): desired_caps={} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '7.0' desired_caps['deviceName'] = 'GWY0216C28000912' desired_caps['appPackage'] = 'xxxxxxxx' desired_caps['appActivity'] = 'xxx.activity.login.LaunchActivity' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 打开app self.driver.implicitly_wait(10000) # 输入手机号并点击获取验证码按钮 self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/edv_login_shortcut_phone").send_keys("18310000022") self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/tv_btn_login_shortcut_submit").click() # 点击登录按钮 self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/tv_btn_login_shortcut_submit").click() # 进入点击引导页确定按钮 self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/ok").click() # 点击“我的”界面 self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/main_activity_usercenter_page").click() # 向下滑动操作 print(self.driver.get_window_size()) x = self.driver.get_window_size()['width'] y = self.driver.get_window_size()['height'] time.sleep(2) self.driver.swipe(x*0.5, y*0.8, x*0.5, y*0.2, 200) # 点击设置按钮+退出登录 self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/civ_setting").click() self.driver.find_element_by_id("cn.zhimawu.shouyiren:id/tv_btn_logout").click() if __name__ == '__main__': login = artisan_login() login.test_login()
appium + python 实战(一):登录与退出
利用了查找元素,滑动屏幕,强制等待的基础功能实现的一个登录与退出功能。