# coding=utf-8

 from appium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC class Base: def __init__(self):
self.driver = self.get_driver()
self.size = self.get_size() def get_driver(self):
capabilities = {
"platformName": "Android",
"automationName": "UiAutomator2", # 测试平台,默认为appium,为了get_tost此处为automator2
"deviceName": "127.0.0.1:21513",
"app": "E:\\pythonAppium\\autoTest\\apps\\mukewang.apk",
"appWaitActivity": "cn.com.open.mooc.user.register.MCPhoneRegisterAty",
"noReset": "True", # 是否重装
# "chromeOptions": {"androidProcess": "WEBVIEW_cn.com.open.mooc"} }
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities)
return driver def get_size(self):
# 获取屏幕大小
size = self.driver.get_window_size()
width = size['width']
height = size['height']
return width, height def swipe_right(self):
"""
从左向右滑
:return:
"""
x = self.get_size()[0]/10
x1 = self.get_size()[0]/10*9
y = self.get_size()[1]/2
self.driver.swipe(x, y, x1, y) def swipe_left(self):
"""
从右向左滑
:return:
"""
x = self.get_size()[0]/10*9
x1 = self.get_size()[0]/10
y = self.get_size()[1]/2
self.driver.swipe(x, y, x1, y) def swipe_up(self):
"""
从下往上滑
:return:
"""
x = self.get_size()[0]/2
y = self.get_size()[1]/10*9
y1 = self.get_size()[1]/10
self.driver.swipe(x, y, x, y1) def swipe_down(self):
"""
从上往下滑
:return:
"""
x = self.get_size()[0]/2
y = self.get_size()[1]/10
y1 = self.get_size()[1]/10*9
self.driver.swipe(x, y, x, y1) def swipe_on(self, direction):
if direction == 'left':
self.swipe_left()
elif direction == 'right':
self.swipe_right()
elif direction == 'up':
self.swipe_up()
else:
self.swipe_down() def go_to_login(self):
"""
跳转到登录界面
:return:
"""
self.driver.find_element_by_id('cn.com.open.mooc:id/tv_go_login').click() def login_by_id(self):
self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit').send_keys('')
# self.drvier.find_element_by_id('cn.com.open.mooc:id/password_edit').send_keys('dianzi1312')
self.driver.find_element_by_id('cn.com.open.mooc:id/login').click() def login_by_uiautomator(self):
self.driver.find_element_by_android_uiautomator('new UiSelector().text("13055211990")').clear()
self.driver.find_element_by_android_uiautomator('new UiSelector().text("手机号/邮箱")').sendkeys('')
self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/password_edit")').sendkeys('dianzi1312') def login_by_xpath(self):
# 在所有层级查找text包含忘记的元素
# self.drvier.find_element_by_xpath('//*[cotains(@text,"忘记")]').click()
# 在class为..中查找text为忘记的元素
# self.drvier.find_element_by_xpath('//android.widget.TextView[@text="忘记"]').click()
# /../preceding-sibiling::寻找上级节点
self.driver.find_element_by_xpath('//android.widget.TextView@resource-id="cn.com.open.mooc:id/login_lable"]/../preceding-sibiling::*[@index="1]') def get_webview(self):
time.sleep(20)
webviews = self.driver.contexts
print(webviews)
for view in webviews:
if 'WEBVIEW_cn.com.open.mooc' in view:
print("")
self.driver.switch_to.context(view)
print("")
break
self.driver.find_element_by_link_text('JAVA').click() def get_tost(self):
time.sleep(2)
tost_locator = ("xpath", "//*[contains(@text,'请输入密码')]")
result = WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(tost_locator))
print(result) if __name__ == '__main__':
run = Base()
time.sleep(5)
# run.login_by_uiautomator()
run.go_to_login()
time.sleep(2)
run.login_by_id()
run.get_tost()

最新文章

  1. 全栈开发必备的10款 Sublime Text 插件
  2. CALayer 易混淆的两个属性 - position和anchorPoint
  3. 阿里资深工程师分享支付宝热补丁技术—— AndFix原理
  4. Portal for ArcGIS上传shp文件中文乱码可能情况
  5. 【CITE】C#目录、文件、文件夹操作
  6. Python的functools.reduce用法
  7. Jquery 操作xml 文档的方法
  8. Best Pratices——Make the Web Faster
  9. 你好,C++(40)7.1 一切指针都是纸老虎:彻底理解指针
  10. mysql导出数据到excel表中
  11. 异常处理第三讲,SEH(结构化异常处理),异常展开问题
  12. happens-before 理解
  13. vue的一些随记
  14. CCF关于公开NOIP复赛选手程序的通告
  15. loadrunner 运行脚本-Run-time Settings之Pacing设置
  16. OneAPM大讲堂 | 基于图像质量分析的摄像头监控系统的实现
  17. C# 生成时间戳
  18. js实现webSocket客户端
  19. Linux+Redis实战教程_Linux上安装jdk,mysql,tomcat_安装jdk
  20. OpenMP n 体问题

热门文章

  1. videojs调整音频播放语速
  2. git 提交大小超过100M
  3. .NET Core学习笔记(2)—— WPF使用UWP Custom Control
  4. windows服务器入门 使用FileZilla搭建FTP服务
  5. Memcache安装配置
  6. FineReport做成之后如何在Tomcat上运行
  7. 乐字节Java编程语言发展,面向对象和类
  8. windows下图形学视觉基本库安装不完全指南
  9. [转帖]Linux中awk工具的使用
  10. 分布式架构下,session共享有什么方案么?