ale*_*cxe 7 javascript arrays testing jasmine protractor
在其中一个测试中,我们需要声明存在3个元素中的一个.目前我们正在使用protractor.promise.all()和Array.reduce():
var title = element(by.id("title")),
summary = element(by.id("summary")),
description = element(by.id("description"));
protractor.promise.all([
title.isPresent(),
summary.isPresent(),
description.isPresent()
]).then(function (arrExists) {
expect(arrExists.reduce(function(a,b) { return a || b; })).toBe(true);
});
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来解决它与Jasmine没有明确解决承诺?我们需要一个自定义匹配器,还是可以通过内置匹配器解决?
检查一下:
let EC = protractor.ExpectedConditions;
let title = EC.visibilityOf($("#title")),
summary = EC.visibilityOf($("#summary")),
description = EC.visibilityOf($("#description"));
expect(EC.or(title, summary, description)() ).toBeTruthy('Title or summary or description should be visible on the page')
Run Code Online (Sandbox Code Playgroud)
请注意,我正在执行 ExpectedCondition 返回的函数 - 所以我得到的是该函数的结果(将解析为布尔值的 Promise)而不是函数。
如果需要,可以使用 .presenceOf() 代替 .visibilityOf()
http://www.protractortest.org/#/api?view=ExpectedConditions.prototype.or
| 归档时间: |
|
| 查看次数: |
247 次 |
| 最近记录: |