【问题标题】:Is there a way in EarlGrey for me to reset the application automatically?EarlGrey 有没有办法让我自动重置应用程序?
【发布时间】:2016-11-13 02:43:31
【问题描述】:

假设我有以下应用结构:

[View Controller 1] -> tap on next button
                       [View Controller 2] -> Check for Title

在 EarlGrey 中,我通过以下方式定义了这个测试:

[[EarlGrey selectElementWithMatcher:grey_text(@"Next Button")]
    performAction:grey_tap()]
[[EarlGrey selectElementWithMatcher:grey_text(@"Screen Title")]
    assertWithMatcher:grey_sufficientlyVisible()];

但是现在,当我想测试[View Controller 3] 时,我注意到应用程序仍然停留在[View Controller 2]。是否有我错过的呼叫可以让我返回第一个屏幕或重置应用程序以进行下一次测试?

【问题讨论】:

    标签: ios ui-automation earlgrey


    【解决方案1】:

    与任何 xctest 一样,该应用不会重新启动,并保持与上一次测试离开时相同的状态。您需要在测试用例的 tearDown 或 setUp 中明确重置应用程序状态。你可以:

    1. 编写 UI 交互,在每个测试用例完成后让应用返回主屏幕。

    2. 在您的 App 委托中引入一个方法 resetApplicationForTesting 并从每个测试用例的 setUp 方法中调用它。 如果此逻辑需要与多个测试用例共享,请考虑创建这些测试用例继承的 BaseTestClass。

    在测试的setUp方法中:

        MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
        [delegate resetApplicationForTesting];
    

    【讨论】:

      猜你喜欢
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多