.elements function is working fine in "nightwatch" context and I'm able to get rows count of the table
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);
}
};
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');
Given(/^click "([^"]*)" service from list$/, async function (service) {
const homepage = client.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);
});
Error : TypeError: Cannot read property 'value' of undefined
Any idea how can I make it work with nightwatch-api and cucumber, Thanks!
My Doubt was right. Nightwatch Browser object and Nightwatch-API client are different.... Here is the proof.
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(" NightWatch Obj Row Length is " + "<->" + result.value.length);
console.log("<<===================>>");
const { client } = require('nightwatch-api');
const { createSession, closeSession, startWebDriver, stopWebDriver } = require('nightwatch-api');
await createSession();
const homePage1 = client.page.homepage();
homePage1.navigate();
let result1 = await homePage1.api.elements('css selector', 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody > tr');
console.log(" Nightwatch API Obj Row length is " + "<->" + result1.value.length);
await closeSession();
}
};
Output is ::
NightWatch Obj Row Length is <->10
<<===================>>
FAILED: 1 errors (6.392s)
TypeError: Cannot read property 'value' of undefined
at Object.demo test (C:\Users\tajisingh\workspace\dashboard-ui-automation\Tests\dashboard.js:40:70)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
_________________________________________________
Wondering if anyone know how can we obtain browser object or something similar from nightwatch-api... thanks!