I have been reading up on Apple's new and improved XCTest/UITesting frameworks and I have some questions as a Android developer. In android, to launch an app that I do not have the source code for to run UiAutomator I would simply use
@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);
}
Using the above code, i am able to launch the package i want then use UiAutomatorView.bat to inspect the elements and get their resource id's (or find by text) then perform operations on them.
In iOS, all of the tutorials that i've found centre on testing apps that you have access to source code for. While I understand that it is much simpler to write these tests in iOS since you simply record the actions you wish to perform and xcode writes the code for you, I am unsure as to how to set the UI Test Target to an app that is currently installed on my device. I watched the WWDC video that went over multi-app testing using this:
var gmailApp: XCUIApplication!
gmailApp.launchArguments = "-StartFromCleanState", "YES"]
gmailApp.launch()
however this will not work since it has no target.
TL;DR: How do I set an app installed on my device, such as gmail, as my UI Test Target, and how do i discover package names in order to launch the app?
Thanks!
I don't believe this is possible unfortunately.