zoukankan      html  css  js  c++  java
  • 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 myselfGoogleChromeApplicationchromedriver.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('哈哈哈哈 ')
    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需要开发配置好
  • 相关阅读:
    C++ Primer Plus 第15章 友元、异常和其它
    03013_JDBC工具类
    python GUI编程(Tkinter)
    Python2.x与3​​.x版本区别
    【python教程】Python JSON
    【python教程】Python IDE
    通过Google Custom Search API 进行站内搜索
    支持wmv、mpg、mov、avi格式的网页视频播放代码
    编写更好的jQuery代码的建议
    KindEditor得不到textarea值的解决方法
  • 原文地址:https://www.cnblogs.com/iamshasha/p/11089889.html
Copyright © 2011-2022 走看看