2017-10-06 97 views
0

我運行它迭代元素,並在其上點擊,如果他們有一個活躍的類,然後檢查測試,這是我目前的測試: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" 

正如你所看到的,它看起來像我的測試應該通過。似乎「有」這個詞就是導致我的測試失敗的原因。有沒有辦法消除這種情況?

回答

0

該測試看起來失敗的正確(雖然我同意has的位置有點混淆)。這是失敗的,因爲你通過選擇器而不是classNameclient.assert.cssClassPresent。嘗試通過此代替:

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