nightwatch.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * Tests to ensure that the app loads correctly in a reasonable time and that operations can be run.
  3. *
  4. * @author n1474335 [n1474335@gmail.com]
  5. * @copyright Crown Copyright 2018
  6. * @license Apache-2.0
  7. */
  8. module.exports = {
  9. before: browser => {
  10. browser
  11. .resizeWindow(1280, 800)
  12. .url(browser.launchUrl);
  13. },
  14. "Loading screen": browser => {
  15. // Check that the loading screen appears and then disappears within a reasonable time
  16. browser
  17. .waitForElementVisible("#preloader", 300)
  18. .waitForElementNotPresent("#preloader", 10000);
  19. },
  20. "App loaded": browser => {
  21. browser.useCss();
  22. // Check that various important elements are loaded
  23. browser.expect.element("#operations").to.be.visible;
  24. browser.expect.element("#recipe").to.be.visible;
  25. browser.expect.element("#input").to.be.present;
  26. browser.expect.element("#output").to.be.present;
  27. browser.expect.element(".op-list").to.be.present;
  28. browser.expect.element("#rec-list").to.be.visible;
  29. browser.expect.element("#controls").to.be.visible;
  30. browser.expect.element("#input-text").to.be.visible;
  31. browser.expect.element("#output-text").to.be.visible;
  32. },
  33. "Operations loaded": browser => {
  34. browser.useXpath();
  35. // Check that an operation in every category has been populated
  36. browser.expect.element("//li[contains(@class, 'operation') and text()='To Base64']").to.be.present;
  37. browser.expect.element("//li[contains(@class, 'operation') and text()='To Binary']").to.be.present;
  38. browser.expect.element("//li[contains(@class, 'operation') and text()='AES Decrypt']").to.be.present;
  39. browser.expect.element("//li[contains(@class, 'operation') and text()='PEM to Hex']").to.be.present;
  40. browser.expect.element("//li[contains(@class, 'operation') and text()='Power Set']").to.be.present;
  41. browser.expect.element("//li[contains(@class, 'operation') and text()='Parse IP range']").to.be.present;
  42. browser.expect.element("//li[contains(@class, 'operation') and text()='Remove Diacritics']").to.be.present;
  43. browser.expect.element("//li[contains(@class, 'operation') and text()='Sort']").to.be.present;
  44. browser.expect.element("//li[contains(@class, 'operation') and text()='To UNIX Timestamp']").to.be.present;
  45. browser.expect.element("//li[contains(@class, 'operation') and text()='Extract dates']").to.be.present;
  46. browser.expect.element("//li[contains(@class, 'operation') and text()='Gzip']").to.be.present;
  47. browser.expect.element("//li[contains(@class, 'operation') and text()='Keccak']").to.be.present;
  48. browser.expect.element("//li[contains(@class, 'operation') and text()='JSON Beautify']").to.be.present;
  49. browser.expect.element("//li[contains(@class, 'operation') and text()='Detect File Type']").to.be.present;
  50. browser.expect.element("//li[contains(@class, 'operation') and text()='Play Media']").to.be.present;
  51. browser.expect.element("//li[contains(@class, 'operation') and text()='Disassemble x86']").to.be.present;
  52. browser.expect.element("//li[contains(@class, 'operation') and text()='Register']").to.be.present;
  53. },
  54. "Recipe can be run": browser => {
  55. const toHex = "//li[contains(@class, 'operation') and text()='To Hex']";
  56. const op = "#rec-list .operation .op-title";
  57. // Check that operation is visible
  58. browser
  59. .useXpath()
  60. .expect.element(toHex).to.be.visible;
  61. // Add it to the recipe by double clicking
  62. browser
  63. .useXpath()
  64. .moveToElement(toHex, 10, 10)
  65. .useCss()
  66. .waitForElementVisible(".popover-body", 1000)
  67. .doubleClick();
  68. // Confirm that it has been added to the recipe
  69. browser
  70. .useCss()
  71. .waitForElementVisible(op)
  72. .expect.element(op).text.to.contain("To Hex");
  73. // Enter input
  74. browser
  75. .useCss()
  76. .setValue("#input-text", "Don't Panic.")
  77. .click("#bake");
  78. // Check output
  79. browser
  80. .useCss()
  81. .waitForElementNotVisible("#stale-indicator", 1000)
  82. .expect.element("#output-text").to.have.value.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
  83. // Clear recipe
  84. browser
  85. .useCss()
  86. .moveToElement(op, 10, 10)
  87. .waitForElementNotPresent(".popover-body", 1000)
  88. .click("#clr-recipe")
  89. .waitForElementNotPresent(op);
  90. },
  91. "Test every module": browser => {
  92. browser.useCss();
  93. // BSON
  94. loadOp("BSON deserialise", browser)
  95. .waitForElementNotVisible("#output-loader", 5000);
  96. // Ciphers
  97. loadOp("AES Encrypt", browser)
  98. .waitForElementNotVisible("#output-loader", 5000);
  99. // Code
  100. loadOp("XPath expression", browser)
  101. .waitForElementNotVisible("#output-loader", 5000);
  102. // Compression
  103. loadOp("Gzip", browser)
  104. .waitForElementNotVisible("#output-loader", 5000);
  105. // Crypto
  106. loadOp("MD5", browser)
  107. .waitForElementNotVisible("#output-loader", 5000);
  108. // Default
  109. loadOp("Fork", browser)
  110. .waitForElementNotVisible("#output-loader", 5000);
  111. // Diff
  112. loadOp("Diff", browser)
  113. .waitForElementNotVisible("#output-loader", 5000);
  114. // Encodings
  115. loadOp("Encode text", browser)
  116. .waitForElementNotVisible("#output-loader", 5000);
  117. // Image
  118. loadOp("Extract EXIF", browser)
  119. .waitForElementNotVisible("#output-loader", 5000);
  120. // PGP
  121. loadOp("PGP Encrypt", browser)
  122. .waitForElementNotVisible("#output-loader", 5000);
  123. // PublicKey
  124. loadOp("Hex to PEM", browser)
  125. .waitForElementNotVisible("#output-loader", 5000);
  126. // Regex
  127. loadOp("Strings", browser)
  128. .waitForElementNotVisible("#output-loader", 5000);
  129. // Shellcode
  130. loadOp("Disassemble x86", browser)
  131. .waitForElementNotVisible("#output-loader", 5000);
  132. // URL
  133. loadOp("URL Encode", browser)
  134. .waitForElementNotVisible("#output-loader", 5000);
  135. // UserAgent
  136. loadOp("Parse User Agent", browser)
  137. .waitForElementNotVisible("#output-loader", 5000);
  138. },
  139. after: browser => {
  140. browser.end();
  141. }
  142. };
  143. /**
  144. * Clears the current recipe and loads a new operation.
  145. *
  146. * @param {string} opName
  147. * @param {Browser} browser
  148. */
  149. function loadOp(opName, browser) {
  150. return browser
  151. .useCss()
  152. .click("#clr-recipe")
  153. .urlHash("op=" + opName);
  154. }