0

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

代码 :

页面元素 -

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”类型中是必需的

4

1 回答 1

1

您发布的代码示例似乎混合使用了 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,您需要WebElement从第一个中提取一个Target

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

希望这可以帮助!

于 2019-09-15T17:02:37.393 回答