Javascript .elements在使用“调用”时在cucumber的给定/然后步骤方法中不起作用;夜视api“;上下文/客户端

Javascript .elements在使用“调用”时在cucumber的给定/然后步骤方法中不起作用;夜视api“;上下文/客户端,javascript,cucumber,nightwatch.js,Javascript,Cucumber,Nightwatch.js,.elements函数在“nightwatch”上下文中运行良好,我能够获得表的行数 module.exports = { async 'demo test'(browser) { const homePage = browser.page.homepage(); homePage.navigate(); let result = await homePage.api.elements('css selector', 'div.flex.m

.elements函数在“nightwatch”上下文中运行良好,我能够获得表的行数

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);
    }
};
module.exports={
异步“演示测试”(浏览器){
const homePage=browser.page.homePage();
首页.导航();
让结果=等待homePage.api.elements('css选择器','div.flex.mt-4.v-card.v-sheet.theme--light>div>div>table>tbody>tr');
log(“行长度为“+”+result.value.length);
}
};
输出:行长度为10

但是,当我尝试在cucumber的给定/Then方法中使用“nightwatch api”上下文时,相同的代码不起作用

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);
  });
const{client}=require('nightwatch-api');
const{Given,When}=require('cumber');
给定(/^单击列表中的“([^”]*)”服务$/,异步函数(服务){
const homepage=client.page.homepage();
首页.导航();
让结果=等待homepage.api.elements('css选择器','div.flex.mt-4.v-card.v-sheet.theme--light>div>div>table>tbody>tr');
log(“行长度为“+”+result.value.length);
});
错误: TypeError:无法读取未定义的属性“值”

你知道我该如何使用夜视api和cucumber,谢谢

我的怀疑是对的。Nightwatch浏览器对象和Nightwatch API客户端是不同的……这就是证据

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();

    }

};
module.exports={
异步“演示测试”(浏览器){
const homePage=browser.page.homePage();
首页.导航();
让结果=等待homePage.api.elements('css选择器','div.flex.mt-4.v-card.v-sheet.theme--light>div>div>table>tbody>tr');
log(“NightWatch Obj行长度为“+”+result.value.Length);
控制台日志(“”);
const{client}=require('nightwatch-api');
const{createSession、closeSession、startWebDriver、stopWebDriver}=require('nightwatch-api');
等待createSession();
const homePage1=client.page.homepage();
homePage1.navigate();
让result1=wait homePage1.api.elements('css选择器','div.flex.mt-4.v-card.v-sheet.theme--light>div>div>table>tbody>tr');
log(“Nightwatch API Obj行长度为“+”+result1.value.length);
等待关闭会话();
}
};
输出为:

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)
_________________________________________________
NightWatch Obj行长度为10
失败:1个错误(6.392s)
TypeError:无法读取未定义的属性“值”
在Object.demo测试中(C:\Users\tajisingh\workspace\dashboard ui automation\Tests\dashboard.js:40:70)
在处理和拒绝时(内部/process/task_queues.js:97:5)
_________________________________________________

想知道是否有人知道如何从nightwatch api获得浏览器对象或类似的东西…谢谢!

这能回答您的问题吗?我想在变量中得到结果,我不想像您在其他帖子中显示的那样执行回调!我觉得nightwatch浏览器对象与nightwatch api的客户端对象不同,它们是其他都不一样,这就是为什么使用浏览器对象而不是客户端对象时工作正常的原因。好的。我现在理解了您的担忧。让我检查一下是否能够找到解决方案。谢谢,希望我们能一起工作:-)