Home > Software engineering >  Cypress: save result, then perform web actions, then compare initial result with end result after ac
Cypress: save result, then perform web actions, then compare initial result with end result after ac

Time:08-31

I would appreciate some help: 1) I am obtaining the total number of items in a list, 2) I perform an action in the website that should remove one item in the list and 3) I need to check that the item is discounted from the list (total items - 1)

static Counter() {
    cy.get('.page-number > span')
      .invoke('text')
      .then((s) => {
      return s.match(/([\d\.]*)$/gmi)[0]
    }).then(parseInt).should('be.a', 'number')
} 

  describe('Compare totals before/after performing web actions', () => {
    it('Store & compare', () => {
      const before = Counter()
      //Perform actions in the web
      const after = Counter()
      expect(after == before - 1).to.equal(true) //?!  
    })
  })

Thank you very much in advance!

CodePudding user response:

I got it if useful:

    describe('Compare totals before/after performing web actions', () => {
      it.only('Store & compare', () => {
        cy.get('.page-number > span')
        .invoke('text')
        .then((s) => {
        //Trim the text: number is mixed with text=> | 1-25 / 10000  
        const u = s.match(/([\d\.]*)$/gmi)[0]
        cy.log('u =', u) //√
  
        //perform action that discounts one item from the list [...]
  
        cy.get('.page-number > span')
        .invoke('text')
        .then((s) => {
        //Trim the text: number is mixed with text=> | 1-25 / 10000  
        const p = s.match(/([\d\.]*)$/gmi)[0]
        cy.log('p =', p)
        
        expect(p, 'Total before').equal(u   1, 'Total after')
  
      
        })
  
  
      }) //.then(cy.log)

  • Related