0

.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!

Tajinder Singh
  • 205
  • 1
  • 5
  • 12
  • Does this answer your question? [client.elements is not working from a step definition using nightwatch-api](https://stackoverflow.com/questions/60459467/client-elements-is-not-working-from-a-step-definition-using-nightwatch-api) – Raju Feb 29 '20 at 19:32
  • I want to get the result in a variable, I don't want to execute callback like the way you showed in other post! – Tajinder Singh Feb 29 '20 at 19:38
  • I feel nightwatch browser object is different then client object of nightwatch-api, they both are not same thats why things are working fine with browser object and not with client object. – Tajinder Singh Feb 29 '20 at 19:40
  • Alright. I understood your concern now. Let me check if I am able to find a solution to this. – Raju Feb 29 '20 at 19:44
  • Thanks, hope we get it work together :-) – Tajinder Singh Feb 29 '20 at 19:47
  • My Doubt is right. Nightwatch Browser object and Nightwatch-API client are different.... I've updated my original post with example... – Tajinder Singh Mar 01 '20 at 01:58
  • Did you try using client for pure nightwatchjs? – Raju Mar 01 '20 at 07:00
  • wondering how to get client object from nightwatch.js? i just know that nightwatch just pass browser object to all functions automatically.... – Tajinder Singh Mar 01 '20 at 14:44
  • I've also tried to create my own browser object from nightwatch.json file and it didnt worked... https://stackoverflow.com/questions/60471945/initclient-nightwatch-typeerror-cannot-read-property-verbose-of-null – Tajinder Singh Mar 01 '20 at 14:47

0 Answers0