使用UI测试测试操作扩展 [英] Testing Action Extension with UI Tests

查看:73
本文介绍了使用UI测试测试操作扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Action Extension目标上执行UI测试?我无法使用Action Extension作为要测试的目标"来创建UI测试目标.我正在尝试从Safari(或照片",虽然首选Safari/两者都选)中加载动作扩展"

如果我记录自己的互动,我可以得到的范围最大:

app.icons ["Safari"].tap()

然后我可以手动添加:

XCUIDevice.sharedDevice().pressButton(.Home)

在生成代码之前,但不能按预期工作(模拟器留在主屏幕上).

我也尝试过:

UIApplication.sharedApplication().openURL(NSURL(string:"https://google.com")!)

但这也无法打开Safari.

我什至不确定是否能够启动与Action Extension的自动化交互,但希望有可能实现.

解决方案

因此,可以使用XCUITest切换应用程序,但该文档未记录.如果您查看 Facebook的WebDriverAgent ,标头转储,并制作了一个用于从跳板发射的助手.您可以致电:

  XCUIApplication * safari = [[XCUIApplication alloc] initWithPrivatePath:nil bundleID:@"com.apple.safari"];[safari启动]; 

然后与Safari交互,就像执行您的应用程序一样.但是,我遇到了类似的问题,其中XCUITest不会真正启动扩展本身.打开后(即在测试运行时在扩展按钮上进行物理点击),测试运行器就可以完美运行,并且可以在与您的应用相同的上下文中与扩展交互.但是,让测试运行程序点击以启动扩展程序无济于事.我还遇到了一个 Apple Dev论坛问题.>

更新:

事实证明,如果您使用该应用程序按按钮位置处的屏幕,则扩展程序将加载,您可以与它进行交互!请注意,用于点击坐标的API非常难以理解.x,y是您从中创建坐标的事物的框架的倍数.相关示例代码:

 //应用是您的XCUIApplication//在这种情况下,我们在水平中间和y坐标603处轻敲(这是6+的屏幕尺寸)XCUICoordinate * ordinateOfRowThatLaunchesYourExtension = [应用程序坐标WithNormalizedOffset:CGVectorMake(0.5,603.0/736.0)];[coordinateOfRowThatLaunchesYourExtension tap]; 

在调用Apple的扩展程序选择器后,这将在操作表中按扩展程序的按钮.无论出于什么原因,只要在操作表中按一下您的应用程序,XCUITest中的bug都不会起作用:

  [app.sheets.staticTexts [@"MyApp"]点击]; 

Is it possible to perform UI tests on Action Extension targets? I am unable to create a UI testing target with the Action Extension as the "Target to be Tested." I am trying to load the Action Extension from within Safari (or Photos, although Safari/both is prefered)

If I record my interactions I can get as far as:

app.icons["Safari"].tap()

I can then manually add:

XCUIDevice.sharedDevice().pressButton(.Home)

before the generated code, but it doesn't work as expected (the simulator is left on the home screen).

I have also tried:

UIApplication.sharedApplication().openURL(NSURL(string: "https://google.com")!)

but that also doesn't open Safari.

I'm not even sure if I'll be able to interact in an automated with with the Action Extension if it does get launched, but hopefully it'll be possible.

解决方案

So, it's possible to switch apps with XCUITest, but it's undocumented. If you check out Facebook's WebDriverAgent, they did a header dump and made a helper for launching from the springboard. You can call:

XCUIApplication* safari = [[XCUIApplication alloc] initWithPrivatePath:nil bundleID:@"com.apple.safari"];

[safari launch];

And then interact with Safari just like you do your app. However, I've run into a similar problem where XCUITest won't actually launch the extension itself. Once open (i.e. you tap physically on the extension button while the test is running), the test runner works perfectly, and you can interact with your extension in the same context as your app. However, having the test runner tap to launch the extension does nothing. I've also got an Apple Dev Forum question going on this topic.

Update:

It turns out if you use the app to press the screen at the location of the button, the extension will load and you can interact with it! Note that the API for tapping a coordinate is very wonky. The x, y are multipliers of the frame of the thing that you created the coordinate from. Relevant sample code:

// app is your XCUIApplication
// In this case we are tapping in the horizontal middle and at the y coordinate 603 (this is for a 6+ screen size)
XCUICoordinate* coordinateOfRowThatLaunchesYourExtension = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 603.0 / 736.0)];
[coordinateOfRowThatLaunchesYourExtension tap];

This will press the button for your extension in the action sheet, after Apple's extension picker has been invoked. For whatever reason / bug in XCUITest simply pressing your app in the action sheet doesn't work:

[app.sheets.staticTexts[@"MyApp"] tap];

这篇关于使用UI测试测试操作扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆