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

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

我在我的项目中使用带有剧本模式的 Serenity-js BDD 框架。在这里,我无法使用 Ensure class 的 "that" 方法对网页上元素的可见性执行断言。

代码:

页面元素 -

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

测试脚本步骤:

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

错误:

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 语法。

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 

你可以这样写:

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

希望对您有所帮助!

一月