Closed tajinders closed 3 years ago
On quick look you miss await statements. Every command like navigate is async so you have to await it. Please let me know if the issue persists even after adding missing awaits
Also you trying to get the result in wrong place. You get result in callback. Not as result of await
I know its strange. But the reason for that that this is the api of original nightwatch
So this below is not working and result is undefined.
Given(/^I open dashboard page$/, async function () {
const { client } = require('nightwatch-api'); const homepage = client.page.homepage(); await homepage.navigate(); let result = await homepage.api.elements('css selector', 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody > tr'); console.log(" row length is " + "<->" + result.value.length); }); -- output : result is undefined
I agree that If I get result with in callback it will work, but then this behavior is not consistent with nightwatch. Also, its not a good practice to use await with callbacks, kind of defeats the overall purpose of async/await.
Below is an example code from nightwatch and it works perfectly fine!! No callbacks needed and my "nightwatch": version is "1.3.4"
module.exports = { async 'demo test'(browser) { const homePage = browser.page.homepage(); homePage.navigate(); let result = await homePage.api.elements('css selector', 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody > tr'); console.log(" row length is " + "<->" + result.value.length); } };
If possible please fix this issue with nightwatch-api, its impacting the way how I want to use async/await in my code, thanks!
Hi @tajinders was there any update on this?
.elements is not working in the Given/Then step methods of cucumber when call with “nightwatch-api” context/client
Output : row length is <->10 However the same code is not working when I try to use it within the Given/Then methods of cucumber with "nightwatch-api" context.
const { client } = require('nightwatch-api'); const { Given, Then, When } = require('cucumber');
Error : TypeError: Cannot read property 'value' of undefined Any idea how can I make it work with nightwatch-api and cucumber, Thanks!
Link to Stack overflow : https://stackoverflow.com/questions/60468313/elements-is-not-working-in-the-given-then-step-methods-of-cucumber-when-call-wi