Guest User

Untitled

a guest
Oct 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. it('Test the input text field and submit button list the basket items', () => {
  2. const allNameBeforeInput = []
  3. const allNameAfterInput = []
  4. cy.document().then((doc) => {
  5. const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
  6. for (let i = 0; i <= elements.length - 1; i++) {
  7. const basketName = elements[i].textContent
  8. if (basketName && basketName !== '') {
  9. allNameBeforeInput.push(`${basketName}`)
  10. }
  11. console.log(allNameBeforeInput.length) //this gives 0
  12. }
  13. })
  14. cy.get(basket.itemInputField)
  15. .type('Suraj')
  16. cy.get(basket.submitInputButtonField)
  17. .click()
  18. cy.get(basket.itemInputField)
  19. .type('Suraj')
  20. cy.get(basket.submitInputButtonField)
  21. .click()
  22. cy.get(basket.itemInputField)
  23. .type('Suraj')
  24. cy.get(basket.submitInputButtonField)
  25. .click()
  26. cy.get('#items').children('.row-style').children('.list-item')
  27. .contains('Suraj')
  28. cy.document().then((doc) => {
  29. const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
  30. for (let i = 0; i <= elements.length - 1; i++) {
  31. const basketName = elements[i].textContent
  32. if (basketName && basketName !== '') {
  33. allNameAfterInput.push(`${basketName}`)
  34. }
  35. }
  36. console.log(allNameAfterInput.length) //this gives 3
  37. expect(allNameBeforeInput.length).equal(0)
  38. expect(allNameAfterInput.length).equal(3)
  39. expect(allNameBeforeInput.length).is.lt(allNameAfterInput.length)
  40. })
  41.  
  42. getAllBasketName() {
  43. cy.document().then((doc) => {
  44. const allName = []
  45. const elements = doc.querySelector('#items').querySelectorAll('.row-style > :nth-child(1)')
  46. for (let i = 0; i <= elements.length - 1; i++) {
  47. const basketName = elements[i].textContent
  48. if (basketName && basketName !== '') {
  49. allName.push(`${basketName}`)
  50. }
  51. }
  52. return allName
  53. })
  54. }
  55.  
  56. const getAllBasketNamesBefore = basket.getAllBasketName()
  57. cy.get(basket.itemInputField)
  58. .type('Suraj')
  59. cy.get(basket.submitInputButtonField)
  60. .click()
  61. cy.get(basket.itemInputField)
  62. .type('Suraj')
  63. cy.get(basket.submitInputButtonField)
  64. .click()
  65. cy.get(basket.itemInputField)
  66. .type('Suraj')
  67. cy.get(basket.submitInputButtonField)
  68. .click()
  69. const getAllBasketNamesAfter = basket.getAllBasketName()
  70. {Assertion goes here}
  71.  
  72. // not a super useful custom command
  73. // but demonstrates how subject is passed
  74. // and how the arguments are shifted
  75. Cypress.Commands.add('console', {
  76. prevSubject: true
  77. }, (subject, method) => {
  78. // the previous subject is automatically received
  79. // and the commands arguments are shifted
  80.  
  81. // allow us to change the console method used
  82. method = method || 'log'
  83.  
  84. // log the subject to the console
  85. console[method]('The subject is', subject)
  86.  
  87. // whatever we return becomes the new subject
  88. //
  89. // we don't want to change the subject so
  90. // we return whatever was passed in
  91. return subject
  92. })
  93.  
  94. Cypress.Commands.add(allNameBeforeInput, (options, options) => {
  95. //custom logic goes here
  96.  
  97. })
  98.  
  99. Cypress.Commands.add('login',
  100. (username="notsharingmyusernam@stackexchange.com",
  101. password="somesecurepasswordshhh") => {
  102. cy.request({
  103. method: "POST",
  104. url: "/api/public/login",
  105. body: `{:person/email "${username}", :person/password "${password}"}`,
  106. headers: {
  107. "Accept": "application/edn",
  108. "Content-Type": "application/edn"
  109. }
  110. })
  111. })
  112.  
  113. describe('Test suite for page traverse', () => {
  114. beforeEach(() => {
  115. cy.server()
  116. cy.route("POST","/api/graphql").as("graphql")
  117. Cypress.Cookies.preserveOnce("wf_jwt_qa")
  118. })
  119.  
  120. it('traverses all subnav items', () => {
  121. cy.login()
  122. cy.visit('/index.html')
  123. cy.wait("@graphql")
  124. cy.get('[data-tag-component="subnav-group"]')
  125. cy.get('[data-tag-component="subnav-title"]').eq(1).click()
  126.  
  127.  
  128. })
  129. })
Add Comment
Please, Sign In to add comment