简体   繁体   English

第二个相同的断言在赛普拉斯中不起作用

[英]The second same assertation doesn't work in Cypress

I am writing a code that will check the names of the dropbox menus.我正在编写一个代码来检查下拉菜单的名称。 With the first one it works fine, but for the others it shows me this error, even thought the dropbox is visible.第一个它工作正常,但对于其他人它向我显示了这个错误,即使认为保管箱是可见的。 I didn't change the code, so it's the same for all menus.我没有更改代码,因此所有菜单都相同。 This error appears:出现此错误:

AssertionError Timed out retrying after 5000ms: expected '' to be 'visible' This element is not visible because it has CSS property: display: none AssertionError Timed out retrying after 5000ms: expected '' to be 'visible' 此元素不可见,因为它具有 CSS 属性:显示:无

My code:我的代码:

 it('Check the dropdown menu Onboarding', function () {

    cy.visit('http://localhost:25000/', { timeout: 300000 })
    cy.wait(10000)
    cy.get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem:eq(1)').click() 
    cy.contains('Smartcard zuweisen').should('be.visible')
    cy.contains('Primäre Smartcard zuweisen').should('be.visible')
    cy.contains('Primäre Karte drucken und zuweisen').should('be.visible')
    cy.get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem:eq(1)').click() 
 
  })


it('Check the dropdown menu Kartenverwaltung', function () {
    //cy.visit('http://localhost:25000/', { timeout: 300000 })
    cy.wait(10000)
    cy.get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem:eq(2)').click()
    //cy.contains('Kartenverwaltung').should('be.visible')  
    cy.contains('Aktive und deaktivierte Karten')
    cy.contains('Karteninventar').should('be.visible')
    cy.contains('Personenübersicht').should('be.visible')
    cy.contains('Follow You Printing').should('be.visible')
    cy.contains('Staging-Tabelle').should('be.visible')
    cy.contains('Ausstehende Karten').should('be.visible')
    cy.contains('Gesperrte Karten').should('be.visible')
    cy.contains('Karte zurückgeben').should('be.visible')
    
})

The first function Onboarding works.第一个function 入职工作。 From the second function Kartenverwaltung appears the error.从第二个 function Kartenverwaltung出现错误。 What could be the problem?可能是什么问题呢?

在此处输入图像描述

First 3 tr and their children:前 3 个 tr 和他们的孩子: 在此处输入图像描述

Update: In the dropdown that doesn't work with 'td':更新:在不适用于“td”的下拉列表中: 在此处输入图像描述

Error:错误: 在此处输入图像描述

This element is not visible because it has CSS property: display: none

The above line tells us that the element is not visible but it exists in the DOM.上面这行告诉我们该元素是不可见的,但它存在于 DOM 中。 One way to assert is you can use exist instead of be.visible .断言的一种方法是您可以使用be.visible exist It will validate that the element exists in HTML DOM.它将验证该元素是否存在于 HTML DOM 中。

cy.contains('Karteninventar').should('exist')

Or, If you have elements that are visible after scrolling you can use scrollTo() to go to that element and then use should(be.visible)或者,如果您有滚动后可见的元素,您可以使用scrollTo()到 go 到该元素,然后使用should(be.visible)

eg.例如。

cy.scrollTo(0, 500)  //Scrolls down
cy.contains('Karteninventar').should('be.visible')

Or, If you want to directly assert the element with the property with display: none you can do something like:或者,如果您想直接使用display: none属性断言元素,您可以执行以下操作:

cy.get('#dijit_MenuItem_3_accel')
    .should('have.attr', 'style', 'display: none')

So here is my best guess at how to do this based on all the info given.所以这是我根据给出的所有信息对如何做到这一点的最佳猜测。 I advise you to take a data-driven approach, which assumes all menus have the same pattern (which may not be true, I can't say for sure).我建议您采用数据驱动的方法,假设所有菜单都具有相同的模式(这可能不是真的,我不能肯定地说)。

There are some gaps in the menu data that you will have to fill out from the app iteslf,您必须从应用程序iteslf填写菜单数据中的一些空白,

describe('Check the menus', () => {

  const menus = [
    {
      number: 1
      name: "Onboarding".
      items: [
        'Smartcard zuweisen', 
        'Primäre Smartcard zuweisen',
        'Primäre Karte drucken und zuweisen',
      ]
     },
     {
       number: 2
       name: "Kartenverwaltung".
       items: [
         'Aktive und deaktivierte Karten', 
         // other items here
       ]
     },
     // other menus here
  ];

  menus.forEach(menu => {

    it(`Check the dropdown menu ${menu.name}`, function () {
      cy.visit('http://localhost:25000/', { timeout: 300000 })
      cy.wait(10000)
      cy.get('.dijitReset.dijitInline.dijitMenuItemLabel.dijitMenuItem')
        .eq(menu.number).click();                                 // open menu
      cy.get(`table[title="${menu.name}"]`).should('be.visible'); // confirm opened
      menu.items.forEach(item => {
        cy.contains('td', item).should('be.visible');  // Confirm items
      };
  });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM