Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip - fix(app): add error stack trace #4344

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions examples/tests/ecosia.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ describe('Ecosia.org Demo', function() {
.navigateTo('https://www.ecosia.org/');
});

it('Demo test ecosia.org', function(browser) {
browser
.waitForElementVisible('body')
.assert.titleContains('Ecosia')
.assert.visible('input[type=search]')
.setValue('input[type=search]', 'nightwatch')
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.textContains('.layout__content', 'Nightwatch.js');
it('Demo test ecosia.org', async function(browser) {
// browser
// .waitForElementVisible('body')
// .assert.titleContains('Ecosia')
// .assert.visible('input[type=search]')
// .setValue('input[type=search]', 'nightwatch')
// .assert.visible('button[type=submit]')
// .click('button[type=submit]')
// .assert.textContains('.layout__content', 'Nightwatch.js');

await browser.element.find('.invalid_selector');
});

after(browser => browser.end());
Expand Down
26 changes: 21 additions & 5 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ class ScopedWebElement {
}

async locateElements({parentElement, selector, timeout, retryInterval}) {
process.stderr.write(`\n\nexecuting locateElements\n\nparentElement && parentElement.webElement:${parentElement && parentElement.webElement}\n`);

const createLocateElement = () => {
return parentElement && parentElement.webElement ? function(locator) {
return new Condition('for at least one element to be located ' + locator, function (driver) {
return parentElement.webElement
.then(function (webElement) {
// also takes into consideration if `webElement`
// resolves to a shadow root.
return webElement.findElements(locator);
})
.then(function (elements) {
Expand All @@ -113,9 +113,21 @@ class ScopedWebElement {
};

const locateFn = createLocateElement();
const webElements = await this.driver.wait(locateFn(selector), timeout, null, retryInterval);

return webElements;
try {
// Capture the error at its source
const webElements = await this.driver.wait(locateFn(selector), timeout, null, retryInterval);

return webElements;
} catch (error) {
// Add our context to the error
// Error.captureStackTrace(error);

// Log the complete error stack at this point
process.stderr.write(`\n\nError in locateElements:\n${error.stack}\n\n`);

throw error; // Re-throw to maintain the chain
}
}

async findElementUsingRecursion({parentElement, recursiveElement, timeout, retryInterval}) {
Expand All @@ -142,6 +154,7 @@ class ScopedWebElement {
}

async findElement({parentElement, selector, index, timeout, retryInterval}) {
process.stderr.write('\n\nexecuting findElement\n\n');
const webElements = await this.locateElements({parentElement, selector, timeout, retryInterval});

if (webElements.length === 0) {
Expand Down Expand Up @@ -173,6 +186,7 @@ class ScopedWebElement {
return null;
}

process.stderr.write(`parentElement: ${JSON.stringify(parentElement)}\ncondition: ${condition.usingRecursion}\n`);
try {
if (condition.usingRecursion) {
return await this.findElementUsingRecursion({parentElement, recursiveElement: condition, timeout, retryInterval});
Expand Down Expand Up @@ -350,11 +364,13 @@ class ScopedWebElement {
return this.webElement.then(onFulfilled, onRejected);
}
}

function createNarrowedError({error, condition, timeout}) {
if (error.name === 'TimeoutError') {
const err = new Error(`Timed out while waiting for element "${condition}" to be present for ${timeout} milliseconds.`);
err.name = 'NoSuchElementError';
process.stderr.write(`error.stack: ${error.stack}\n\n\n\n\nhijk\n\n`);
process.stderr.write(`err.stack: ${err.stack}\n\n\n\n\nlmno\n\n`);
err.stack = error.stack;

return err;
}
Expand Down