2
0

grid.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module.exports = {
  2. 'grid': function (browser) {
  3. const columns = ['name', 'power']
  4. browser
  5. .url('http://localhost:8080/examples/grid/')
  6. .waitForElementVisible('table', 1000)
  7. .assert.count('th', 2)
  8. .assert.count('th.active', 0)
  9. .assert.containsText('th:nth-child(1)', 'Name')
  10. .assert.containsText('th:nth-child(2)', 'Power')
  11. assertTable([
  12. { name: 'Chuck Norris', power: Infinity },
  13. { name: 'Bruce Lee', power: 9000 },
  14. { name: 'Jackie Chan', power: 7000 },
  15. { name: 'Jet Li', power: 8000 }
  16. ])
  17. browser
  18. .click('th:nth-child(1)')
  19. .assert.count('th.active:nth-child(1)', 1)
  20. .assert.count('th.active:nth-child(2)', 0)
  21. .assert.count('th:nth-child(1) .arrow.dsc', 1)
  22. .assert.count('th:nth-child(2) .arrow.dsc', 0)
  23. assertTable([
  24. { name: 'Jet Li', power: 8000 },
  25. { name: 'Jackie Chan', power: 7000 },
  26. { name: 'Chuck Norris', power: Infinity },
  27. { name: 'Bruce Lee', power: 9000 }
  28. ])
  29. browser
  30. .click('th:nth-child(2)')
  31. .assert.count('th.active:nth-child(1)', 0)
  32. .assert.count('th.active:nth-child(2)', 1)
  33. .assert.count('th:nth-child(1) .arrow.dsc', 1)
  34. .assert.count('th:nth-child(2) .arrow.dsc', 1)
  35. assertTable([
  36. { name: 'Chuck Norris', power: Infinity },
  37. { name: 'Bruce Lee', power: 9000 },
  38. { name: 'Jet Li', power: 8000 },
  39. { name: 'Jackie Chan', power: 7000 }
  40. ])
  41. browser
  42. .click('th:nth-child(2)')
  43. .assert.count('th.active:nth-child(1)', 0)
  44. .assert.count('th.active:nth-child(2)', 1)
  45. .assert.count('th:nth-child(1) .arrow.dsc', 1)
  46. .assert.count('th:nth-child(2) .arrow.asc', 1)
  47. assertTable([
  48. { name: 'Jackie Chan', power: 7000 },
  49. { name: 'Jet Li', power: 8000 },
  50. { name: 'Bruce Lee', power: 9000 },
  51. { name: 'Chuck Norris', power: Infinity }
  52. ])
  53. browser
  54. .click('th:nth-child(1)')
  55. .assert.count('th.active:nth-child(1)', 1)
  56. .assert.count('th.active:nth-child(2)', 0)
  57. .assert.count('th:nth-child(1) .arrow.asc', 1)
  58. .assert.count('th:nth-child(2) .arrow.asc', 1)
  59. assertTable([
  60. { name: 'Bruce Lee', power: 9000 },
  61. { name: 'Chuck Norris', power: Infinity },
  62. { name: 'Jackie Chan', power: 7000 },
  63. { name: 'Jet Li', power: 8000 }
  64. ])
  65. browser
  66. .setValue('input[name="query"]', 'j')
  67. assertTable([
  68. { name: 'Jackie Chan', power: 7000 },
  69. { name: 'Jet Li', power: 8000 }
  70. ])
  71. browser
  72. .clearValue('input[name="query"]')
  73. .setValue('input[name="query"]', 'infinity')
  74. assertTable([
  75. { name: 'Chuck Norris', power: Infinity }
  76. ])
  77. browser
  78. .clearValue('input[name="query"]')
  79. .assert.count('p', 0)
  80. .setValue('input[name="query"]', 'stringthatdoesnotexistanywhere')
  81. .assert.count('p', 1)
  82. browser.end()
  83. function assertTable (data) {
  84. browser.assert.count('td', data.length * columns.length)
  85. for (let i = 0; i < data.length; i++) {
  86. for (let j = 0; j < columns.length; j++) {
  87. browser.assert.containsText(
  88. 'tr:nth-child(' + (i + 1) + ') td:nth-child(' + (j + 1) + ')',
  89. data[i][columns[j]]
  90. )
  91. }
  92. }
  93. }
  94. }
  95. }