Javascript 异步方法中的量角器计数表行

Javascript 异步方法中的量角器计数表行,javascript,jasmine,protractor,Javascript,Jasmine,Protractor,我正试图用量角器数一数表中的行。下面是我的代码 this.rowNumbersInFileMatches = async function () { expect(await locator.Student_List_Table.isPresent()).toBeTruthy(); // This is test using conventional .then function $$('#studentListTable > tbody > tr').th

我正试图用量角器数一数表中的行。下面是我的代码

this.rowNumbersInFileMatches = async function () {
    expect(await locator.Student_List_Table.isPresent()).toBeTruthy();

   // This is test using conventional .then function

    $$('#studentListTable > tbody > tr').then(function(Rows){

        R1 = Rows.length;
        console.log('Number of Rows in Then Method' + R1);

    });

    //This is using async await

    let R2 = $$('#studentListTable > tbody > tr');
    console.log('\n*** Number of Rows in the table is : ' + await R2.length);

};
当脚本执行.then块时,它会正确标识行并返回行数,但当使用async await函数时,它返回未定义的行数

以下是相关日志:

Started
..Total number of records to be shown: 2
.
*** Number of Rows in the table is : undefined
Number of Rows in Then Method2

如何在async await方法中修复此问题?我试图完全避免.then函数。

$$
元素的别名。all
返回一个对象,该对象具有方法。因此,您的代码可以像这样重写

const items = $$('#studentListTable > tbody > tr');
const countOfItems = await items.count();