Skip to content

Commit

Permalink
Added support for launching the local web server for component testin…
Browse files Browse the repository at this point in the history
…g from the android emulator (#3460)
  • Loading branch information
prudhvi22 committed Nov 1, 2022
1 parent ab253b9 commit 6c727ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,13 @@ class NightwatchClient extends EventEmitter {
}

setLaunchUrl() {
const value = this.settings.baseUrl || this.settings.launchUrl || this.settings.launch_url || null;
let value = this.settings.baseUrl || this.settings.launchUrl || this.settings.launch_url || null;

// For e2e and component testing on android emulator
if (!this.settings.desiredCapabilities.real_mobile && this.settings.desiredCapabilities.avd) {
value = value.replace('localhost', '10.0.2.2').replace('127.0.0.1', '10.0.2.2');
}

this
.setApiProperty('baseUrl', value)
.setApiProperty('launchUrl', value)
Expand Down
36 changes: 36 additions & 0 deletions test/src/index/testMobileComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const assert = require('assert');
const common = require('../../common.js');
const NightwatchClient = common.require('index.js');


describe('Mobile Component Testing in Android Emulator', function () {
it('test baseUrl - localhost', function(){
const client = NightwatchClient.client({
baseUrl: 'http://localhost:3000',
webdriver: {
start_process: true
},
desiredCapabilities: {
avd: 'nightwatch-android-11',
real_mobile: false
}
});

assert.strictEqual(client.api.baseUrl, 'http://10.0.2.2:3000');
});

it('test baseUrl - 127.0.0.1', function(){
const client = NightwatchClient.client({
baseUrl: 'http://127.0.0.1:3000',
webdriver: {
start_process: true
},
desiredCapabilities: {
avd: 'nightwatch-android-11',
real_mobile: false
}
});

assert.strictEqual(client.api.baseUrl, 'http://10.0.2.2:3000');
});
});

0 comments on commit 6c727ee

Please sign in to comment.