簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM