模拟 Home 按钮按下 - iPhone 测试
所以我正在测试一个 iPhone 应用程序。我正在尝试设置测试用例,以便稍后使用 UIAutomation 使用(我并没有真正受限于此 - 我可以切换到其他框架)。我基本上需要创建一个类似以下的测试:
+ Launches application
+ Clicks a few specific buttons
+ Hits the home button exiting the application
+ Relaunches the application
+ Checks the status of the application
有人知道如何执行此操作或使用什么框架来执行此操作吗?
提前致谢。
So I'm working on testing an iPhone app. I'm trying to setup test cases that we can use later using UIAutomation (I'm not really tied down to this - I can switch to some other framework). I basically need to create a test that goes something like:
+ Launches application
+ Clicks a few specific buttons
+ Hits the home button exiting the application
+ Relaunches the application
+ Checks the status of the application
Does anyone have any idea how to do this or what framework to use to do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法模拟按下主页按钮,但您可以强制应用程序退出。调用
[[UIApplication sharedApplication] Terminate];
将终止应用程序或(在 iOS 4.x 的情况下)将应用程序置于后台。但是,您将无法使用 UIAutomation 重新启动应用程序。您可以尝试将 UIAutomation 与屏幕录制脚本结合使用,该脚本允许您重播鼠标移动和单击。这将允许您直接与模拟器进行交互,例如单击主页按钮和单击应用程序图标。
或者,您可以使用
UIATarget
类。根据文档,使用
UIATarget.localTarget().deactivateAppForDuration(seconds);
您可以让应用程序后台运行 n 秒。You can't simulate the home button being pressed, but you can force the app to exit as if it were. Calling
[[UIApplication sharedApplication] terminate];
will terminate or (in the case of iOS 4.x) background the app. You will not, however, be able to relaunch the application using UIAutomation.You could try UIAutomation in combination with a screen recording script that allows you to replay mouse movement and clicks. This would allow you to interact with the simulator directly for things like home button clicks and app icon clicks.
Alternately you can get "good enough" testing using the
UIATarget
class. Per the docs,Using
UIATarget.localTarget().deactivateAppForDuration(seconds);
you can background your app for n seconds.通过 UI 测试,可以在 Xcode 7 中按主页按钮。
来源:https://stackoverflow.com/a/33087217/142358
It is possible to press the home button in Xcode 7 with UI Testing.
Source: https://stackoverflow.com/a/33087217/142358
我认为这是不可能的,但您可以使用
将您的应用程序放在后台一段特定的时间。
I don't think this is possible but you could use
To put your app in the background for a specific amount time.
在 iOS 中按下设备主页按钮
presses device home button in iOS