Comparing two text values, stripping out text and saving

We added functionality to generate a code to give out for use in deferring payments. This feature also has a button to generate a new code on-the-fly. In addition to needing to confirm the code generator works, I need to store this in a text file (while stripping out unneeded text) for use in another script for another user type. This is how I did it

      .get('[class="group-side-panel"]')
      .within(() => {
        let oldCode;
        cy.get('[data-testid="group-code-copy-code"]').should($div => {
          oldCode = $div.text(); //Grabs the old code & stores it as "oldCode"
        });
        cy.get('[data-testid="group-code-code-generation-btn"]')
          .click({ force: true }) //Generates new code
          .get('[data-testid="group-code-copy-code"]')
          .should($div => {
            const newCode = $div.text(); //Stores new code as "newCode"
            expect(oldCode).not.equal(newCode); //Compare the two & confirm diff
          })
          .then($groupCode => {
            // Capture text for new group code, excluding the leading text:
            const label = 'PRIVATE GROUP CODE: ';
            const text = $groupCode.text().replace(label, '');
            cy.writeFile(
            'cypress/integration/04-venueAdmin/deferredPayments/groupCode.txt', text
            );
          });
      });

What this code does: It
1. Copies the old code and stores it as oldCode
2. Clicks the refresh button to generate a new code
3. Stores the new code as newCode
4. Compares oldCode to newCode and confirms they don’t match
5. Strips the “PRIVATE GROUP CODE:” text
6. Writes just the actual code to a .txt file for use in another script

Previous
Previous

Checking CSS of images with dynamic environments

Next
Next

Dynamically setting the environment under test