Enter The Balance Value Into The Input Field

Veröffentlicht am: 05 Dezember 2022
auf dem Kanal: gleb bahmutov
956
22

Let's say we want to look up the available balance in the table, parse the value, then enter it into the input field. The full test code is available at https://glebbahmutov.com/cypress-exam... We can chain the commands to find the row, then find the cell, then parse the text into a number.

// find the row that includes the balance text
// and then find a child TD cell with "$"
cy.contains('tr', 'Available balance')
.contains('td', '$') // yields jQuery object
.invoke('text') // yields its text
.invoke('replace', '$', '') // removes "$" character
.then(parseFloat) // yields a number
// confirm the balance is reasonable
.should('be.within', 1, 10_000)
.then(function (balance) {
// now we can type this balance into the input field
cy.get('#transfer').type(balance)
})

Tip: a much better test would know exactly the balance shown on the page, without looking it up:

cy.contains('tr', 'Available balance').contains('td', '$800')
cy.get('#transfer').clear().type(800)


Auf dieser Seite können Sie das Online-Video Enter The Balance Value Into The Input Field mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer gleb bahmutov 05 Dezember 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 956 Mal angesehen und es wurde von 22 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!