NightWatch.js测试在不应该失败的时候失败了



我正在运行一个测试,该测试迭代元素并单击它们,然后检查它们是否有活动类,这是我当前的测试:

'testing if executing a function works': function(client) {
client.elements('css selector', '#home-main-content .swiper-container-vertical>.swiper-pagination-bullets .swiper-pagination-bullet', function(res) {
        var numberOfElements = res.value.length;
for (var i = 1; i <= numberOfElements; i++) {
            clicked('.swiper-pagination-bullet:nth-of-type' + '(' + i + ')')
        }
        function clicked(iteration) {
            client.click(iteration, function(res2) {
                client.assert.cssClassPresent(iteration, '.swiper-pagination-bullet swiper-pagination-bullet-active');
            })
        }
    }).end();
}

我在控制台中得到的当前错误是这样的:

Testing if element <.swiper-pagination-bullet:nth-of-type(1)> has css class: 
".swiper-pagination-bullet swiper-pagination-bullet-active".  
- expected "has .swiper-pagination-bullet swiper-pagination-bullet-active" 
but got: "swiper-pagination-bullet swiper-pagination-bullet-active"

正如你所知道的,看起来我的测试应该通过。 似乎"有"这个词是导致我的测试失败的原因。有没有办法删除它?

测试看起来正确失败(尽管我同意该has的位置有点混乱)。它失败了,因为您要传递一个选择器而不是类名client.assert.cssClassPresent 。尝试传递以下内容:

client.assert.cssClassPresent(
  iteration,
  'swiper-pagination-bullet swiper-pagination-bullet-active' // note that there is no leading `.`
);

最新更新