E2E测试 - 单击特定按钮
我有一个按钮,看起来像html的
<span class="v-btn__content">Create</span>
e2e测试中,我正在尝试单击创建
按钮
module.exports = {
'My first test case'(browser) {
browser
.url('http://localhost:8080/#/')
.waitForElementVisible('#app')
.waitForElementVisible('#input-10')
.waitForElementVisible('#input-13')
.setValue('#input-10', '[email protected]')
.setValue('#input-13', '**')
.click('.v-btn__content')
.assert.textContains('.v-toolbar__title','App')
.waitForElementVisible('.v-data-footer__pagination')
.waitForElementVisible('.v-btn__content')
.assert.textContains('.v-btn__content','Create')
.click('.v-btn__content','Create') ❌
}
}
,我得到了
✖测试如果元素&lt; .v-btn__content&gt;包含5000ms中的文本“创建” - 预期“包含文本'create'”但got:“不包含'create'”(5219ms)
I have a button, it looks like this in HTML form
<span class="v-btn__content">Create</span>
My E2E Test, I am trying to click that Create
button
module.exports = {
'My first test case'(browser) {
browser
.url('http://localhost:8080/#/')
.waitForElementVisible('#app')
.waitForElementVisible('#input-10')
.waitForElementVisible('#input-13')
.setValue('#input-10', '[email protected]')
.setValue('#input-13', '**')
.click('.v-btn__content')
.assert.textContains('.v-toolbar__title','App')
.waitForElementVisible('.v-data-footer__pagination')
.waitForElementVisible('.v-btn__content')
.assert.textContains('.v-btn__content','Create')
.click('.v-btn__content','Create') ❌
}
}
I got
✖ Testing if element <.v-btn__content> contains text 'Create' in 5000ms - expected "contains text 'Create'" but got: "does not contain 'Create'" (5219ms)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法100%确认我的猜测是正确的,但是根据我的理解,TextContains会选择您提供的选择器的DOM元素,并与提供的文本进行比较。
但是,在您的示例中,您的选择器是className,可以归因于几个元素,尤其是一个元素,例如
v-btn__content
。潜在的修复可能是给您的HTML按钮一个ID,例如:
&lt; span ID =“ create-content” class =“ v-btn__content”&gt; create&lt;/span&gt;
,然后通过以下方式替换textContains selector:现在,如果这是错误,则令我惊讶的是,您没有在
.assert.textcontains('。v-toolbar__title','app')
中遇到错误如果您的页面中只有一个,则很可能是这种情况。如果这无法解决,那么如果您可以提供最小的代码和框,请进一步提供帮助。
I cannot confirm 100% that my guess is correct, but from my understanding, textContains would select a DOM element that you provide the selector for, and compare with the text you provided.
Though, in your example, your selector is a classname, which can be attributed to several elements, especially a generic one such as
v-btn__content
.A potential fix could be to give your HTML button an id such as:
<span id="create-content" class="v-btn__content">Create</span>
, and then replace the textContains selector by:Now again, if this is the error, then I am surprised that you did not get an error with
.assert.textContains('.v-toolbar__title','App')
, but this could be because textContains is smart enough to shorthand to a single element if only one exists in your page, which most likely is the case.If this does not resolve it, happy to help further if you could provide a minimal codesandbox.