traversal.spec.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /// <reference types="cypress" />
  2. context('Traversal', () => {
  3. beforeEach(() => {
  4. cy.visit('https://example.cypress.io/commands/traversal')
  5. })
  6. it('.children() - get child DOM elements', () => {
  7. // https://on.cypress.io/children
  8. cy.get('.traversal-breadcrumb')
  9. .children('.active')
  10. .should('contain', 'Data')
  11. })
  12. it('.closest() - get closest ancestor DOM element', () => {
  13. // https://on.cypress.io/closest
  14. cy.get('.traversal-badge')
  15. .closest('ul')
  16. .should('have.class', 'list-group')
  17. })
  18. it('.eq() - get a DOM element at a specific index', () => {
  19. // https://on.cypress.io/eq
  20. cy.get('.traversal-list>li')
  21. .eq(1).should('contain', 'siamese')
  22. })
  23. it('.filter() - get DOM elements that match the selector', () => {
  24. // https://on.cypress.io/filter
  25. cy.get('.traversal-nav>li')
  26. .filter('.active').should('contain', 'About')
  27. })
  28. it('.find() - get descendant DOM elements of the selector', () => {
  29. // https://on.cypress.io/find
  30. cy.get('.traversal-pagination')
  31. .find('li').find('a')
  32. .should('have.length', 7)
  33. })
  34. it('.first() - get first DOM element', () => {
  35. // https://on.cypress.io/first
  36. cy.get('.traversal-table td')
  37. .first().should('contain', '1')
  38. })
  39. it('.last() - get last DOM element', () => {
  40. // https://on.cypress.io/last
  41. cy.get('.traversal-buttons .btn')
  42. .last().should('contain', 'Submit')
  43. })
  44. it('.next() - get next sibling DOM element', () => {
  45. // https://on.cypress.io/next
  46. cy.get('.traversal-ul')
  47. .contains('apples').next().should('contain', 'oranges')
  48. })
  49. it('.nextAll() - get all next sibling DOM elements', () => {
  50. // https://on.cypress.io/nextall
  51. cy.get('.traversal-next-all')
  52. .contains('oranges')
  53. .nextAll().should('have.length', 3)
  54. })
  55. it('.nextUntil() - get next sibling DOM elements until next el', () => {
  56. // https://on.cypress.io/nextuntil
  57. cy.get('#veggies')
  58. .nextUntil('#nuts').should('have.length', 3)
  59. })
  60. it('.not() - remove DOM elements from set of DOM elements', () => {
  61. // https://on.cypress.io/not
  62. cy.get('.traversal-disabled .btn')
  63. .not('[disabled]').should('not.contain', 'Disabled')
  64. })
  65. it('.parent() - get parent DOM element from DOM elements', () => {
  66. // https://on.cypress.io/parent
  67. cy.get('.traversal-mark')
  68. .parent().should('contain', 'Morbi leo risus')
  69. })
  70. it('.parents() - get parent DOM elements from DOM elements', () => {
  71. // https://on.cypress.io/parents
  72. cy.get('.traversal-cite')
  73. .parents().should('match', 'blockquote')
  74. })
  75. it('.parentsUntil() - get parent DOM elements from DOM elements until el', () => {
  76. // https://on.cypress.io/parentsuntil
  77. cy.get('.clothes-nav')
  78. .find('.active')
  79. .parentsUntil('.clothes-nav')
  80. .should('have.length', 2)
  81. })
  82. it('.prev() - get previous sibling DOM element', () => {
  83. // https://on.cypress.io/prev
  84. cy.get('.birds').find('.active')
  85. .prev().should('contain', 'Lorikeets')
  86. })
  87. it('.prevAll() - get all previous sibling DOM elements', () => {
  88. // https://on.cypress.io/prevall
  89. cy.get('.fruits-list').find('.third')
  90. .prevAll().should('have.length', 2)
  91. })
  92. it('.prevUntil() - get all previous sibling DOM elements until el', () => {
  93. // https://on.cypress.io/prevuntil
  94. cy.get('.foods-list').find('#nuts')
  95. .prevUntil('#veggies').should('have.length', 3)
  96. })
  97. it('.siblings() - get all sibling DOM elements', () => {
  98. // https://on.cypress.io/siblings
  99. cy.get('.traversal-pills .active')
  100. .siblings().should('have.length', 2)
  101. })
  102. })