如何知道任何UI呈现是在自动化代码中完成的



我想知道按钮是否在主窗口UI上呈现。这个按钮渲染取决于服务器响应结果(写在Objective C中)。如果服务器响应完美,它就会完美渲染(可见),否则它就不存在了(不可见)。每当它变得可见时,我总是点击它以进行下一个处理。

我写了代码

UIATarget.localTarget().pushTimeout(200);
   //My code
UIATarget.localTarget().popTimeout();

通过上面的代码,我必须等待200秒,但我担心的是我想等待,但无论何时对象在屏幕上,我都不想让我在等待模式下忙碌。

如何在自动化中编写代码?

谢谢

好的,这可能会让你知道如何跟进:

为您的视图实现一个 accessbilityvalue 方法,返回一个JSON格式化值:

- (NSString *)accessibilityValue
{
    return [NSString stringWithFormat:
            @"{'MyButtonisVisible':%@}", 
            self.MyButton.isHidden ? @"false" : @"true"];
}

然后你可以从测试javascript中访问它:

var thisproperty = eval("(" + element.value() + ")");
if (thisproperty.MyButtonisVisible) {
    UIATarget.localTarget().tap({"x":100, "y":100});
}

希望对你有帮助。

如果您在启用按钮时使名称不同,您可以这样做:

var awesomeButton = target.frontMostApp().mainWindow().buttons()[0];
UIATarget.localTarget().pushTimeout(200);
awesomeButton.withName("My Awesome Button");
if (awesomeButton.isVisible()) {
    UIALogger.logError("Error no awesome button!");
}
UIATarget.localTarget().popTimeout();        

withName将重复测试该名称,一旦名称匹配或达到超时时间,控件将返回到脚本。

Per Apple's Doc

withName :测试元素的name属性是否具有给定的字符串值。如果匹配失败,则重试测试,直到当前超时时间到期。

超时时间:如果动作在超时期间完成,则返回该代码行,脚本可以继续。如果动作在超时时间内未完成,则抛出异常。

https://developer.apple.com/library/etc/redirect/xcode/ios/e808aa/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html//apple_ref/doc/uid/TP40004652-CH20

最新更新