我在页面上有以下DOM
<button type="submit" ng-reflect-disabled="true" disabled="">
Save & 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标记了已禁用属性,但我在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使用the attribute's question
我没有足够的解决方法来定位任何属性另外,我没有找到任何用例,任何建议,提示都会非常感激
答案 0 :(得分:2)
你走在正确的轨道上!您只需要告诉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),
)
希望这有帮助!
扬