1

我在页面上有以下 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("");
    });

Basiccaly我没有足够的了解如何使用属性的问题来定位任何属性

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

4

1 回答 1

2

你在正确的轨道上!你只需要告诉 Serenity/JS你感兴趣的属性

问题的语法AttributeAttribute.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('');

或者更好的是,使用任务来查看

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),
)

希望这可以帮助!

于 2017-09-21T21:16:46.577 回答