app 端自动化 (简单易学)

直接上代码

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:62001"
caps["appPackage"] = "com.tencent.mobileqq"
caps["appActivity"] = "com.tencent.mobileqq.activity.SplashActivity"

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(60)
el1 = driver.find_element_by_id("com.tencent.mobileqq:id/btn_login")
el1.click()
dl2 = driver.find_element_by_accessibility_id("请输入QQ号码或手机或邮箱")
dl2.send_keys("2676334829")
dl3 = driver.find_element_by_accessibility_id("密码 安全")
dl3.send_keys("2676334829..")
#登入
dl4 = driver.find_element_by_id("com.tencent.mobileqq:id/login")
dl4.click()
dl5 = driver.find_element_by_accessibility_id("同意")
dl5.click()
#重复触发登入点击
dl4.click()
#切换账号
dl6 = driver.find_element_by_id("com.tencent.mobileqq:id/ok5")
dl6.click()
#添加账号
dl7 = driver.find_element_by_accessibility_id("添加帐号")
zh = driver.find_element_by_accessibility_id("请输入QQ号码或手机或邮箱")
zh.send_keys("1050463161")
mm = driver.find_element_by_accessibility_id("密码 安全")
mm.send_keys("liuyanying1001")
dr = driver.find_element_by_accessibility_id("登录")
dr.click()


#driver.quit()

 

下面这个是加了 po 模型

from dome3.basePages.BasePages import BasePages
from appium.webdriver.common.mobileby import MobileBy
class TestOneClass(BasePages):
    def __init__(self, driver):
        BasePages.__init__(self, driver)
    def click_dr(self):
        self.click(MobileBy.ID,"com.tencent.mobileqq:id/btn_login")
from dome3.basePages.BasePages import BasePages
from appium.webdriver.common.mobileby import MobileBy
class TestTwoClass(BasePages):
    def __init__(self, driver):
        BasePages.__init__(self, driver)
    def zhanghao(self,test):
        self.input(test,MobileBy.ACCESSIBILITY_ID,"请输入QQ号码或手机或邮箱")
    def mima(self,test):
        self.input(test, MobileBy.ACCESSIBILITY_ID, "密码 安全")
    def click_dr(self):
        self.click(MobileBy.ID,"com.tencent.mobileqq:id/login")
    def click_Ys(self):
        self.click(MobileBy.ACCESSIBILITY_ID,"同意")
from dome3.basePages.BasePages import BasePages
from appium.webdriver.common.mobileby import MobileBy
class TestThrClass(BasePages):
    def __init__(self, driver):
        BasePages.__init__(self, driver)
    def click_Zt(self):
        self.click(MobileBy.ID,"com.tencent.mobileqq:id/ok5")
    def input_zh(self):
        self.click(MobileBy.ACCESSIBILITY_ID,"添加帐号")
from dome3.basePages.BasePages import BasePages
from appium.webdriver.common.mobileby import MobileBy
class TestFouClass(BasePages):
    def __init__(self, driver):
        BasePages.__init__(self, driver)
    def zhanghao(self, test):
        self.input(test, MobileBy.ACCESSIBILITY_ID, "请输入QQ号码或手机或邮箱")
    def mima(self, test):
        self.input(test, MobileBy.ACCESSIBILITY_ID, "密码 安全")
    def click_dr(self):
        self.click(MobileBy.ACCESSIBILITY_ID, "登录")
import unittest,time,os
from dome3.testMethod.TestOneClass import TestOneClass
from dome3.testMethod.TestTwoClass import TestTwoClass
from dome3.testMethod.TestThrClass import TestThrClass
from dome3.testMethod.TestFouClass import TestFouClass
from appium import webdriver
from dome3.commonm.read_yaml import readYaml

class TestClass(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # os.path.dirname(__file__)当前文件的上一级目录
        # os.path.abspath(path)找到路径的绝对路径
        rootpath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
        dd = os.path.join(rootpath, "datas\config.yaml")
        dd = readYaml(dd)
        cls.driver = webdriver.Remote("http://localhost:4723/wd/hub",dd["caps"])
        cls.driver.implicitly_wait(60)
    def test001(self):
        to =TestOneClass(self.driver)
        to.click_dr()
    def test002(self):
        tt =TestTwoClass(self.driver)
        tt.zhanghao("")#这里写自己的QQ帐号
        tt.mima("")#这里写自己的QQ密码
        tt.click_dr()
        tt.click_Ys()
        tt.click_dr()
    def test003(self):
        th =TestThrClass(self.driver)
        th.click_Zt()
        th.input_zh()
    def test004(self):
        tf =TestFouClass(self.driver)
        tf.zhanghao("")#这里写登录另外一个的QQ帐号
        tf.mima("")#这里写登录另外一个的QQ密码
        tf.click_dr()
    @classmethod
    def tearDownClass(cls) -> None:
        time.sleep(4)
        cls.driver.quit()
if __name__ == '__main__':
  unittest.main()

caps:
  platformName: Android
  deviceName: 127.0.0.1:62001
  appPackage: com.tencent.mobileqq
  appActivity: com.tencent.mobileqq.activity.LoginActivity
import yaml,os
def readYaml(path):
    with open(path,"r",encoding="utf-8") as file:
        data = yaml.load(stream=file,Loader=yaml.FullLoader)
        return data
if __name__ == '__main__':
    #os.path.dirname(__file__)当前文件的上一级目录
    #os.path.abspath(path)找到路径的绝对路径
    rootpath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    dd = os.path.join(rootpath , "datas\config.yaml")
    print(dd)
    print(readYaml(dd))

代码结构

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值