利用Appium Python测试爱壁纸的登录和设置壁纸
2024-10-19 12:01:53
设置壁纸:
#coding:utf-8
#Import the common package
import os
import unittest
from appium import webdriver
from time import sleep #设置路径信息
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
) class LoginAndroidTests(unittest.TestCase):
def setUp(self):
#初始化测试平台
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '127.0.0.1:62001'
#desired_caps['app'] = 'D:\apk\爱壁纸.apk'
desired_caps['appPackage'] = 'com.lovebizhi.wallpaper'
desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) def tearDown(self): self.driver.quit() def test_1(self):
#测试导航页
print("start test1...") #判断是否安装爱壁纸APP
wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
if wallpaper:
#self.driver.remove_app("com.lovebizhi.wallpaper")
sleep(8)
# 点击某一壁纸图片
self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[4].click()
sleep(4)
# 点击设置壁纸
self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click()
sleep(5)
else:
self.driver.install_app("D:\apk\爱壁纸.apk")
sleep(30) def test_2(self):
#测试导航页
print("start test2") #判断是否安装爱壁纸APP
wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
#是
if wallpaper:
sleep(8)
# 点击某一壁纸图片
self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[5].click()
sleep(4)
# 点击设置壁纸
self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click()
sleep(5)
#否,安装
else:
self.driver.install_app("D:\apk\爱壁纸.apk")
sleep(30) if __name__ == '__main__':
suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
爱壁纸登录:
三种:微博、QQ、爱壁纸
#coding:utf-8
#Import the common package
import os
import unittest
from appium import webdriver
from time import sleep __author__ = 'sker' #设置路径信息
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
) class LoginAndroidTests(unittest.TestCase): """
loginMethod:登录的方法
method:传入的字符串
"""
def loginMethod(self,method):
try:
self.method = self.driver.find_element_by_class_name(method)
except Exception as e:
self._logins[method] = False
print(e)
else:
self._logins[method] = True
"""
toLoginPage:跳转到登录界面
"""
def toLoginPage(self):
#判断是否安装爱壁纸APP
wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
if wallpaper:
sleep(2)
print(u"已经安装爱壁纸")
# 点击头部的菜单栏
self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/logo").click()
print(u"出现隐藏的菜单栏")
sleep(2)
print(u"当前的activity是" + self.driver.current_activity)
# 点击登录头像
self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/ivFace").click()
print(u"跳转到登录页面")
sleep(2)
print(u"获取控件名称")
for context in self.driver.contexts:
print(context)
sleep(2)
print(u"切入h5的webdriver控件")
self.driver.switch_to.context("WEBVIEW_com.lovebizhi.wallpaper")
sleep(2) else:
print(u"开始安装apk")
self.driver.install_app("D:\apk\爱壁纸.apk")
sleep(30) """
weiBo:微博登录
username:用户名
password:密码
"""
def weiBo(self,username,password):
if(self._logins["weibo"]):
self.method.click()
print(u"进入通过微博登录")
sleep(5)
print(u"输入用户名和密码")
self._username = self.driver.find_element_by_id("userId")
self._username.send_keys(username)
self._pwd = self.driver.find_element_by_id("passwd")
self._pwd.send_keys(password)
sleep(2)
print(u"点击登录")
self.driver.find_element_by_class_name("btnP").click()
sleep(5)
else:
print(u"无法用微博登录") """
QQ:QQ登录
username:用户名
password:密码
"""
def QQ(self, username, password):
if(self._logins["tencent"]):
self.method.click()
print(u"进入通过QQ登录")
sleep(6)
print(u"输入用户名和密码")
self._username = self.driver.find_element_by_id("u")
self._username.send_keys(username)
self._pwd = self.driver.find_element_by_id("p")
self._pwd.send_keys(password)
sleep(2)
print(u"点击登录")
self.driver.find_element_by_id("go").click()
sleep(5)
else:
print(u"无法用QQ登录") """
paper:爱壁纸登录
username:用户名
password:密码
"""
def paper(self,username,password):
if(self._logins["lovebizhi"]):
self.method.click()
print(u"进入通过爱壁纸登录")
sleep(6)
print(u"输入用户名和密码")
self._username = self.driver.find_element_by_id("user")
self._username.send_keys(username)
self._pwd = self.driver.find_element_by_id("pass")
self._pwd.send_keys(password)
sleep(2)
print(u"点击登录")
self.driver.find_element_by_id("login").click()
sleep(5)
else:
print(u"无法用QQ登录") def setUp(self):
#初始化测试平台
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '127.0.0.1:62001'
#desired_caps['app'] = 'D:\apk\爱壁纸.apk'
desired_caps['appPackage'] = 'com.lovebizhi.wallpaper'
desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
#三种登录的方法,默认选中的都为False
self._logins = {"weibo":False,"tencent":False,"lovebizhi":False}
#跳转到登录界面
self.toLoginPage(); def tearDown(self): self.driver.quit() def test_weibo1(self):
self.loginMethod("weibo")
self.weiBo("admin","")
sleep(4)
self.assertEqual(u"admin",self.driver.find_element_by_class_name("logins_a_em").text)
sleep(2) def test_QQ1(self):
self.loginMethod("tencent")
self.QQ("admin","")
sleep(4)
self.assertEqual(u"admin",self.driver.find_element_by_id("name").value)
sleep(2) def test_paper1(self):
self.loginMethod("lovebizhi")
self.paper("admin","")
sleep(4) if __name__ == '__main__':
suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
最新文章
- 学习SpringMVC——国际化+上传+下载
- 移动电商时代、微分销商城O2O生活圈系统开发功能分析
- 关于linux,我们应该学什么?
- AngularJS入门心得3——HTML的左右手指令
- Vue.js——60分钟快速入门
- Swift3.0语言教程字符串大小写转化
- Iterator用法
- Jexus &; Mono 迁移
- Android TextView换行问题
- 最全的CMD命令
- HDU 4587 TWO NODES 割点
- LeetCode_N-Queens
- 201521123072《java程序设计》第十周学习总结
- 如何在 Centos7 中安装 nginx
- redis下载安装以及添加服务
- 别让持续交付自动化交付bug
- hadoop2.7集群安装
- CSS:opacity:0,visibility:hidden,display:none的区别
- NYOJ 16 矩形嵌套(经典DP)
- 在命令提示符下启动并使用JVM时,简单设置堆
热门文章
- JS类、对象、方法、prototype、_proto_
- 20135302魏静静——linux课程第四周实验及总结
- IDEA 安装mybatis 插件 可以通过mapper定位到xml
- struts1.2上传多个文件
- Spring @Scheduler使用cron时的执行问题
- 【Semantic Segmentation】 Instance-sensitive Fully Convolutional Networks论文解析(转)
- 【eclipse】Multiple annotations found at this line:——解决方法
- Linux计划任务,自动删除n天前的旧文件
- Kaggle 项目之 Digit Recognizer
- centos7 VNC安装