如何使用 chai assertion & serenity 比较两个定位器值

How to compare two locator value using chai assertion & serenity

我是 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");

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

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

你有两种可能: 1. 解决两个承诺并比较值(使用 chai)。 2. 解决其中一个承诺并将价值与另一个承诺进行比较(使用 chai-as-promise)。

下面你可以看到我的建议(第二个选项)。 test1 promise 已解决并存储为 test1text 并与第二个 promise 进行比较。

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);
});