Skip to content

Commit f2199ff

Browse files
harshit-bsgarg3133
andauthored
README for iOS and fix uuid -> udid (#4)
Co-authored-by: Priyansh Garg <[email protected]>
1 parent 9915f07 commit f2199ff

File tree

3 files changed

+110
-9
lines changed

3 files changed

+110
-9
lines changed

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Official Nightwatch helper-tool to easily setup all the requirements needed to g
2626
// other envs above this line
2727
'android.chrome': {
2828
desiredCapabilities: {
29+
real_mobile: false,
30+
avd: 'nightwatch-android-11',
2931
browserName: 'chrome',
3032
'goog:chromeOptions': {
3133
w3c: true,
@@ -53,6 +55,8 @@ Official Nightwatch helper-tool to easily setup all the requirements needed to g
5355

5456
'android.firefox': {
5557
desiredCapabilities: {
58+
real_mobile: false,
59+
avd: 'nightwatch-android-11',
5660
browserName: 'firefox',
5761
acceptInsecureCerts: true,
5862
'moz:firefoxOptions': {
@@ -80,6 +84,8 @@ Official Nightwatch helper-tool to easily setup all the requirements needed to g
8084
7. If testing on real-device:
8185
1. Make sure latest version of Chrome/Firefox browsers are installed. If not, install them from Google Play Store.
8286
2. [Turn on USB Debugging](https://developer.android.com/studio/debug/dev-options#enable) on your Android Device and connect it to your system via data cable.
87+
3. Set `real_mobile` capability to true in the configuration.
88+
8389
8. If testing on emulator, make sure `chromedriver-mobile/chromedriver` is present in your Nightwatch project's root dir. If not present, re-run the command in first step.
8490
9. Run your nightwatch tests on Android mobile browsers:
8591
```sh
@@ -88,3 +94,97 @@ Official Nightwatch helper-tool to easily setup all the requirements needed to g
8894
# for chrome
8995
npx nightwatch --env android.chrome
9096
```
97+
98+
### iOS
99+
100+
1. From your [Nightwatch](https://nightwatch.org) project's root dir, run:
101+
102+
```sh
103+
npx @nightwatch/mobile-helper ios
104+
```
105+
2. Answer a device related question:
106+
107+
<img width="352" alt="image" src="https://user-images.githubusercontent.com/94462364/199410412-e40da151-e545-4039-90db-e68697358665.png">
108+
109+
110+
3. It will verify if all the requirements are being met.
111+
4. If some requirements are not being met, follow the guide to setup those requirements.
112+
113+
<img width="662" alt="image" src="https://user-images.githubusercontent.com/94462364/199419711-43e7793a-df82-4d67-a832-679eb5c1f7b9.png">
114+
115+
116+
5. Great :tada: Your setup is now complete. (Re-run the command in the first step to verify.)
117+
118+
6. Add the following env configuration to your `nightwatch.conf.js` or `nightwatch.json` file:
119+
```js
120+
"test_settings": {
121+
// other envs above this line
122+
'ios.real.safari': {
123+
desiredCapabilities: {
124+
browserName: 'safari',
125+
platformName: 'iOS',
126+
// add the device UDID to run tests on (necessary)
127+
// Run command: `xcrun simctl list devices`
128+
// 'safari:deviceUDID': '00008030-00024C2C3453402E',
129+
},
130+
131+
webdriver: {
132+
start_process: true,
133+
server_path: '',
134+
cli_args: [
135+
// --verbose
136+
]
137+
}
138+
},
139+
140+
'ios.simulator.safari': {
141+
desiredCapabilities: {
142+
browserName: 'safari',
143+
platformName: 'iOS',
144+
'safari:useSimulator': true,
145+
// change the deviceName, platformVersion accordingly to run tests on
146+
// Run command: `xcrun simctl list devices`
147+
// 'safari:platformVersion': '15.0',
148+
'safari:deviceName': 'iPhone 13'
149+
},
150+
151+
webdriver: {
152+
start_process: true,
153+
server_path: '',
154+
cli_args: [
155+
// --verbose
156+
]
157+
}
158+
},
159+
}
160+
```
161+
7. (**Real Device**) Run the following command to get the *UDID*:
162+
```sh
163+
system_profiler SPUSBDataType | sed -n '/iPhone/,/Serial/p' | grep 'Serial Number:' | awk -F ': ' '{print $2}'
164+
```
165+
166+
8. (**Optional**) Update the configurations :
167+
168+
**Real Device**
169+
170+
Set `safari:deviceUDID` capability to *UDID* from the previous step, in your Nightwatch configuration for `ios.real.safari` environment.
171+
172+
**Simulators**
173+
174+
Run the following command to get a list of simulators:
175+
```sh
176+
xcrun simctl list devices
177+
```
178+
And then update `safari:deviceName` (eg: 'iphone 13') and `safari:platformVersion` (eg: '15.0') in your Nightwatch configuration for `ios.simulator.safari` environment according to your preference.
179+
180+
181+
8. Run your nightwatch tests on Android mobile browsers:
182+
```sh
183+
# for simulators
184+
npx nightwatch --env ios.simulator.safari
185+
186+
# for real device
187+
npx nightwatch --env ios.real.safari --udid <YOUR-DEVICE-UDID>
188+
# for real device (if updated the config in the previous step)
189+
npx nightwatch --env ios.real.safari
190+
```

src/commands/ios/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prompt } from 'inquirer';
22
import { Options, SetupConfigs, IosSetupResult } from './interfaces';
3-
import { getPlatformName, iosRealDeviceUUID, symbols } from '../../utils';
3+
import { getPlatformName, iosRealDeviceUDID, symbols } from '../../utils';
44
import { AVAILABLE_OPTIONS, SETUP_CONFIG_QUES } from './constants';
55
import colors from 'ansi-colors';
66
import { execSync } from 'child_process';
@@ -105,8 +105,9 @@ export class IosSetup {
105105

106106
if (stdout.toString() !== '') {
107107
Logger.log(boxen(
108-
colors.white(`Update ${colors.cyan('UUID')} in nightwatch configuration for ${colors.gray.italic('ios.real.safari')} environment.`) +
109-
colors.cyan("\nUUID: " + iosRealDeviceUUID(stdout.toString())), {padding: 1}));
108+
colors.white(`Update ${colors.cyan('UDID')} in nightwatch configuration for ${colors.gray.italic('ios.real.safari')} environment.`) +
109+
"\nUDID: " +
110+
colors.cyan(iosRealDeviceUDID(stdout.toString())), {padding: 1}));
110111
} else {
111112
throw "Device is not connected";
112113
}
@@ -171,11 +172,11 @@ export class IosSetup {
171172
if (setupConfigs.mode === 'real' || setupConfigs.mode === 'both') {
172173
Logger.log("\nSetting up missing requirements for real devices...")
173174

174-
let msg = colors.cyan("Remote Automation should be turned on (necessary) ") +
175+
let msg = colors.cyan("1. Remote Automation should be turned on your iOS device.") +
175176
colors.grey.italic("\n(turn it on via Settings → Safari → Advanced → Remote Automation.)");
176177

177178
if (missingRequirements.includes('Device is not connected')) {
178-
msg += colors.cyan(`\n\nAlso make sure your device is connected and turned on properly`);
179+
msg += colors.cyan(`\n\n2. Device is connected via data cable and turned on properly.`);
179180
result.real = false;
180181
}
181182
Logger.log(boxen(msg, {padding: 1}));

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ export const rmDirSync = (dirPath: string) => {
6464
}
6565
};
6666

67-
export const iosRealDeviceUUID = (uuid: string) => {
68-
if (uuid.length > 25) {
69-
return uuid;
67+
export const iosRealDeviceUDID = (udid: string) => {
68+
if (udid.length > 25) {
69+
return udid;
7070
}
7171

72-
return `${uuid.substring(0, 8)}-${uuid.substring(9, 25)}`;
72+
return `${udid.substring(0, 8)}-${udid.substring(9, 25)}`;
7373
};

0 commit comments

Comments
 (0)