0

我是 Serenity 和 Protractor 的新手,因此需要您的帮助来完成以下查询。使用 - Protractor、Chai 断言、Screenplay serenity、Cucumber、TypeScript

我的定位器文件中有以下 2 个定位器:

static test1 = Target.the("test1).located(by.xpath(...**...);

static test2 = Target.the("test2).located(by.xpath(...**...);

我必须比较 test1 和 test2 的值。

Steps.ts 文件:

expect(actor.toSee(Text.of(locatorClass.test1))).to.eventually.equal("21");

如果我传递一些恒定值,它就可以工作。但我必须通过其他定位器。如何比较这两个定位器?

4

1 回答 1

0

我对 serenityjs 不熟悉,但问题是您正在尝试将承诺的结果(从测试 1 获取文本)与未解决的承诺(从测试 1 获取文本)进行比较。

您有两种可能性: 1. 解决两个承诺并比较值(使用 chai)。2. 解决一个promise 并将值与另一个promise 进行比较(使用c​​hai-as-promise)。

您可以在下面看到我的建议(第二个选项)。与第二个 promise 相比,test1promise 被解析并存储。test1text

static test1 = Target.the("test1).located(by.xpath(...**...);
static test2 = Target.the("test2).located(by.xpath(...**...);

return actor.toSee(Text.of(locatorClass.test1)).then((test1text) => {
    return expect(actor.toSee(Text.of(locatorClass.test2))).to.eventually.equal(test1text);
});
于 2018-01-09T13:24:33.807 回答