利用Appium Python测试爱壁纸的登录和设置壁纸
Posted 珍真小心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用Appium Python测试爱壁纸的登录和设置壁纸相关的知识,希望对你有一定的参考价值。
设置壁纸:
#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","123456") 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","123456") 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","123456") sleep(4) if __name__ == ‘__main__‘: suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests) unittest.TextTestRunner(verbosity=2).run(suite)
以上是关于利用Appium Python测试爱壁纸的登录和设置壁纸的主要内容,如果未能解决你的问题,请参考以下文章