nightwatch.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * Tests to ensure that the app loads correctly in a reasonable time and that operations can br run.
  3. *
  4. * @author n1474335 [n1474335@gmail.com]
  5. * @copyright Crown Copyright 2018
  6. * @license Apache-2.0
  7. */
  8. module.exports = {
  9. before: function (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 an operation in every category
  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", 500)
  67. .doubleClick()
  68. .waitForElementVisible(op);
  69. // Confirm that it has been added to the recipe
  70. browser
  71. .useCss()
  72. .expect.element(op).text.to.contain("To Hex");
  73. // Enter input
  74. browser
  75. .useCss()
  76. .setValue("#input-text", "Don't Panic.");
  77. // Check output
  78. browser
  79. .useCss()
  80. .expect.element("#output-text").to.have.value.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
  81. // Clear recipe
  82. browser
  83. .useCss()
  84. .moveToElement(op, 10, 10)
  85. .waitForElementNotPresent(".popover-body", 500)
  86. .click("#clr-recipe")
  87. .waitForElementNotPresent(op);
  88. },
  89. "Test every module": browser => {
  90. browser.useCss();
  91. // BSON
  92. loadOp("BSON deserialise", browser)
  93. .waitForElementNotVisible("#output-loader", 5000);
  94. // Ciphers
  95. loadOp("AES Encrypt", browser)
  96. .waitForElementNotVisible("#output-loader", 5000);
  97. // Code
  98. loadOp("XPath expression", browser)
  99. .waitForElementNotVisible("#output-loader", 5000);
  100. // Compression
  101. loadOp("Gzip", browser)
  102. .waitForElementNotVisible("#output-loader", 5000);
  103. // Crypto
  104. loadOp("MD5", browser)
  105. .waitForElementNotVisible("#output-loader", 5000);
  106. // Default
  107. loadOp("Fork", browser)
  108. .waitForElementNotVisible("#output-loader", 5000);
  109. // Diff
  110. loadOp("Diff", browser)
  111. .waitForElementNotVisible("#output-loader", 5000);
  112. // Encodings
  113. loadOp("Encode text", browser)
  114. .waitForElementNotVisible("#output-loader", 5000);
  115. // Image
  116. loadOp("Extract EXIF", browser)
  117. .waitForElementNotVisible("#output-loader", 5000);
  118. // PGP
  119. loadOp("PGP Encrypt", browser)
  120. .waitForElementNotVisible("#output-loader", 5000);
  121. // PublicKey
  122. loadOp("Hex to PEM", browser)
  123. .waitForElementNotVisible("#output-loader", 5000);
  124. // Regex
  125. loadOp("Strings", browser)
  126. .waitForElementNotVisible("#output-loader", 5000);
  127. // Shellcode
  128. loadOp("Disassemble x86", browser)
  129. .waitForElementNotVisible("#output-loader", 5000);
  130. // URL
  131. loadOp("URL Encode", browser)
  132. .waitForElementNotVisible("#output-loader", 5000);
  133. // UserAgent
  134. loadOp("Parse User Agent", browser)
  135. .waitForElementNotVisible("#output-loader", 5000);
  136. },
  137. after: browser => {
  138. browser.end();
  139. }
  140. };
  141. /**
  142. * Clears the current recipe and loads a new operation.
  143. *
  144. * @param {string} opName
  145. * @param {Browser} browser
  146. */
  147. function loadOp(opName, browser) {
  148. return browser
  149. .useCss()
  150. .click("#clr-recipe")
  151. .urlHash("op=" + opName);
  152. }