appium使用实例

# encoding: utf-8
import unittest
import warnings
from appium import webdriver
from common.Logger import Log
import time

log = Log()
class orderTests(unittest.TestCase):

@classmethod
def setUp(cls):
log.info('--启动微信程序--')
warnings.filterwarnings("ignore") # 禁用警告提示
desired_caps = {} # appium参数设置
desired_caps['platformName'] = 'Android'
desired_caps['fastReset'] = 'false'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = '.ui.LauncherUI'
desired_caps['fullReset'] = 'false'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['autoAcceptAlerts'] = 'True' # 支持断言
desired_caps['ChromeOptions'] = {'androidProcess': 'com.tencent.mm:appbrand0'} # 小程序使用
desired_caps['ChromeOptions'] = {'androidProcess': 'com.tencent.mm:tools'} # 公众号使用
# 启动微信程序
cls.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
cls.driver.implicitly_wait(30)
cls.driver.find_element_by_accessibility_id('搜索').click()
cls.driver.implicitly_wait(30)
cls.driver.find_element_by_id('com.tencent.mm:id/hz').send_keys(u"诚实充值特惠")
cls.driver.implicitly_wait(30)
cls.driver.find_element_by_id('com.tencent.mm:id/lp').click()
log.info('--成功进入诚实充值特惠小程序--')
print(cls.driver.contexts)

# @classmethod
def tearDown(cls):
time.sleep(10)
cls.driver.quit()
log.info('--退出程序--')

def test_order_01(self):
log.info('--下10元话费订单--')
try:
self.driver.implicitly_wait(50)
self.driver.find_element_by_accessibility_id('10元').click()
self.driver.implicitly_wait(20)
self.driver.find_element_by_id('com.tencent.mm:id/bri').send_keys('000021')
self.driver.implicitly_wait(20)
self.driver.find_element_by_name('支付成功')
log.info('--下单成功--')
except Exception as e:
log.warning('--下单失败--')
print("出错了" + str(e))


if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(orderTests)
unittest.TextTestRunner(verbosity=2).run(suite)
unittest.main()
 

转载于:https://www.cnblogs.com/wapn/p/9618973.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值