angular - 角,量角器,黄瓜问题
问题描述
我对黄瓜和量角器完全陌生,以前从未编写过任何 e2e 测试。我正在将此 libaray用于 Angular,但在运行测试时遇到了各种困难。
我的步骤文件如下所示:
const {Given, Then} = require('cucumber');
const expect = require('expect');
Given('I navigate to the homepage', function (callback) {
browser.get('http://localhost:4200');
callback();
});
Then('I want to see a welcome message', function (callback) {
expect($$('h1').first().getText()).toEqual('Welcome!');
callback();
});
但它似乎getText()
是一个异步调用。getText()
似乎正在回报一个承诺。
该测试应该失败,因为h1
is not的文本Welcome!
。当我尝试捕获 promise 和expect()
inthen()
时,测试在它应该失败的地方成功。
网上有很多关于黄瓜/量角器的资源,都说不同的东西。很难知道如何开始。实际的 cucumber 文档没有给出测试浏览器元素的例子。
任何人都可以帮忙吗?我正在使用量角器黄瓜框架 6.1.1 和黄瓜 5.0.1。
解决方案
将以下步骤功能更改如下:
Then('I want to see a welcome message', function (callback) {
$$('h1').first().getText().then(function(txt){
console.log('in then() txt: ' +txt);
expect(txt).toEqual('Welcome!');
callback();
});
});
在您的场景中添加多行Then I want to see a welcome message 1
,并为其添加以下步骤功能。
Then('I want to see a welcome message 1', function (callback) {
expect($$('h1').first().getText()).resolves.toEqual('Welcome!');
callback();
});
再次运行并告诉我结果和输出console.log('in then() txt: ' +txt)
推荐阅读
- css - 从css样式表反应类样式不起作用
- oop - 尽管是抽象的,如何创建 Map 类的实例
- java - 如何在 Java 中向文本文件添加多行(在不同时间?)?
- cmake - 仅标头文件和静态库的 target_link_libraries 错误
- ruby-on-rails - 基于环境的凭据?
- c# - 有没有办法在 C# 中设置 Microsoft.VisualBasic.Interaction.InputBox TopMost = true;
- javafx - TableView 键盘导航 - 为什么 setOnKeyPressed 在 JavaFX11 (OpenJFX) 与 JavaFX8 中对于 TAB、SHIFT+TAB 等键的行为不同?
- php - 如何根据所选数据/ id 在下拉菜单上显示值?
- node.js - Firebase 云函数令牌
- android - 我怎样才能展示广告,它给了我这个错误