Unable to use async/await with mocha runner #2549
Replies: 11 comments
-
There an issue with your code or documentation. browser.url('https://nightwatchjs.org/');
browser.waitForElementVisible('.btn-download', 10000);
//taken from https://nightwatchjs.org/api/getWindowSize.html
const value = await browser.getWindowSize();
console.log('value', value);
console.log('value', value.value); Output: Running: Dummy
√ Element <.btn-download> was visible after 63 milliseconds.
value { height: 1020, width: 945 }
value undefined |
Beta Was this translation helpful? Give feedback.
-
Apologies should be the below, edited the original too.
Output |
Beta Was this translation helpful? Give feedback.
-
Give console log in callback (if get window size defines)
pt., 27 lis 2020, 19:58 użytkownik MancLad89 <[email protected]>
napisał:
… Apologies should be the below, edited the original too.
describe('mocha test', async function() {
it('async/await test', async function (browser) {
browser.url('https://nightwatchjs.org/');
browser.waitForElementVisible('.btn-download', 10000);
//taken from https://nightwatchjs.org/api/getWindowSize.html
const value = await browser.getWindowSize();
console.log('value:', value);
});
});
Output
value: undefined
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/nightwatchjs/nightwatch/issues/2549#issuecomment-734953972>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMUVMH53R7REY3A5D2PMHRDSR7ZGVANCNFSM4UECNMXA>
.
|
Beta Was this translation helpful? Give feedback.
-
Apologies not sure what you mean by this? |
Beta Was this translation helpful? Give feedback.
-
Just to check ...getWindowSize(function(result) {
Console.log(result.value)
}
I don't use micha runner but I wonder if it helps
pt., 27 lis 2020, 19:58 użytkownik MancLad89 <[email protected]>
napisał:
… Apologies should be the below, edited the original too.
describe('mocha test', async function() {
it('async/await test', async function (browser) {
browser.url('https://nightwatchjs.org/');
browser.waitForElementVisible('.btn-download', 10000);
//taken from https://nightwatchjs.org/api/getWindowSize.html
const value = await browser.getWindowSize();
console.log('value:', value);
});
});
Output
value: undefined
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/nightwatchjs/nightwatch/issues/2549#issuecomment-734953972>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMUVMH53R7REY3A5D2PMHRDSR7ZGVANCNFSM4UECNMXA>
.
|
Beta Was this translation helpful? Give feedback.
-
The below works but trying to using async/await and avoid callbacks.
Output:
|
Beta Was this translation helpful? Give feedback.
-
Please try
await console.log()
pt., 27 lis 2020, 20:22 użytkownik MancLad89 <[email protected]>
napisał:
… The below works but trying to using async/await and avoid callbacks.
browser.getWindowSize(function(value) {
console.log(value);
});
Output:
{
width: 1920,
hCode: 30720,
class: 'org.openqa.selenium.Dimension',
height: 1080
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/nightwatchjs/nightwatch/issues/2549#issuecomment-734959753>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMUVMH6GH7FBF3C2DIAT3HLSR737TANCNFSM4UECNMXA>
.
|
Beta Was this translation helpful? Give feedback.
-
Before the test you can set variable visible in scope of the test file and
callback would set it so that it was defined at console.log I guess. Unless
async/awaits dont work with mocha
pt., 27 lis 2020, 19:58 użytkownik MancLad89 <[email protected]>
napisał:
… Apologies should be the below, edited the original too.
describe('mocha test', async function() {
it('async/await test', async function (browser) {
browser.url('https://nightwatchjs.org/');
browser.waitForElementVisible('.btn-download', 10000);
//taken from https://nightwatchjs.org/api/getWindowSize.html
const value = await browser.getWindowSize();
console.log('value:', value);
});
});
Output
value: undefined
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/nightwatchjs/nightwatch/issues/2549#issuecomment-734953972>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMUVMH53R7REY3A5D2PMHRDSR7ZGVANCNFSM4UECNMXA>
.
|
Beta Was this translation helpful? Give feedback.
-
@Pieras2 I have provided a simple async/await example but have much more complex cases and doing what you suggest it would be easier to write in callback fashion. Which is not something I am looking to do/can't do it some cases. The purpose of this bug report is I believe to point out async/await does not work with a mocha test runner. |
Beta Was this translation helpful? Give feedback.
-
Exactly the same code works ok with default runner. Must be mocka runner issue. |
Beta Was this translation helpful? Give feedback.
-
@pawlakmaly, agreed works with default runner. Issue looks specific to mocha test runner. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Hi,
I am trying to use the mocha as the test runner as per the guide here
However it seems I am unable to use async/await with mocha runner as I cannot access the the result of the promise.
The promise resolves but when logging or trying to use the result of the promise
undefined
is returned.However when ran with
--verbose
the promise does look to resolve but I cannot access the result.If any other information is required do let me know.
Response when ran with
--verbose
:Sample test
sampleTest.js
Run with command
Verbose output
debug.log
Configuration
nightwatch.json
nightwatch_config = { //global paths src_folders : [ "tests" ],
};
// Code to support common capabilites
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
config['selenium_host'] = nightwatch_config.selenium.host;
config['selenium_port'] = nightwatch_config.selenium.port;
config['desiredCapabilities'] = config['desiredCapabilities'] || {};
for(var j in nightwatch_config.common_capabilities){
config['desiredCapabilities'][j] = config['desiredCapabilities'][j] || nightwatch_config.common_capabilities[j];
}
}
module.exports = nightwatch_config;
Your Environment
nightwatch --version
npm --version
yarn --version
node --version
Beta Was this translation helpful? Give feedback.
All reactions