appium webview切换native界面操作方法

webview界面:
print(driver.contexts)
driver.switch_to.context(输入待测试webview名字))

native界面:
driver.switch_to.content(输入待测试native界面‘NATIVE_APP’)

代码如下:

from appium import webdriver
import time,traceback

desired_caps = {}
desired_caps['platformName'] = 'Android'#测试平台
desired_caps['platforVersion'] = '7'#平台版本
desired_caps['deviceName'] = 'test'#设备名称 随便填写一个值
#desired_caps['browserName'] = 'Chrome'
desired_caps['appPackage'] = 'com.example.jcy.wvtest'#app packagem包名
desired_caps['appActivity'] = 'com.example.jcy.wvtest.MainActivity'#主activity信息
desired_caps['unicodeKeyboard'] = True#自动化输入内容有中文字符加此参数
desired_caps['noReset'] = True#测试完成 还原输入法 重要参数保证app测试前数据不被删除
desired_caps['newCommandTimeout'] = 6000#超过6000毫秒 无命令 appium会断开
desired_caps['automationName'] = 'uiautomator2'
desired_caps['chromedriverExecutable'] = r'D:\for myself\Google\Chrome\Application\chromedriver.exe'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
#启动手机浏览器
try:
time.sleep(3)
print(driver.contexts)#打印出待测试的webview名字
driver.switch_to.context('WEBVIEW_com.example.jcy.wvtest')#输入待测试webview名字 切换至webview界面
driver.find_element_by_id('index-kw').send_keys('哈哈哈哈\n')
driver.switch_to.contextt('NATIVE_APP')#切换至native界面
time.sleep(2)
driver.find_element_by_id('com.example.jcy.wvtest:id/navigation_notifications').click()#切换至通知面板

except:
print(traceback.format_exc())

input('**** Press to quit..')
driver.quit()


测试webview界面前提是webview需要开发配置好

posted on 2019-06-26 14:57  芋头加满仓  阅读(620)  评论(0编辑  收藏  举报

导航