appium启动小程序

1、配置小程序

coding:utf-8

author = ‘lili’

‘’’
description:driver配置
‘’’
import time
from appium import webdriver

class driver_configure():
@property
def get_driver(self):
# 获取driver
try:
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’ # 平台
desired_caps[‘platformVersion’] = ‘23’ # 系统版本
desired_caps[‘deviceName’] = ‘c3756aa**’ # 设备名称
desired_caps[‘appPackage’] = ‘com.tencent.mm’ # APK包名
desired_caps[‘appActivity’] = ‘com.tencent.mm.ui.LauncherUI’ # 被测程序启动时的Activity
desired_caps[‘unicodeKeyboard’] = ‘true’ # 是否支持unicode的键盘。如果需要输入中文,要设置为“true”
desired_caps[‘resetKeyboard’] = ‘true’ # 是否在测试结束后将键盘重置为系统默认的输入法。
desired_caps[‘newCommandTimeout’] = ‘120’ # Appium服务器待appium客户端发送新消息的时间。默认为60秒
desired_caps[‘noReset’] = True # true:不重新安装APP,false:重新安装app
desired_caps[‘automationName’] = ‘uiautomator2’
desired_caps[‘chromeOptions’] = {‘androidProcess’: ‘com.tencent.mm:appbrand’} # 当前小程序运行的进程
self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
time.sleep(5)
return self.driver
except Exception as e:
print(‘启动失败’)
raise e

2、uiautomatorviewer页面元素定义

coding:utf-8

author = ‘lili’
‘’’
description:元素定义
‘’’
from common import Base_page
from appium.webdriver.common import mobileby
import time

class swipe_page(Base_page.Base_page):
by = mobileby.MobileBy()
item_fx = (by.XPATH, “//android.widget.TextView[@text=‘发现’]”) # 点击“发现”
item_xcx = (by.NAME, “小程序”) # 点击小程序
item_wdxcx = (by.NAME, “我的小程序”) # 点击我的小程序
item_kjxs = (by.NAME, “科技线上”) # 点击科技线上

def click_fx(self):
    self.find_element(*self.item_fx).click()      # 点击“发现”

def click_xcx(self):
    self.find_element(*self.item_xcx).click()     # 点击小程序
    time.sleep(3)
    self.find_element(*self.item_wdxcx).click()  # 点击我的小程序
    time.sleep(3)
    self.find_element(*self.item_kjxs).click()  # 点击科技线上

def swipe_down(self, n):   #      # 向下滑动
    x = self.driver.get_window_size()['width']
    y = self.driver.get_window_size()['height']
    for i in range(n):
        self.driver.swipe(x / 2, y * 3 / 4, x / 2, y / 4)

def swipe_up(self, n):
    '''上滑'''
    x = self.driver.get_window_size()['width']
    y = self.driver.get_window_size()['height']
    for i in range(n):
        self.driver.swipe(x / 2, y / 4, x / 2, y * 3 / 4)

3、启动小程序,以及具体的test_case

coding:utf-8

author = ‘lili’
‘’’
description:
‘’’
import unittest
from common import driver_configure
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_c

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值