[英]How to assert that web element is visible on the screen using serenity-js?
我在我的项目中使用带有剧本模式的 Serenity-js BDD 框架。 在这里,我无法使用确保类的“那个”方法对网页上元素的可见性执行断言。
代码 :
页面元素 -
static searchPatientsVerificationRow = Target.the('verification record').located(by.xpath("//div[@class='row']//tr"));
测试脚本步骤:
return Ensure.that(TaggingSearchControls.searchPatientsVerificationRow,Is.visible())
错误 :
“SuccessCondition”类型的参数不可分配给“Assertion”类型的参数。 属性“answeredBy”在“SuccessCondition”类型中缺失,但在“Assertion”类型中需要
您发布的代码示例似乎混合使用了 Serenity/JS 1.x 和 2.x 语法。
使用Serenity/JS 版本 2 ,您可以通过安装以下依赖项来获得它( 参见示例):
npm install --save-dev @serenity-js/core@next @serenity-js/assertions@next @serenity-js/protractor@next @serenity-js/serenity-bdd@next
你可以这样写:
// in page object file
import { Target } from '@serenity-js/protractor';
import { by } from 'protracter';
class TaggingSearchControls {
static searchPatientsVerificationRow =
Target.the('verification record').located(by.xpath("//div[@class='row']//tr"));
}
// in test file
import { Ensure } from '@serenity-js/assertions';
import { isVisible } from '@serenity-js/protractor';
Ensure.that(TaggingSearchControls.searchPatientsVerificationRow, isVisible())
使用 Serenity/JS 版本 1,您需要先从Target
提取一个WebElement
:
Ensure.that(WebElement.of(TaggingSearchControls.searchPatientsVerificationRow), Is.Visible())
希望这可以帮助!
简
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.