Support idb/physical devices for navigation

Summary: idb has a command for doing the same now.

Reviewed By: timur-valiev

Differential Revision: D30277192

fbshipit-source-id: eb46cdc7a7218077a7da90f6182d5f17bfcc758a
This commit is contained in:
Pascal Hartig
2021-08-12 07:58:30 -07:00
committed by Facebook GitHub Bot
parent dd47d08444
commit 87e5e18c46
3 changed files with 39 additions and 2 deletions

View File

@@ -69,8 +69,10 @@ export default class IOSDevice extends BaseDevice {
} }
navigateToLocation(location: string) { navigateToLocation(location: string) {
const command = `xcrun simctl openurl ${this.serial} "${location}"`; return this.iOSBridge.navigate(this.serial, location).catch((err) => {
exec(command); console.warn(`Failed to navigate to location ${location}:`, err);
return err;
});
} }
startLogging() { startLogging() {

View File

@@ -27,6 +27,7 @@ export interface IOSBridge {
deviceType: DeviceType, deviceType: DeviceType,
) => child_process.ChildProcessWithoutNullStreams; ) => child_process.ChildProcessWithoutNullStreams;
screenshot: (serial: string) => Promise<Buffer>; screenshot: (serial: string) => Promise<Buffer>;
navigate: (serial: string, location: string) => Promise<void>;
} }
async function isAvailable(idbPath: string): Promise<boolean> { async function isAvailable(idbPath: string): Promise<boolean> {
@@ -119,6 +120,20 @@ export async function idbScreenshot(serial: string): Promise<Buffer> {
return runScreenshotCommand(command, imagePath); return runScreenshotCommand(command, imagePath);
} }
export async function xcrunNavigate(
serial: string,
location: string,
): Promise<void> {
exec(`xcrun simctl io ${serial} launch url "${location}"`);
}
export async function idbNavigate(
serial: string,
location: string,
): Promise<void> {
exec(`idb open --udid ${serial} "${location}"`);
}
export async function makeIOSBridge( export async function makeIOSBridge(
idbPath: string, idbPath: string,
isXcodeDetected: boolean, isXcodeDetected: boolean,
@@ -129,6 +144,7 @@ export async function makeIOSBridge(
return { return {
startLogListener: idbStartLogListener.bind(null, idbPath), startLogListener: idbStartLogListener.bind(null, idbPath),
screenshot: idbScreenshot, screenshot: idbScreenshot,
navigate: idbNavigate,
}; };
} }
@@ -137,6 +153,7 @@ export async function makeIOSBridge(
return { return {
startLogListener: xcrunStartLogListener, startLogListener: xcrunStartLogListener,
screenshot: xcrunScreenshot, screenshot: xcrunScreenshot,
navigate: xcrunNavigate,
}; };
} }

View File

@@ -116,3 +116,21 @@ test.unix('uses idb to take screenshots when available', async () => {
'idb screenshot --udid deadbeef /temp/00000000-0000-0000-0000-000000000000.png', 'idb screenshot --udid deadbeef /temp/00000000-0000-0000-0000-000000000000.png',
); );
}); });
test('uses xcrun to navigate with no idb when xcode is detected', async () => {
const ib = await makeIOSBridge('', true);
ib.navigate('deadbeef', 'fb://dummy');
expect(exec).toHaveBeenCalledWith(
'xcrun simctl io deadbeef launch url "fb://dummy"',
);
});
test('uses idb to navigate when available', async () => {
const ib = await makeIOSBridge('/usr/local/bin/idb', true, async (_) => true);
ib.navigate('deadbeef', 'fb://dummy');
expect(exec).toHaveBeenCalledWith('idb open --udid deadbeef "fb://dummy"');
});