模拟 Home 按钮按下 - iPhone 测试

发布于 2024-11-28 11:25:02 字数 352 浏览 1 评论 0原文

所以我正在测试一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

久光 2024-12-05 11:25:02

您无法模拟按下主页按钮,但您可以强制应用程序退出。调用 [[UIApplication sharedApplication] Terminate]; 将终止应用程序或(在 iOS 4.x 的情况下)将应用程序置于后台。但是,您将无法使用 UIAutomation 重新启动应用程序。

您可以尝试将 UIAutomation 与屏幕录制脚本结合使用,该脚本允许您重播鼠标移动和单击。这将允许您直接与模拟器进行交互,例如单击主页按钮和单击应用程序图标。

或者,您可以使用 UIATarget。根据文档,

UIATarget 类代表高级用户界面元素
被测系统 (SUT) — 即您的应用程序、iOS 和
它们正在运行的连接设备。您的测试脚本,
用 JavaScript 编写并与 UI 结合运行
自动化仪表,使用该类和相关UIA类
练习 SUT 并记录结果。

使用 UIATarget.localTarget().deactivateAppForDuration(seconds); 您可以让应用程序后台运行 n 秒。

使用此方法来测试将您的应用程序移入和移出
后台执行上下文。请注意,使用 iOS 构建的应用程序
SDK 4.0 或更高版本并在 iOS 4.0 和更高版本中运行不一定
当用户按下主页按钮时终止。请参阅 iOS 应用程序
有关多任务处理和后台执行详细信息的编程指南
上下文。

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,

The UIATarget class represents high-level user interface elements of
the system under test (SUT)—that is, your application, the iOS, and
the connected device on which they’re running. Your test scripts,
written in JavaScript and running in conjunction with the UI
Automation instrument, use this class and related UIA classes to
exercise the SUT and log results.

Using UIATarget.localTarget().deactivateAppForDuration(seconds); you can background your app for n seconds.

Use this method to test shifting your application to and from the
background execution context. Note that applications built using iOS
SDK 4.0 or later and running in iOS 4.0 and later aren’t necessarily
terminated when the user presses the Home button. See iOS Application
Programming Guide for details of multitasking and background execution
context.

那伤。 2024-12-05 11:25:02

通过 UI 测试,可以在 Xcode 7 中按主页按钮。

XCUIDevice.sharedDevice().pressButton(XCUIDeviceButton.Home)

来源:https://stackoverflow.com/a/33087217/142358

It is possible to press the home button in Xcode 7 with UI Testing.

XCUIDevice.sharedDevice().pressButton(XCUIDeviceButton.Home)

Source: https://stackoverflow.com/a/33087217/142358

长伴 2024-12-05 11:25:02

我认为这是不可能的,但您可以使用

UIATarget.localTarget().deactivateAppForDuration(100);

将您的应用程序放在后台一段特定的时间。

I don't think this is possible but you could use

UIATarget.localTarget().deactivateAppForDuration(100);

To put your app in the background for a specific amount time.

涫野音 2024-12-05 11:25:02

在 iOS 中按下设备主页按钮

def hit_home
  home =`osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'keystroke "H" using command down' -e'delay 2' -e'end tell'`
  puts("home button exits - #{home.to_i}")
end

presses device home button in iOS

def hit_home
  home =`osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'keystroke "H" using command down' -e'delay 2' -e'end tell'`
  puts("home button exits - #{home.to_i}")
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文