柏树E2E测试:如何在网页上的Toast容器(或)弹出窗口上测试短信?

发布于 2025-02-13 13:52:57 字数 745 浏览 1 评论 0原文

html代码的屏幕截图,用于错误吐司弹出我正在尝试获得弹出元素(或)吐司包容器并断言文本,但是我得到了一个从未发现的错误。请有人帮忙吗?

describe('Wholesoft Login Page', function(){

    it('Check Login popup', function(){

        cy.visit('https://https://platform.wholesoftmarket.com/login')
        cy.get('#email').type('[email protected]')
        cy.get('#password').type('hello')
        cy.get('button.btn.active').click()
        cy.get('div').within(($div)=>{
            cy.get('div.overlay-container').should('have.text','no record found')
        }) 
    })
 })

screenshot of html code for the error toast popupI am trying to get the element of popup (or) toast-container and asserting the text, but I am getting an error that element never found. Please someone help?

describe('Wholesoft Login Page', function(){

    it('Check Login popup', function(){

        cy.visit('https://https://platform.wholesoftmarket.com/login')
        cy.get('#email').type('[email protected]')
        cy.get('#password').type('hello')
        cy.get('button.btn.active').click()
        cy.get('div').within(($div)=>{
            cy.get('div.overlay-container').should('have.text','no record found')
        }) 
    })
 })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

雪若未夕 2025-02-20 13:52:57

您需要为元素设置更大的超时,等待在DOM中存在:

cy.get('div[aria-label="Error"]', {timeout: 10000}).should('have.text','no record found')
// maybe you can use the class selector on that div (div.toast-title.ng-star-inserted)
// default timeout is 6000
// increase it until it is caught by Cypress

You need to set a bigger timeout for the element, waiting to be present in the DOM:

cy.get('div[aria-label="Error"]', {timeout: 10000}).should('have.text','no record found')
// maybe you can use the class selector on that div (div.toast-title.ng-star-inserted)
// default timeout is 6000
// increase it until it is caught by Cypress
梦初启 2025-02-20 13:52:57

您需要等到可以看到烤面包或弹出元件才能访问它。

请确保元素选择器正确。
遵循CMD

cy.get('div.overlay-container').should('be.visible').should('have.text','no record found')

You need to wait till the toast or pop-up element is visible to access it for further steps.

Please make sure element selector is right.
following cmd

cy.get('div.overlay-container').should('be.visible').should('have.text','no record found')
℡寂寞咖啡 2025-02-20 13:52:57

只要您没有覆盖默认的CSS类,您可能只想选择以下内容以下内容的实体

cy.get('#root').within(() => {
  cy.get('.Toastify__toast-body').should(...your expectations here...)
})

,或者用ID替换#root,

而在您的React App渲染的位置),就超时而言,确保将其设置为等于或稍大,比toastcontainer组件的“自动差”属性。较高的设置只会不必要地降低测试流程。

编辑:.toastify__ toast-body div的内容如下:

[ 在这种特殊情况下,我解决了问题:

cy.get('.Toastify__toast-body').children().eq(1).should(...)

希望这可以帮助...
[1]: https://i.sstatic.net/l9o5j.png

Provided you did not override the default Toastify CSS classes, you may simply want to select the entity with something like:

cy.get('#root').within(() => {
  cy.get('.Toastify__toast-body').should(...your expectations here...)
})

(or replace #root by the id where your React app is rendered)

And as far as the timeout is of concern, just make sure that it is set equal or slightly greater than the 'autoClose' property of your ToastContainer component. Higher settings would just unnecessarily slower the tests flow.

Edit: the content of the .Toastify__toast-body div looks like this:
[.Toastify__toast-body snapshot][1]

so it has four children: the icon, the text, a close button and a progress bar. In this particular case, I solved the problem using:

cy.get('.Toastify__toast-body').children().eq(1).should(...)

Hope this can help...
[1]: https://i.sstatic.net/l9O5j.png

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