如何在Protractor / Gherkins中对元素中的行数执行chai断言?

时间:2018-02-22 22:34:05

标签: javascript protractor cucumber chai gherkin

使用Cucumber / Protractor / Gherkins很新,所以请耐心等待。

无论如何,这是步骤定义:

Then('I should see {int} results', function (int, callback) {        
//assert that the # of results passed in, is equal to the # of rows displayed in the listings table
  expect(locationsPageObj.locationsTable.element.all(by.tagType("tr"))              
    .count()).to.eventually.equal(numberOfResults);
callback(null, 'pending');
});

这是在我们的页面对象中定义的locationsTable元素:

locationsTable : {
    get : function() {
        return element(by.css('.main .locations'));
    }
},

在功能文件中,以下是概述方案的方式:

@Dashboard @Login @Users @UsersValidation 
Scenario Outline: Searching by location name
Given I should wait for the Locations screen to load in admin dashboard
When I enter the search box with content : "<content>" in locations grid page
Then I should see <numberOfResults> displayed

  @qa
 Examples:
| content | numberOfResults |
| test  |       0        |

无论如何,总而言之,我只想验证当我输入一串文本时,表元素中会显示0个tr元素。

2 个答案:

答案 0 :(得分:0)

步骤定义中的一些代码问题:

Then(/^I should see (\d+) results$/, function (numberOfResults, callback) {        
    // assert that the # of results passed in, 
    // is equal to the # of rows displayed in the listings table
    var rowCount = locationsPageObj
            .locationsTable
            .all(by.css("tr")).count();

    expect(rowCount).to.eventually.equal(numberOfResults);
    callback(null, 'pending');
});

答案 1 :(得分:0)

适用于我的案例的步骤定义:

Then('I should see {int} displayed', function (numberOfResults, callback) {
    // Write code here that turns the phrase above into concrete actions
    // assert that the # of results passed in, 
    // is equal to the # of rows displayed in the listings table

browser.wait(EC.invisibilityOf(locationsPageObj.locationsOverlay), timeouts.EC_TIMEOUT).then(function () {              
            var rowCount = locationsPageObj
          .locationsTable
          .all(by.css("tr")).count();

  expect(rowCount).to.eventually.equal(numberOfResults);
            callback();

    });

});