简体   繁体   English

如何使用 serenity-js 断言 web 元素在屏幕上可见?

[英]How to assert that web element is visible on the screen using serenity-js?

I am using Serenity-js BDD framework with screenplay pattern in my project.我在我的项目中使用带有剧本模式的 Serenity-js BDD 框架。 Here I am not able to perform assertion for visibility of an element on web-page using Ensure class's "that" method.在这里,我无法使用确保类的“那个”方法对网页上元素的可见性执行断言。

Code :代码 :

Page Element -页面元素 -

static searchPatientsVerificationRow = Target.the('verification record').located(by.xpath("//div[@class='row']//tr")); 

Test Script Step :测试脚本步骤:

return Ensure.that(TaggingSearchControls.searchPatientsVerificationRow,Is.visible()) 

Error :错误 :

Argument of type 'SuccessCondition' is not assignable to parameter of type 'Assertion'. “SuccessCondition”类型的参数不可分配给“Assertion”类型的参数。 Property 'answeredBy' is missing in type 'SuccessCondition' but required in type 'Assertion'属性“answeredBy”在“SuccessCondition”类型中缺失,但在“Assertion”类型中需要

It seems like the code sample you posted might be using a mixture of Serenity/JS 1.x and 2.x syntax.您发布的代码示例似乎混合使用了 Serenity/JS 1.x 和 2.x 语法。

With Serenity/JS version 2 , which you can get by installing the following dependencies ( see an example ):使用Serenity/JS 版本 2 ,您可以通过安装以下依赖项来获得它( 参见示例):

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

With Serenity/JS version 1 you'd need to extract a WebElement from the Target first:使用 Serenity/JS 版本 1,您需要先从Target提取一个WebElement

Ensure.that(WebElement.of(TaggingSearchControls.searchPatientsVerificationRow), Is.Visible())     

Hope this helps!希望这可以帮助!

Jan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM