运行XCUITest时,使用app.images找不到XCUIElement

Way*_*yne 5 objective-c swift xcuitest

我有一个XCUITest,它找不到特定的图像,但是在屏幕上完全可见。(模拟器和物理设备)

我怎样才能解决方法或使该UIImage的访问测试? 所有我想要验证是元素是否可见和可触摸屏幕上。

UIImage作为子视图添加到UITableView-放置在TableView的底部。

- (void)viewDidLoad {
         [super viewDidLoad];
         // portions of code left out here
         _aView = [[UIImageView alloc] initWithFrame:CGRectZero];
         [[self aView] setContentMode:UIViewContentModeScaleAspectFit];
         [[self aView] setImage:[UIImage imageNamed:IMG_NAME]] ;
         [[self tableView] addSubview:[self aView]]; 
Run Code Online (Sandbox Code Playgroud)

UIImageView稍后进行布局:

  - (void) viewWillLayoutSubviews {
       // portions of code left out here
       [[self aView] setFrame:CGRectMake(0, MAX([self tableView].contentSize.height - 41 ,[self tableView].bounds.size.height - 41) , 180, 30)];
       [[self aView] setCenter:CGPointMake([self tableView].center.x, [self aView].center.y)];
Run Code Online (Sandbox Code Playgroud)

然后在运行测试时:

    let app = XCUIApplication()

    //this works
    let tapString = localizedString("skip")
    let skipButton = app.buttons[tapString].firstMatch
    if (skipButton.exists) {
        skipButton.tap()
    }

    let theImage = app.images["img.png"]
    let doesExist = theImage.exists //<< it never exists
Run Code Online (Sandbox Code Playgroud)

还做了调试和打印所有图像不显示图像。我在与doesExists行设置一个断点,并在调试窗口,我运行以下命令:

po app.images
Run Code Online (Sandbox Code Playgroud)

找到了许多图像,但没有找到要测试的特定图像。

是否有解决此问题的替代方法?