【问题标题】:Which command can be used in Appium to switch between mobile app and web application?Appium 中可以使用哪个命令在移动应用程序和 Web 应用程序之间切换?
【发布时间】:2020-08-23 14:26:31
【问题描述】:

在 Appium 中可以使用哪个命令在移动应用程序和 Web 应用程序之间切换? 例如,我想测试一个需要在移动应用测试之间切换到网络应用的场景。

【问题讨论】:

    标签: appium appium-android


    【解决方案1】:

    如果您的意思是从 Appium 驱动程序更改为 Appium Web 驱动程序(假设是 chrome),您应该更改驱动程序上下文。 (Python 中的示例)

    像往常一样使用任何应用程序运行 appium。那么:

    对于网页/网络应用程序:

    driver.switch_to.context('WEBVIEW_chrome')   
    

    并切换回 tu pure appium:

    driver.switch_to.context('NATIVE_APP')
    

    每次在运行时您想要打开任何 android 应用程序/通知等...您应该将上下文更改为 NATIVE_APP。 同样,在打开 chrome 之前,您应该将上下文更改为 WEBVIEW,然后运行 ​​driver.get("https://sample.com") - 可以是任何网页或网络应用程序。

    请注意:

    1- 在 webdriver 上下文中,您应该使用 selenium 定位策略来定位元素。喜欢 "html/body/div/div/span[2]" (abs-xpath) 或 #div.class>span (css)

    2- 这不会运行 selenium WebDriver。 Selenium webdriver 仅适用于桌面。如果是移动设备,您应该只使用 Appium 并使用驱动程序上下文。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-10-19
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多