Skip to content

Commit

Permalink
Merge branch 'main' into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Oct 28, 2022
2 parents 322599b + 4eb3228 commit a42e19a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 45 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ansi-colors": "^4.1.3",
"appium-adb": "^9.10.11",
"axios": "^1.1.2",
"boxen": "5.1.2",
"cli-progress": "^3.11.2",
"dotenv": "^16.0.3",
"download": "^8.0.0",
Expand Down
92 changes: 47 additions & 45 deletions src/commands/ios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getPlatformName, iosRealDeviceUUID, symbols } from '../../utils';
import { AVAILABLE_OPTIONS, SETUP_CONFIG_QUES } from './constants';
import colors from 'ansi-colors';
import { execSync } from 'child_process';
import boxen from 'boxen';
import Logger from '../../logger';

export class IosSetup {
options: Options;
Expand All @@ -29,7 +31,7 @@ export class IosSetup {
}

if (this.platform !== 'mac') {
console.log('Only macOS is supported');
Logger.log('Only macOS is supported');
return false;
}

Expand Down Expand Up @@ -75,59 +77,59 @@ export class IosSetup {
const missingRequirements: string[] = [];

if (setupConfigs.mode === 'simulator' || setupConfigs.mode === 'both') {
console.log('\nVerifying the setup requirements for simulators ...');
Logger.log('\nVerifying the setup requirements for simulators ...');

try {
execSync("/usr/bin/xcodebuild -version", {
stdio: 'pipe'
});
console.log(` ${colors.red(symbols().ok)} Xcode is installed in your machine\n`);
Logger.log(` ${colors.red(symbols().ok)} Xcode is installed in your machine\n`);

console.log(`Run the following command to get the list of siulators\n` +
Logger.log(boxen(`Run the following command to get the list of simulators\n` +
colors.cyan.italic('xcrun simctl list devices') + '\n' +
`\nAnd then update ${colors.cyan('safari:deviceName')} (eg: 'iphone 13') and ${colors.cyan('safari:platformVersion')} (eg: '15.0') in nightwatch configuration for ${colors.gray.italic('ios.simulator.safari')} environment accordingly.`
);
, {padding: 1}));
} catch (error) {
console.log(` ${colors.red(symbols().fail)} Xcode is not installed.`);
Logger.log(` ${colors.red(symbols().fail)} Xcode is not installed.`);
missingRequirements.push('Xcode is not installed')
}
}

if (setupConfigs.mode === 'real' || setupConfigs.mode === 'both') {
console.log('\nVerifying the setup requirements for real devices...');
Logger.log('\nVerifying the setup requirements for real devices...');

try {
const stdout = execSync("system_profiler SPUSBDataType | sed -n '/iPhone/,/Serial/p' | grep 'Serial Number:' | awk -F ': ' '{print $2}'", {
stdio: 'pipe'
});

if (stdout.toString() !== '') {
console.log(
Logger.log(boxen(
colors.white(`Update ${colors.cyan('UUID')} in nightwatch configuration for ${colors.gray.italic('ios.real.safari')} environment.`) +
colors.cyan("\nUUID: " + iosRealDeviceUUID(stdout.toString()) + "\n"));
colors.cyan("\nUUID: " + iosRealDeviceUUID(stdout.toString())), {padding: 1}));
} else {
throw "Device is not connected";
}
} catch (error) {
console.log(` ${colors.red(symbols().fail)} Device is either not connected or turned off.`);
Logger.log(` ${colors.red(symbols().fail)} Device is either not connected or turned off.`);
missingRequirements.push('Device is not connected')
}
}

if (missingRequirements.length === 0) {

console.log('\nGreat! All the requirements are being met.');
Logger.log('\nGreat! All the requirements are being met.');

if (setupConfigs.mode === 'real') {
console.log('You can go ahead and run your tests now on your iOS device.');
Logger.log('You can go ahead and run your tests now on your iOS device.');
} else if (setupConfigs.mode === 'simulator') {
console.log('You can go ahead and run your tests now on an iOS simulator.');
Logger.log('You can go ahead and run your tests now on an iOS simulator.');
} else {
console.log('You can go ahead and run your tests now on an iOS device/simulator.');
Logger.log('You can go ahead and run your tests now on an iOS device/simulator.');
}
} else if (!this.options.setup) {
console.log(`\nSome requirements are missing: ${missingRequirements.join(', ')}`);
console.log(`Please use ${colors.magenta('--setup')} flag with the command to install all the missing requirements.`);
Logger.log(`\nSome requirements are missing: ${missingRequirements.join(', ')}`);
Logger.log(`Please use ${colors.magenta('--setup')} flag with the command to install all the missing requirements.`);
}

return missingRequirements;
Expand All @@ -142,55 +144,55 @@ export class IosSetup {

if (setupConfigs.mode === 'simulator' || setupConfigs.mode === 'both') {
if (missingRequirements.includes('Xcode is not installed')) {
console.log('\nSetting up missing requirements for iOS simulator...\n');

console.log(`${colors.cyan(" If Xcode is already installed : ")}` +
`${colors.white("\n 1. Run the following after changing the Xcode app name in the command ")}` +
`\n ${colors.grey.italic("sudo xcode-select -switch /Applications/Xcode_x_x.app")}\n` +

`${colors.cyan("\n If Xcode is not installed : ")}` +
`${colors.green("\n [Easiest Option] : Download via the App Store for the latest version")}` +
`${colors.white("\n 1. Open the App Store on your mac and Sign in with your Apple credentials")}` +
`${colors.white("\n 2. Search for Xcode & click install or update. That's it!!")}\n` +
`${colors.green("\n [Preferred Option] : Download via the Developer site for a specific version")}` +
`${colors.white(`\n 1. Navigate to this URL ${colors.grey.italic("https://developer.apple.com/download/more/")}`)}` +
`${colors.white("\n 2. Sign in with your Apple credentials")}` +
`${colors.white("\n 3. Type in the version that you like, and download the Xcode_x_x.xip file")}` +
`${colors.white("\n 4. Once the file is downloaded, click on .xip to extract it.")}` +
`${colors.white("\n 5. Now click on that Xcode file complete all the installation process")}` +
`${colors.white("\n 6. After completion drag the Xcode to Applications folder")}`);

console.log(`${colors.magenta("\n Follow the guide for more detailed info https://www.freecodecamp.org/news/how-to-download-and-install-xcode/")}\n`);
Logger.log('\nSetting up missing requirements for iOS simulator...');

Logger.log(boxen(`${colors.cyan("If Xcode is already installed : ")}` +
`${colors.white("\n 1. Run the following after changing the Xcode app name in the command ")}` +
`\n ${colors.grey.italic("sudo xcode-select -switch /Applications/Xcode_x_x.app")}\n` +

`${colors.cyan("\nIf Xcode is not installed : ")}` +
`${colors.green("\n [Easiest Option] : Download via the App Store for the latest version")}` +
`${colors.white("\n 1. Open the App Store on your mac and Sign in with your Apple credentials")}` +
`${colors.white("\n 2. Search for Xcode & click install or update. That's it!!")}\n` +
`${colors.green("\n [Preferred Option] : Download via the Developer site for a specific version")}` +
`${colors.white(`\n 1. Navigate to this URL ${colors.grey.italic("https://developer.apple.com/download/more/")}`)}` +
`${colors.white("\n 2. Sign in with your Apple credentials")}` +
`${colors.white("\n 3. Type in the version that you like, and download the Xcode_x_x.xip file")}` +
`${colors.white("\n 4. Once the file is downloaded, click on .xip to extract it.")}` +
`${colors.white("\n 5. Now click on that Xcode file complete all the installation process")}` +
`${colors.white("\n 6. After completion drag the Xcode to Applications folder")}`, {padding: 1}));

Logger.log(`\nFollow the guide for more detailed info ${colors.magenta("https://www.freecodecamp.org/news/how-to-download-and-install-xcode/")}\n`);

result = false;
}
}

if (setupConfigs.mode === 'real' || setupConfigs.mode === 'both') {
console.log('\nSetting up missing requirements for real devices...');
Logger.log("\nSetting up missing requirements for real devices...")

console.log(colors.cyan("\n Remote Automation should be turned on (necessary) ") +
colors.grey.italic("\n (turn it on via Settings → Safari → Advanced → Remote Automation.)"));
let msg = colors.cyan("Remote Automation should be turned on (necessary) ") +
colors.grey.italic("\n(turn it on via Settings → Safari → Advanced → Remote Automation.)");

if (missingRequirements.includes('Device is not connected')) {
console.log(colors.cyan(`\n Make sure your device is connected and turned on properly`));

msg += colors.cyan(`\n\nAlso make sure your device is connected and turned on properly`);
result = false;
}
Logger.log(boxen(msg, {padding: 1}));
}

return result;
}

showHelp(unknownOptions: string[]) {
if (unknownOptions.length) {
console.log(colors.red(`unknown option(s) passed: ${unknownOptions.join(', ')}\n`));
Logger.log(colors.red(`unknown option(s) passed: ${unknownOptions.join(', ')}\n`));
}

console.log(`Usage: ${colors.cyan('npx @nightwatch/mobile-helper ios [options]')}`);
console.log(' Verify if all the requirements are met to run tests on an iOS device/simulator.\n');
Logger.log(`Usage: ${colors.cyan('npx @nightwatch/mobile-helper ios [options]')}`);
Logger.log(' Verify if all the requirements are met to run tests on an iOS device/simulator.\n');

console.log(`${colors.yellow('Options:')}`);
Logger.log(`${colors.yellow('Options:')}`);

const switches = Object.keys(AVAILABLE_OPTIONS).reduce((acc: {[T: string]: string}, key) => {
acc[key] = [key].concat(AVAILABLE_OPTIONS[key].alias || [])
Expand Down Expand Up @@ -224,7 +226,7 @@ export class IosSetup {

const prelude = ' ' + (kswitch) + ' ' + colors.grey(spadding);

console.log(prelude + ' ' + colors.grey(desc));
Logger.log(prelude + ' ' + colors.grey(desc));
});
}

Expand Down

0 comments on commit a42e19a

Please sign in to comment.