Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取未定义的-量角器Typescript的属性“getText”_Javascript_Typescript_Protractor - Fatal编程技术网

Javascript TypeError:无法读取未定义的-量角器Typescript的属性“getText”

Javascript TypeError:无法读取未定义的-量角器Typescript的属性“getText”,javascript,typescript,protractor,Javascript,Typescript,Protractor,我在使用cucumber的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、getAttributeinnerHTML、innerText、

我在使用cucumber的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、getAttributeinnerHTML、innerText、Text,但它就是找不到href链接的文本。我在谷歌上到处搜索,仍然没有找到解决方案。我不熟悉javascript类型脚本。熟悉javascript typescript量角器的人能提供一些指导吗?谢谢

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=新categoryPg

我意识到我的错误是,我在函数区域中传递category作为cucumber关键字,我调用category.element,因此它变得混乱,无法找到category.element。现在我唯一地重命名了它,现在它找到了它

谢谢