Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

72
Vistas
How to adding values from dynamic elements and verifying the result

Similarly to this question. How add two values[1,2 elements] and verify its equal to result[3 element]

from the below HTML structure I need to add A(element) & B(element) and verify the sum is equal to A+B(element) its complex for me since A & B are dynamic and they can or cannot be present depending on the changes from the user.

enter image description here

I tried to use the below script.

cy.get('[data-cy="Selected in Final InterviewofferBreakUpTableBodyCellRenderer"] >span').invoke('text')

But it's yielding both the text, i only need the number.

enter image description here

I need help in making a test that won't fail even if only one element A or B is present.

6 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can do something like this:

cy.contains('span', 'Final Interview Selects')
  .next()
  .invoke('text')
  .then((sum) => {
    cy.contains('span', 'Selected - Not Offered')
      .next()
      .invoke('text')
      .then((A) => {
        cy.contains('span', 'Selected in Final Interview')
          .next()
          .invoke('text')
          .then((B) => {
            expect(+sum).to.eq(+A + +B)
          })
      })
  })

You can do something like this if some of the elements are not visible.

const A = 0,
  B = 0
cy.get('body')
  .then(($body) => {
    if (
      '$body:not(:contains("Selected - Not Offered"))' &&
      '$body:contains("Selected in Final Interview")'
    ) {
      A = 0
      cy.contains('span', 'Selected in Final Interview')
        .next()
        .invoke('text')
        .then((num) => {
          B = +num
        })
    }

    if (
      '$body:contains("Selected - Not Offered")' &&
      '$body:not(:contains("Selected in Final Interview"))'
    ) {
      B = 0
      cy.contains('span', 'Selected - Not Offered')
        .next()
        .invoke('text')
        .then((num) => {
          A = +num
        })
    }

    if (
      '$body:not(:contains("Selected - Not Offered"))' &&
      '$body:not(:contains("Selected in Final Interview"))'
    ) {
      A = 0
      B = 0
    }
  })
  .then(() => {
    cy.contains('span', 'Final Interview Selects')
      .next()
      .invoke('text')
      .then((sum) => {
        expect(+sum).to.eq(A + B)
      })
  })

6 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos