【问题标题】:Testing of Android Application without resetting its state using Appium and Selenium WebDriver使用 Appium 和 Selenium WebDriver 测试 Android 应用程序而不重置其状态
【发布时间】:2016-10-13 09:41:45
【问题描述】:

我希望在不重置其状态的情况下测试我的 android 应用程序。我注意到每次运行应用程序时都会出现不同的弹出窗口,所以我希望记录所有不同的弹出窗口。

我在这里对“运行”的定义是点击手机上的返回按钮并再次点击我的应用程序图标。

但是,我无法在我的 Appium 测试中模拟手机的这种物理敲击。我可以退出我的第一个测试,但我无法再次重新打开我的应用程序。 (模拟用手指点击应用程序图标)

我尝试过的事情:

1. Setting noReset to true in capabilities setting

2. Using uiautomator to find my application.  However, uiautomator doesn't seem to be able to detect any icons in the app menu page. It just shows many layers of frame layouts.

3. closeApp() and launchApp() resets the application and this defeats the purpose of my test.  My application somehow behaves differently with each run so I hope to run my test in a single session (i.e. closing and opening the application while it is still in the same state)

无论如何我可以以代码的形式模拟图标的物理点击吗?我知道我们可以设置坐标,但我不想硬编码我的测试只在手机的特定实例上运行。如果卸载了其他应用程序并且我的应用程序图标移动到另一个位置,它将无法运行。

【问题讨论】:

    标签: java android selenium-webdriver appium


    【解决方案1】:

    这对我有用:

    "appPackage": "com.company.app",
    "appActivity": "com.company.app.activities.HomeActivity",
    "skipDeviceInitialization": true,
    "skipServerInstallation": true,
    "noReset": true
    

    这不会重新安装 .apk、appium 服务器,也不会删除 appdata。您可以像在开始测试之前离开它一样启动应用程序。

    我发现这个在 GitHub 上浏览相同的问题:

    https://github.com/appium/appium/issues/4955

    https://github.com/appium/appium/issues/3783

    【讨论】:

      【解决方案2】:

      如果我在这里没有误会您,您可以尝试使用AndroidDriver 的以下组合:

      driver.navigate().back(); // from app home screen to mobile home screen
      driver.startActivity(String appPackage, String appActivity); // or possibly cast ((AndroidDriver)driver)
      

      【讨论】:

      • 我的代码找不到函数startActivity。您正在使用哪些库?我正在使用 java-client:4.0.0 和 selenium 2.53.0
      • @ykw - 如前所述,该方法与 AndroidDriver 相关联,您使用的是什么驱动程序?
      • 哦,是的...我正在使用 AppiumDriver。对不起。 AppiumDriver 和 AndroidDriver 有什么区别? :P
      • @ykw - AndroidDriver 是从 AppiumDriver 派生的,更具体到平台(Android)。
      • 我得到了这个异常:线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at io.appium.java_client.android.AndroidDriver.startActivity(AndroidDriver. java:343) 在 io.appium.java_client.android.AndroidDriver.startActivity(AndroidDriver.java:389) 这是由于包定义吗?我使用 AppiumServer 启动了服务器,所以我没有在设置功能阶段指定包和活动名称。
      【解决方案3】:

      您可以通过提供包名称和启动活动名称而不是所需大写的 apk 文件来启动应用程序,这样您的应用程序将不会在您每次启动应用程序时重置 使用presskey4点击返回按钮,你可以调用启动应用程序功能来启动应用程序而无需重置

      【讨论】:

        猜你喜欢
        • 2018-04-29
        • 2017-02-20
        • 2014-07-05
        • 1970-01-01
        • 2013-07-02
        • 2017-11-23
        • 2016-05-06
        • 1970-01-01
        • 2015-10-09
        相关资源
        最近更新 更多