python + appnium 做android自动化测试

环境准备:

  1. android模拟器:androidstudio 下载

  2. python

  3. python开发工具PyCharm 下载地址: https://www.jetbrains.com/pycharm/

  4. node.js 环境

  5. chrome浏览器

  6. appnium 下载:
    http://appium.io/
    api: https://testerhome.com/topics/3144

  7. chrome 远程查看webview中内容:https://developers.google.com/web/tools/chrome-devtools/remote-debugging/?utm_source=dcc&utm_medium=redirect&utm_campaign=2016q3#configure-webview

参考:http://blog.csdn.net/qq744746842/article/details/47839645

示例代码:

#coding=utf-8

from appium import webdriver
import unittest
import  os
from time import  sleep

"""
试验测试android中的webview控件
"""

PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class AndroidWebview(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1'
        desired_caps['deviceName'] = 'emulator-5554'
        desired_caps['app'] = PATH(
            '../../../sample-code/mobile.apk'
        )

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.quit()

    def testWebview(self):
        sleep(15)
        ele = self.driver.find_element_by_name("新高考英语听力强化训练")
        ele.click()
        sleep(3)
        ele = self.driver.find_element_by_name("英语听力模拟试题(一)")
        ele.click()
        print self.driver.contexts

        self.driver.switch_to.context('WEBVIEW_com.android.browser')
        sleep(6)
        ele = self.driver.find_element_by_class_name("look")
        ele.click()
        sleep(6)

if __name__ == "__main__":
    suite = unittest.TestLoader().loadTestsFromTestCase(AndroidWebview)
    unittest.TextTestRunner(verbosity=2).run(suite)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值