【问题标题】:EarlGrey GREYCondition waitWithTimeout:15 does not wait for 15 secondsEarlGrey GREYCondition waitWithTimeout:15 不等15秒
【发布时间】:2016-09-28 11:22:37
【问题描述】:

我编写了一个测试,它应该在评估条件之前等待 15 秒。它目前等待的时间要短得多,并立即进入评估块,产生错误。之后的秒参数:waitWithTimeout 似乎被忽略了。

我的测试代码:

- (void)testAsyncEvent {

    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Button")]
        performAction:grey_tap()];

    // Wait for the main view controller to become the root view controller.
    BOOL success = [[GREYCondition conditionWithName:@"Wait for label to change text"
        block:^{

        NSError *error;
        [[EarlGrey selectElementWithMatcher:grey_text(@"Delayed Appearance")]
            performAction:grey_tap()
                    error:&error];

        if ([error.domain isEqual:kGREYInteractionErrorDomain] &&
            error.code == kGREYInteractionElementNotFoundErrorCode) {
            return NO;
        }

        return YES;

    }] waitWithTimeout:15];

    GREYAssertTrue(success, @"Label text should be changed after 5 seconds. ");
}

这里是按钮点击动作:

- (IBAction)buttonPressed:(id)sender
{
    self.titleLabel.text = @"Button Pressed";

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
    ^(void)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
         self.titleLabel.text = @"Delayed Appearance";
        });
    });
}

titleLabel 的文本应该在 4 秒后通过异步调度更改为“延迟外观”。但是测试中的块触发非常快,尽管它设置为 15 秒。 (并且失败,因为没有找到具有此类文本的元素)。

【问题讨论】:

  • 我通过禁用 GRAY API 上的同步来解决这个问题,如下所示: [[GREYConfiguration sharedInstance] setValue:@(NO) forConfigKey:kGREYConfigKeySynchronizationEnabled];它现在等待我指定的全部金额。所以我想知道是什么导致它在启用同步 API 时提前触发......

标签: ios xctest ui-testing earlgrey


【解决方案1】:

我认为这不是 API 的意图。该 API 用于等待满足 X 秒的条件。 timeout 中的 seconds 参数是它应该真正等待满足条件的时间。如果此时条件仍未满足,则超时并返回 NO。如果您真的只想等待 15 秒,请使用: [[NSRunLoop currentRunLoop] runUntilDate:]

而且,由于您使用的是 dispatch_after,因此您可以增加 dispatch_after 调用的跟踪时间: [[GREYConfiguration sharedInstance] setValue:@(5.0) forConfigKey:kGREYConfigKeyDispatchAfterMaxTrackableDelay];

只要记住在未来 5.0 秒内不再希望跟踪调度后将其重置为默认值即可。

【讨论】:

    猜你喜欢
    • 2021-02-26
    • 1970-01-01
    • 2011-04-15
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 2015-08-17
    • 2011-12-28
    相关资源
    最近更新 更多