Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- it('Test the input text field and submit button list the basket items', () => {
- const allNameBeforeInput = []
- const allNameAfterInput = []
- cy.document().then((doc) => {
- const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
- for (let i = 0; i <= elements.length - 1; i++) {
- const basketName = elements[i].textContent
- if (basketName && basketName !== '') {
- allNameBeforeInput.push(`${basketName}`)
- }
- console.log(allNameBeforeInput.length) //this gives 0
- }
- })
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- cy.get('#items').children('.row-style').children('.list-item')
- .contains('Suraj')
- cy.document().then((doc) => {
- const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
- for (let i = 0; i <= elements.length - 1; i++) {
- const basketName = elements[i].textContent
- if (basketName && basketName !== '') {
- allNameAfterInput.push(`${basketName}`)
- }
- }
- console.log(allNameAfterInput.length) //this gives 3
- expect(allNameBeforeInput.length).equal(0)
- expect(allNameAfterInput.length).equal(3)
- expect(allNameBeforeInput.length).is.lt(allNameAfterInput.length)
- })
- getAllBasketName() {
- cy.document().then((doc) => {
- const allName = []
- const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
- for (let i = 0; i <= elements.length - 1; i++) {
- const basketName = elements[i].textContent
- if (basketName && basketName !== '') {
- allName.push(`${basketName}`)
- }
- }
- return allName
- })
- }
- const getAllBasketNamesBefore = basket.getAllBasketName()
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- cy.get(basket.itemInputField)
- .type('Suraj')
- cy.get(basket.submitInputButtonField)
- .click()
- const getAllBasketNamesAfter = basket.getAllBasketName()
- {Assertion goes here}
- // not a super useful custom command
- // but demonstrates how subject is passed
- // and how the arguments are shifted
- Cypress.Commands.add('console', {
- prevSubject: true
- }, (subject, method) => {
- // the previous subject is automatically received
- // and the commands arguments are shifted
- // allow us to change the console method used
- method = method || 'log'
- // log the subject to the console
- console[method]('The subject is', subject)
- // whatever we return becomes the new subject
- //
- // we don't want to change the subject so
- // we return whatever was passed in
- return subject
- })
- Cypress.Commands.add(allNameBeforeInput, (options, options) => {
- //custom logic goes here
- })
- Cypress.Commands.add('login',
- (username="notsharingmyusernam@stackexchange.com",
- password="somesecurepasswordshhh") => {
- cy.request({
- method: "POST",
- url: "/api/public/login",
- body: `{:person/email "${username}", :person/password "${password}"}`,
- headers: {
- "Accept": "application/edn",
- "Content-Type": "application/edn"
- }
- })
- })
- describe('Test suite for page traverse', () => {
- beforeEach(() => {
- cy.server()
- cy.route("POST","/api/graphql").as("graphql")
- Cypress.Cookies.preserveOnce("wf_jwt_qa")
- })
- it('traverses all subnav items', () => {
- cy.login()
- cy.visit('/index.html')
- cy.wait("@graphql")
- cy.get('[data-tag-component="subnav-group"]')
- cy.get('[data-tag-component="subnav-title"]').eq(1).click()
- })
- })
Add Comment
Please, Sign In to add comment