如何在夜巡 js 中验证/断言下面的 html



我有一个html类

<a class="mobile-nav-btn" href="/news-mobile"><img src="img/news.svg" role="presentation"><span>Resources</span></a>

我正在尝试单击,然后断言或验证上述内容是否存在。

.click('a[class="mobile-nav-btn"][href="/news-mobile"]')
.waitForElementVisible('body', 3000)
.url(function(response){
      console.log('the url is', response.value);
      this.assert.urlContains(response.value, 'news-mobile')
})

上面的点击失败了,因为我的网址没有改变。我可以从控制台上看到这一点。并在成功点击后。全班转向mobile-nav-btn active.以下是我尝试验证的方式。它也失败了

.verify.elementPresent('a[class="mobile-nav-btn active"][href="news-mobile"]')

我如何实现这些目标?任何帮助将不胜感激。

什么应该对你有用

改变

.click('a[class="mobile-nav-btn"][href="/news-mobile"]')
.waitForElementVisible('body', 3000)
.url(function(response){
      console.log('the url is', response.value);
      this.assert.urlContains(response.value, 'news-mobile')
})

.click('a.mobile-nav-btn[href="/news-mobile"]')
.waitForElementVisible('body', 3000)
.url(function(response){
     this.assert.urlContains(response.value, 'news-mobile')
})

.verify.elementPresent('a[class="mobile-nav-btn active"][href="news-mobile"]')

.assert.cssClassPresent('a.mobile-nav-btn[href="/news-mobile"]','active')

您的测试失败,因为您错误地使用了选择器。

最新更新