小编Dav*_*e P的帖子

量角器元素链接对我不起作用

我正在使用量角器针对 Angular 应用程序构建一些测试操作。我试图让我的定位器尽可能易于阅读和维护,并试图使用“元素链接”来做到这一点。根据我在 SO 和 Protractor 文档中阅读的所有内容,我认为以下定位器策略应该有效:

xpPanelPayment 变量的定义只是为了便于阅读。

let xpPanelPayment = "//div [@class='panel-heading' and text()='Payment']/following-sibling::div [@class='panel-body']";   
this.pnlPayment = element(by.xpath(`${xpPanelPayment}`));
this.valTotalPayment = element(by.xpath(`${xpPanelPayment}`))
    .element(by.xpath(`//strong [text()='Total Payment:']/../following-sibling::div/strong`));
Run Code Online (Sandbox Code Playgroud)

我更喜欢的是:

this.valTotalPayment = this.pnlPayment
    .element(by.xpath(`//strong [text()='Total Payment:']/../following-sibling::div/strong`));
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这样做时,我收到一个错误,似乎表明 this.pnlPayment 未定义。也许这是一个线索?

这是使用这些定位器的方法:

const Receipt = require('./Receipt.js').Receipt;

exports.verifyTotalPayment = (payment) => {
    it(`Receipt Validation - Verify total payment $${payment}`, () => {
        console.log(`Receipt.pnlPayment.locator() = '${Receipt.pnlPayment.locator()}'`);
        console.log(`Receipt.valTotalPayment.locator() =         
'${Receipt.valTotalPayment.locator()}'`);
        expect(Receipt.valTotalPayment.getText()).toEqual(`$${payment}`);
    });
}
Run Code Online (Sandbox Code Playgroud)

下面是运行日志的内容:

Receipt.pnlPayment.locator() = 'By(xpath, //div [@class='panel-heading' and text()='Payment']/following-sibling::div [@class='panel-body'])'
Receipt.valTotalPayment.locator() = 'By(xpath, //strong [text()='Total Payment:']/../following-sibling::div/strong)' …
Run Code Online (Sandbox Code Playgroud)

element chaining protractor angular

2
推荐指数
1
解决办法
764
查看次数

标签 统计

angular ×1

chaining ×1

element ×1

protractor ×1