如何使用 serenity js 属性来断言元素是否被禁用

How to use serenity js Attribute to assert if the element is disabled

我在页面上有以下 DOM

<button type="submit" ng-reflect-disabled="true" disabled="">
    Save &amp Exit
</button>

我还有一个(屏幕播放)组件来定位它的属性

import {Attribute, Target} from "serenity-js/lib/serenity-protractor";
import {by} from "protractor";

export class myComponent {

    public static saveAndExit = Target.the('"Save & Exit" submit button')
        .located(by.buttonText("Save & Exit"));

    public static saveAndExitAttribute = Attribute.of(CreateClientComponent.saveAndExit);
}

我想要做的就是确保 DOM 标记了 disabled 属性,但是我在 step_definitain 文件中的以下尝试正在获取无处

this.Then(
    /^he should see "Save & Exit" button still is disabled$/,
    function(buttonText) {

        return expect(
            this.stage.theActorInTheSpotlight().toSee(CreateClientComponent.saveAndExitAttribute),
        ).to.equal("");
    });

基本上我没有足够的了解如何使用the attribute's question

来定位任何属性

我也没有找到它的任何用例,任何建议,提示将不胜感激

你走在正确的轨道上!您只需要告诉 Serenity/JS 您对哪个 属性感兴趣。

根据 unit tests here.

Attribute 问题的语法是 Attribute.of(target).called('attribute name')

所以不要说:

import {Attribute, Target} from "serenity-js/lib/serenity-protractor";
import {by} from "protractor";

export class myComponent {

    public static saveAndExit = Target.the('"Save & Exit" submit button')
        .located(by.buttonText("Save & Exit"));

    public static saveAndExitAttribute = Attribute.of(CreateClientComponent.saveAndExit);
}

试试这个:

export class myComponent {

    public static saveAndExit = Target.the('"Save & Exit" submit button')
        .located(by.buttonText("Save & Exit"));
}

然后在你的断言中:

return expect(       
   actor.toSee(
      Attribute.of(CreateClientComponent.saveAndExit).called('disabled')
   )
).to.eventually.equal('');

或者更好,使用任务 See:

return actor.attemptsTo(
  See.if(Attribute.of(CreateClientComponent.saveAndExit).called('disabled'), value => expect(value).to.eventually.equal('')
)

然后您可以将其提取到另一个任务中:

const CheckIfTheButtonIsDisabled = (button: Target) => Task.where(`#actor checks if the ${button} is disabled`,
      See.if(Attribute.of(button).called('disabled'), value => expect(value).to.eventually.equal('')
);

这会将您的断言简化为:

return actor.attemptsTo(
  CheckIfTheButtonIsDisabled(CreateClientComponent.saveAndExit),
)

希望对您有所帮助!

一月