Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created August 12, 2020 21:06
Show Gist options
  • Save colinfwren/da0abfbdafc991970caf5952991082a9 to your computer and use it in GitHub Desktop.
Save colinfwren/da0abfbdafc991970caf5952991082a9 to your computer and use it in GitHub Desktop.
Launching the Expo Client on iOS
import {remote} from "webdriverio";
const capabilities = {
platformName: 'iOS',
platformVersion: '13.6',
deviceName: 'DEVICE_NAME', // Change this to the device you want to run
automationName: 'XCUITest',
bundleId: 'com.apple.mobilesafari',
autoAcceptAlerts: true,
};
const options = {
path: '/wd/hub/',
port: 4723,
};
async function expoDeepLink13_6(client) {
const urlFieldSelector = 'label == "Address"';
const urlField = await client.$(`-ios predicate string:${ urlFieldSelector }`);
await urlField.setValue('exp://127.0.0.1:19000/\uE007');
}
async function handleFirstLaunch(client) {
try {
const gotItSelector = 'label == "Got it"';
const gotIt = await client.$(`-ios predicate string:${gotItSelector}`);
await gotIt.click();
const reloadSelector = 'type == \'XCUIElementTypeOther\' && name CONTAINS \'Reload\'';
const reload = await client.$(`-ios predicate string:${ reloadSelector }`);
await reload.click();
} catch (err) {
console.log('No need to handle first launch');
}
}
async function reloadExpo(client) {
await client.shake();
const reloadSelector = 'type == \'XCUIElementTypeOther\' && name CONTAINS \'Reload\'';
const reload = await client.$(`-ios predicate string:${ reloadSelector }`);
await reload.click();
}
async function launchExpoIOS() {
const client = await remote({ ...options, capabilities});
await client.execute('mobile: launchApp', { bundleId: 'com.apple.mobilesafari' });
await expoDeepLink13_6(client);
await handleFirstLaunch(client);
await reloadExpo(client);
return client;
}
describe('Example Test', () => {
let client;
beforeAll(async () => {
client = await launchExpoIOS();
});
afterAll(async () => {
await client.deleteSession();
});
// Add tests here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment