Skip to content

Commit

Permalink
Merge branch 'main' of github.com:nightwatchjs/nightwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Nov 3, 2022
2 parents d6e0a34 + 2cd3314 commit 2b908cf
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
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
6 changes: 3 additions & 3 deletions lib/reporter/global-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ module.exports = class GlobalReporter {
});
}

addTestSuiteResults(testResults) {
addTestSuiteResults(testResults, httpOutput) {
testResults = testResults || {};
testResults.httpOutput = Logger.collectOutput().map(item => {
testResults.httpOutput = (httpOutput || Logger.collectOutput()).map(item => {
return [item[0], this.ansiConverter.toHtml(item[1]),
(item[2] ? this.ansiConverter.toHtml(item[2]) : '')];
});
Expand All @@ -71,7 +71,7 @@ module.exports = class GlobalReporter {
if (!Concurrency.isTestWorker()) {
emitter.on('message', data => {
data = JSON.parse(data);
this.addTestSuiteResults(data.results);
this.addTestSuiteResults(data.results, data.httpOutput);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runner/test-runners/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DefaultRunner {
this.addtOpts = addtOpts;
this.publishReport = true; // in-case of an uncaught exception, the report will not be published
this.globalReporter = new GlobalReporter(argv.reporter, settings, {
open: argv.open,
openReport: argv.open,
reportFileName: argv['report-filename']
});
}
Expand Down
3 changes: 2 additions & 1 deletion lib/testsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ class TestSuite {
process.send(SafeJSON.stringify({
type: 'testsuite_finished',
itemKey: process.env.__NIGHTWATCH_ENV_LABEL,
results: this.reporter.exportResults()
results: this.reporter.exportResults(),
httpOutput: Logger.collectOutput()
}));
}

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');
});
});
54 changes: 50 additions & 4 deletions test/src/runner/testReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ describe('testReporter', function() {
if (err) {
return done(err);
}
mockery.enable({useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false});
done();
});
});

// afterEach(function(done) {
// rimraf('output', done);
// });

afterEach(function(done) {
mockery.deregisterAll();
mockery.resetCache();
mockery.disable();
rimraf('output', done);
});


after(function(done) {
this.server.close(function() {
Expand Down Expand Up @@ -94,7 +100,6 @@ describe('testReporter', function() {
});

it('test with valid reporter from NPM', function() {
mockery.enable({useCleanCache: true, warnOnUnregistered: false});
mockery.registerMock('nightwatch_reporter', {
async write(results, options) {

Expand Down Expand Up @@ -174,4 +179,45 @@ describe('testReporter', function() {

assert.strictEqual(possibleError, null);
});

it('test run tests with default reporters - open the html report', async function () {
let htmlFile;

mockery.registerMock('open', function(filename) {
htmlFile = filename;

return Promise.resolve();
});

let possibleError = null;
const testsPath = [path.join(__dirname, '../../sampletests/simple/test/sample.js')];

try {
await runTests({
source: testsPath,
open: true
},
settings({
output_folder: 'output',
globals: {
waitForConditionPollInterval: 20,
waitForConditionTimeout: 50,
retryAssertionTimeout: 50,
reporter: function () {}
},
silent: true,
output: false
}));

await readFilePromise(`output${path.sep}FIREFOX_TEST_firefox__sample.xml`);
await readFilePromise(`output${path.sep}FIREFOX_TEST_firefox__sample.json`);
await readDirPromise(`output${path.sep}nightwatch-html-report`);
} catch (error) {
possibleError = error;
}

assert.strictEqual(possibleError, null);
assert.strictEqual(htmlFile, `output${path.sep}nightwatch-html-report${path.sep}index.html`);

});
});

0 comments on commit 2b908cf

Please sign in to comment.