TypeError: Cannot read property 'getText' of undefined - Protractor Typescript

TypeError: Cannot read property 'getText' of undefined - Protractor Typescript

我在使用带黄瓜的打字稿的量角器脚本中遇到此错误。

TypeError: Cannot read property 'getText' of undefined 
And the left side menu will have the "Shoes" and the "Sandals" actively open # StepsDefinitions/steps.ts:69

我尝试使用 getText、getAttribute(innerHTML、innerText、Text),但它就是找不到 href link 的文本。我搜索了整个 google,但仍未找到解决方案。我是 angular javascript 打字稿的新手。任何熟悉 javascript 打字稿量角器的人都可以提供一些指导吗?谢谢

steps.ts    
import { Given, When, Then} from "cucumber";
import { searchHomePg } from "../PageObjects/searchHomePg";
import { categoryPg } from "../PageObjects/categoryPg";
import { browser, protractor, ExpectedConditions } from "protractor";
import chai from "chai";

var assert = chai.assert;
var expect = chai.expect;
let search = new searchHomePg();
let category = new categoryPg();


Given('I will hover over a category header to bring up the subcategories popup', async()=> { 
    await browser.sleep(3000);
    await browser.actions().mouseMove(category.shoesCategory).perform();
});

When('I select a subcategory', async()=>  {
    await category.sandalsSubCategory.click();
    await browser.sleep(3000);

});

Then('the products displayed will show {string} name in the description text', async(subcategory)=>{
    let products = category.productname;
    let size = await products.length;
    for(let i=0; i<size; i++)
    {
        await products.get(i).getText().then(function(text){
            expect(text).to.include(subcategory);
        });
    }
});

#PROBLEM STEP HERE
Then('the left side menu will have the {string} and the {string} actively open', async(category, subcategory)=>{

    await category.leftmenuCategoryHeader.getText().then(function(text) {
        console.log(text);
        expect(text).to.include(category);
    });


    await category.leftmenuSubCategoryHeader.getText().then(function(text) {
        console.log(text);
        expect(text).to.include(subcategory);
    });

});


Then('the results page displayed will show the {string} header ', async(subcategoryheader)=> {
    await category.pageCategoryHeader.getText().then(function(text){
        console.log(text);
        expect(text).to.include(subcategoryheader);
    });

});

categoryPg.ts
import {ElementFinder, ElementArrayFinder, element, by} from "protractor";

export class categoryPg
{
    productname:ElementArrayFinder;
    shoesCategory:ElementFinder;
    sandalsSubCategory:ElementFinder;
    pageCategoryHeader:ElementFinder;
    leftmenuCategoryHeader:ElementFinder;
    leftmenuSubCategoryHeader:ElementFinder;

    constructor()
    {
        this.productname=element.all(by.css("span[class='product-name']"));
        this.shoesCategory=element(by.css("li[role='tab']>a[href='/shoes']"));
        this.sandalsSubCategory=element(by.linkText("Sandals"));
        this.pageCategoryHeader=element(by.xpath(".//div[@class='number-of-products']//following-sibling::h1[contains(text(), 'sandals')]"));
        //this.leftmenuCategoryHeader=element(by.xpath(".//div[@class='category-heading active']/a[@class='active' and contains(text(),'Shoes')]"));
        //this.leftmenuSubCategoryHeader=element(by.xpath(".//div[@class='category-heading']/a[@class='active']/span[contains(text(),'Sandals')]"));
        this.leftmenuCategoryHeader=element(by.cssContainingText("a.active", "Shoes"));
        this.leftmenuSubCategoryHeader=element(by.cssContainingText("a.active", "Sandals"));

    }


}

谢谢。我也把这个加到步骤中,它通过了步骤。 让 category1 = new categoryPg();

我意识到我的错误是我在 function() 区域中将类别作为 cucumber 关键字传递并且我正在调用 category.element 所以它变得混乱并且找不到 category.element。现在我给它重命名了,现在它找到了。

谢谢。