Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nightwatchjs/nightwatch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.10.2
Choose a base ref
...
head repository: nightwatchjs/nightwatch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.11.0
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 16, 2025

  1. Add option to not load Nightwatch APIs while launching browser. (#4358)

    * Add option to not load Nightwatch APIs while launching browser.
    
    * Add test.
    garg3133 authored Jan 16, 2025

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nowseemee Daniel Beck
    Copy the full SHA
    e4e259d View commit details
  2. Pass local context to browser.debug() command. (#4299)

    * Allow local context to be passed to browser.debug command.
    
    * Improve debug experience.
    garg3133 authored Jan 16, 2025
    Copy the full SHA
    991f79d View commit details
  3. v3.11.0

    garg3133 committed Jan 16, 2025
    Copy the full SHA
    97a94df View commit details
Showing with 110 additions and 13 deletions.
  1. +19 −5 lib/api/client-commands/debug.js
  2. +4 −2 lib/core/client.js
  3. +2 −2 lib/index.js
  4. +1 −1 lib/testsuite/repl.js
  5. +2 −2 package-lock.json
  6. +1 −1 package.json
  7. +81 −0 test/src/index/testProgrammaticApis.js
24 changes: 19 additions & 5 deletions lib/api/client-commands/debug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const EventEmitter = require('events');
const NightwatchRepl = require('../../testsuite/repl');
const Debuggability = require('../../utils/debuggability.js');
const {By} = require('selenium-webdriver');

/**
* This command halts the test execution and provides users with a REPL interface where they can type
@@ -37,24 +38,37 @@ class Debug extends EventEmitter {
}

command(config, callback) {
// Create context for vm
const context = {
browser: this.api,
app: this.api,
by: By,
By: By
};

// set the user provided context
if (config.context) {
Object.assign(context, config.context);
delete config.context;
}

const repl = new NightwatchRepl(config);

// eslint-disable-next-line
console.log(NightwatchRepl.introMessage());

// Create context for vm
const context = {
browser: this.api,
app: this.api
};
// TODO: what's the use of this `if` block?
if (config?.selector) {
this.api.executeScript('console.log("Element ' + config.selector + ':", document.querySelector("' + config.selector + '"))');
}

// Before starting REPL server, Set debugMode to true
Debuggability.debugMode = true;

// Set isES6AsyncTestcase to true in debugmode
const isES6AsyncTestcase = this.client.isES6AsyncTestcase;
this.client.isES6AsyncTestcase = true;

repl.startServer(context);

repl.onExit(() => {
6 changes: 4 additions & 2 deletions lib/core/client.js
Original file line number Diff line number Diff line change
@@ -680,10 +680,12 @@ class NightwatchClient extends EventEmitter {
// Initialize the APIs
//////////////////////////////////////////////////////////////////////////////////////////

async initialize() {
async initialize(loadNightwatchApis = true) {
this.loadKeyCodes();

return this.loadNightwatchApis();
if (loadNightwatchApis) {
return this.loadNightwatchApis();
}
}

setCurrentTest() {
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -142,10 +142,10 @@ module.exports.createClient = function({
return cliRunner.globals.runGlobalHook('after', [client.settings]);
},

launchBrowser() {
launchBrowser({loadNightwatchApis = true} = {}) {
const {argv} = cliRunner;

return client.initialize()
return client.initialize(loadNightwatchApis)
.then(() => {
return client.createSession({argv});
})
2 changes: 1 addition & 1 deletion lib/testsuite/repl.js
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ module.exports = class NightwatchRepl {
}

async _handleResult(result, callback) {
const resultIsPromise = result instanceof Promise;
const resultIsPromise = result instanceof Promise || (result && typeof result.then === 'function');

if (!resultIsPromise) {
return callback(null, result);
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nightwatch",
"description": "Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.",
"version": "3.10.2",
"version": "3.11.0",
"author": "Andrei Rusu",
"homepage": "https://nightwatchjs.org",
"main": "./lib/index.js",
81 changes: 81 additions & 0 deletions test/src/index/testProgrammaticApis.js
Original file line number Diff line number Diff line change
@@ -882,4 +882,85 @@ describe('test programmatic apis', function () {
CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});

it('test multiple calls to launchBrowser() on same client', async function() {
const CliRunner = common.require('runner/cli/cli.js');
const Nightwatch = common.require('index.js');
MockServer.createChromeSession({sessionId: '12345678'});
MockServer.createChromeSession({sessionId: '87654321'});

const defaultConfig = {
test_settings: {
default: {
launchUrl: 'http://localhost'
},

chrome: {
desiredCapabilities: {
browserName: 'chrome'
}
}
},
selenium: {
port: 10195,
start_process: false
},
selenium_host: 'localhost'
};

const createDefaultConfig = CliRunner.createDefaultConfig;
const loadConfig = CliRunner.prototype.loadConfig;

CliRunner.createDefaultConfig = function(destFileName) {
return defaultConfig;
};

CliRunner.prototype.loadConfig = function () {
return defaultConfig;
};

const clientChrome = Nightwatch.createClient({
browserName: 'chrome',
headless: true
});

const session = await clientChrome.launchBrowser();

assert.strictEqual(session.sessionId, '12345678');
assert.strictEqual(session.options.webdriver.port, 10195);
assert.deepStrictEqual(session.capabilities, {
acceptInsecureCerts: false,
browserName: 'chrome',
browserVersion: '90'
});

await session.end();
assert.strictEqual(session.sessionId, null);

let launchBrowserError;
try {
await clientChrome.launchBrowser();
} catch (err) {
launchBrowserError = err;
}
assert.notStrictEqual(launchBrowserError, undefined);
assert.strictEqual(launchBrowserError.message.includes('Error while loading the API commands'), true);

const session2 = await clientChrome.launchBrowser({loadNightwatchApis: false});

assert.strictEqual(session2.sessionId, '87654321');
assert.strictEqual(session2.options.webdriver.port, 10195);
assert.deepStrictEqual(session2.capabilities, {
acceptInsecureCerts: false,
browserName: 'chrome',
browserVersion: '90'
});

await session2.quit();
// TODO: calling `.quit()` does not clear the sessionId
assert.notStrictEqual(session2.sessionId, null);

CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});
});