E2E测试 - 单击特定按钮

发布于 2025-01-26 10:05:44 字数 1073 浏览 2 评论 0原文

我有一个按钮,看起来像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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2025-02-02 10:05:44

我无法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('#create-content', 'Create')
...

现在,如果这是错误,则令我惊讶的是,您没有在.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:

...
.assert.textContains('#create-content', 'Create')
...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文