Skip to content

Commit 6c727ee

Browse files
authored
Added support for launching the local web server for component testing from the android emulator (#3460)
1 parent ab253b9 commit 6c727ee

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

lib/core/client.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,13 @@ class NightwatchClient extends EventEmitter {
443443
}
444444

445445
setLaunchUrl() {
446-
const value = this.settings.baseUrl || this.settings.launchUrl || this.settings.launch_url || null;
446+
let value = this.settings.baseUrl || this.settings.launchUrl || this.settings.launch_url || null;
447+
448+
// For e2e and component testing on android emulator
449+
if (!this.settings.desiredCapabilities.real_mobile && this.settings.desiredCapabilities.avd) {
450+
value = value.replace('localhost', '10.0.2.2').replace('127.0.0.1', '10.0.2.2');
451+
}
452+
447453
this
448454
.setApiProperty('baseUrl', value)
449455
.setApiProperty('launchUrl', value)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const assert = require('assert');
2+
const common = require('../../common.js');
3+
const NightwatchClient = common.require('index.js');
4+
5+
6+
describe('Mobile Component Testing in Android Emulator', function () {
7+
it('test baseUrl - localhost', function(){
8+
const client = NightwatchClient.client({
9+
baseUrl: 'http://localhost:3000',
10+
webdriver: {
11+
start_process: true
12+
},
13+
desiredCapabilities: {
14+
avd: 'nightwatch-android-11',
15+
real_mobile: false
16+
}
17+
});
18+
19+
assert.strictEqual(client.api.baseUrl, 'http://10.0.2.2:3000');
20+
});
21+
22+
it('test baseUrl - 127.0.0.1', function(){
23+
const client = NightwatchClient.client({
24+
baseUrl: 'http://127.0.0.1:3000',
25+
webdriver: {
26+
start_process: true
27+
},
28+
desiredCapabilities: {
29+
avd: 'nightwatch-android-11',
30+
real_mobile: false
31+
}
32+
});
33+
34+
assert.strictEqual(client.api.baseUrl, 'http://10.0.2.2:3000');
35+
});
36+
});

0 commit comments

Comments
 (0)