NightWatch.js测试失败了吗?

时间:2017-10-06 18:37:29

标签: javascript testing automation 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"

正如您所知,看起来我的测试应该通过。似乎&#34;这个词有&#34;是什么导致我的测试失败。有没有办法删除它?

1 个答案:

答案 0 :(得分:0)

测试看起来失败了(虽然我同意has的放置有点混乱)。由于您将选择器而不是 className 传递给client.assert.cssClassPresent,因此失败了。尝试传递这个:

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