如何使用serenity-js断言Web元素在屏幕上可见? [英] How to assert that web element is visible on the screen using serenity-js?
问题描述
我在我的项目中使用带有剧本模式的Serenity-js BDD框架.在这里,我无法使用确保"类的"that"方法对网页上某个元素的可见性进行断言.
I am using Serenity-js BDD framework with screenplay pattern in my project. Here I am not able to perform assertion for visibility of an element on web-page using Ensure class's "that" method.
代码:
页面元素-
static searchPatientsVerificationRow = Target.the('verification record').located(by.xpath("//div[@class='row']//tr"));
测试脚本步骤:
return Ensure.that(TaggingSearchControls.searchPatientsVerificationRow,Is.visible())
错误:
'SuccessCondition'类型的参数不能分配给'Assertion'类型的参数. 类型"SuccessCondition"中缺少属性"answeredBy",但类型为"Assertion"时必填
Argument of type 'SuccessCondition' is not assignable to parameter of type 'Assertion'. Property 'answeredBy' is missing in type 'SuccessCondition' but required in type 'Assertion'
推荐答案
似乎您发布的代码示例可能使用了Serenity/JS 1.x和2.x语法的混合.
It seems like the code sample you posted might be using a mixture of Serenity/JS 1.x and 2.x syntax.
使用 Serenity/JS版本2 ,您可以获得通过安装以下依赖项(查看示例):
With Serenity/JS version 2, which you can get by installing the following dependencies (see an example):
npm install --save-dev @serenity-js/core@next @serenity-js/assertions@next @serenity-js/protractor@next @serenity-js/serenity-bdd@next
您将按如下方式编写它:
you'd write it as follows:
// 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
:
With Serenity/JS version 1 you'd need to extract a WebElement
from the Target
first:
Ensure.that(WebElement.of(TaggingSearchControls.searchPatientsVerificationRow), Is.Visible())
希望这会有所帮助!
Jan
这篇关于如何使用serenity-js断言Web元素在屏幕上可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!