• 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需要开发配置好
  • 相关阅读:
    物联网与边缘计算的融合
    在【自我认知】大学,你可能永远毕不了业
    Spring Security实现短信验证码登录
    线上课程
    【技术人成长】公众号
    大数据是阿猫阿狗都能玩的吗
    机器不能代替你思考
    如何缓解需求沟通中的鸡同鸭讲
    如何成为一个更渊博的技术人
    招聘季,聊聊那些古怪的候选人
  • 原文地址:https://www.cnblogs.com/iamshasha/p/11089889.html
Copyright © 2020-2023  润新知