簡體   English   中英

無法單擊網格的分頁來驗證某些網格值

[英]Unable to click pagination of grid to verify certain grid values

我正在使用以下方法來驗證表的所有頁面中的某些表數據。 我已經嘗試了所有可能,任何人都可以分享您對此的想法。

以下代碼是我的頁面,

this.isApplicationPresentUsingName = function (name) {

    return this.pgnumCount.count().then(function(num){
        if (num > 0) {
            console.log(num);
            for (var i = 0; i < num; i++) {
                return this.pgnumCount.filter(function(pg){
                    pg.getText().then(function(text){
                       return text.toString()===i.toString();
                   }).then(function(number){
                       number.click();
                }).then(function(){
                this.checkApplication(name).then(function (found) {
                    console.log("Text1");
                return found.length > 0;});
                });
            });
            }
        } else {
            console.log('Pagination not exists');
        }
    });
});

this.checkApplication = function(text){return element.all(by.cssContainingText(“#application-auth-list-2 tbody tr td:first-child”,文本)); };

this.pgnumCount = $$( 'a.ui-分頁程序頁');

我在以下規格中稱呼它,

。期待(appAuth.isApplicationPresentUsingName(的applicationName))toBeFalsy();

我正面臨以下問題,

失敗:無法讀取未定義的屬性“過濾器”

但是我可以將頁面號設置為3,與控制台中的完全匹配。

請幫忙

首先,我將解釋如何執行您的代碼。

this.isApplicationPresentUsingName = function (name) {

return this.pgnumCount.count().then(function (num) {

    //You will get the total number of pages

    if (num > 0) {
        console.log(num);
        for (var i = 0; i < num; i++) {
            //below statement will throw an error because 
            // `this` refers to current function scope.
            return this.pgnumCount.filter(function (pg) {
                // return statement is missing.
                // so the filter wont work
                pg.getText().then(function (text) {
                    // value of i will always equals to num
                    // because this code will be executed asynchronously
                    // you need to use `closure` to get correct value of i
                    return text.toString() === i.toString();
                }).then(function (number) {
                    number.click();
                }).then(function () {
                    this.checkApplication(name).then(function (found) {
                        console.log("Text1");
                        return found.length > 0;
                    });
                });
            });
        }
    } else {
        console.log('Pagination not exists');
    }
});
}

因此,您的實際代碼應類似於

this.isApplicationPresentUsingName = function (name) {
//save the reference of `this` to a local variable.
var self = this;

function recursiveSearch(currentPage, totalPage) {
    if (currentPage < totalPage) {
         //if current page is less total page
         // click the current page number
         self.pgnumCount.get(currentPage).click();
            // check if name is present in current page
            return self.checkApplication(name).then(function (found) {
                //if name is present in current page, return true.
                if (found) {
                    return true;
                } else {
                   //if name is not present in current page, 
                   // we need to again click next page and check if it is present
                    return recursiveSearch(index + 1, totalPage)
                }
            });
        }     else {
             //after checking for the name in all pages
             // return false because the name is not present in any of the page.
            return false;
        }
    }

    //get the total page number and recursively check if the name is present in each page.
    return this.pgnumCount.count().then(function (totalCount) {
        //start with page 0 till total number of pages    
        return recursiveSearch(0, totalCount);
    });

};

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM