gpt4 book ai didi

ios - 如何在我没有源代码的应用程序上执行 UITesting?

转载 作者:可可西里 更新时间:2023-11-01 00:56:48 24 4
gpt4 key购买 nike

我一直在阅读 Apple 新的和改进的 XCTest/UITesting 框架,作为 Android 开发人员我有一些问题。在 android 中,要启动一个我没有源代码来运行 UiAutomator 的应用程序,我只需使用

@Before
public void setup() {
//Init UiDevice instance
Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(mInstrumentation);

//start from home screen on each new test
mDevice.pressHome();

//wait for launcher
final String launcherPackage = mDevice.getLauncherPackageName();
assertThat(launcherPackage, notNullValue());
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

//launch app
Context mContext = InstrumentationRegistry.getContext();
final Intent intent = mContext.getPackageManager()
.getLaunchIntentForPackage(GMAIL_APP_PACKAGE);

//Clear any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
mContext.startActivity(intent);

//wait for app to appear
mDevice.wait(Until.hasObject(By.pkg(GMAIL_APP_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
mDevice.waitForWindowUpdate(null, 5000);
}

使用上面的代码,我可以启动我想要的包,然后使用 UiAutomatorView.bat 检查元素并获取它们的资源 ID(或通过文本查找),然后对它们执行操作。

在 iOS 中,我找到的所有教程都以测试您有权访问其源代码的应用程序为中心。虽然我知道在 iOS 中编写这些测试要简单得多,因为您只需记录您希望执行的操作并且 xcode 会为您编写代码,但我不确定如何将 UI 测试目标设置为当前正在运行的应用程序安装在我的设备上。我观看了使用此进行多应用程序测试的 WWDC 视频:

var gmailApp: XCUIApplication!
gmailApp.launchArguments = "-StartFromCleanState", "YES"]
gmailApp.launch()

但是这不会起作用,因为它没有目标。

TL;DR:如何将安装在我的设备上的应用程序(例如 gmail)设置为我的 UI 测试目标,以及如何发现包名称以启动该应用程序?

谢谢!

最佳答案

不幸的是,我认为这是不可能的。

关于ios - 如何在我没有源代码的应用程序上执行 UITesting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45469481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com