Tidied up UI tests

This commit is contained in:
n1474335 2022-04-14 13:16:36 +01:00
parent 8e37fec8f8
commit fb3eceaee0
2 changed files with 26 additions and 51 deletions

View File

@ -14,7 +14,8 @@
}, },
"desiredCapabilities": { "desiredCapabilities": {
"browserName": "chrome" "browserName": "chrome"
} },
"enable_fail_fast": true
}, },
"dev": { "dev": {

View File

@ -25,7 +25,7 @@ module.exports = {
testOp(browser, "AES Encrypt", "test input", "e42eb8fbfb7a98fff061cd2c1a794d92", [{"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex"]); testOp(browser, "AES Encrypt", "test input", "e42eb8fbfb7a98fff061cd2c1a794d92", [{"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex"]);
testOp(browser, "AND", "test input", "4$04 $044", [{ "option": "Hex", "string": "34" }]); testOp(browser, "AND", "test input", "4$04 $044", [{ "option": "Hex", "string": "34" }]);
testOp(browser, "Add line numbers", "test input", "1 test input"); testOp(browser, "Add line numbers", "test input", "1 test input");
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, ["Chef", "Center", "Middle", 0, 0, 16]); testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16], []]);
testOp(browser, "Adler-32 Checksum", "test input", "16160411"); testOp(browser, "Adler-32 Checksum", "test input", "16160411");
testOp(browser, "Affine Cipher Decode", "test input", "rcqr glnsr", [1, 2]); testOp(browser, "Affine Cipher Decode", "test input", "rcqr glnsr", [1, 2]);
testOp(browser, "Affine Cipher Encode", "test input", "njln rbfpn", [2, 1]); testOp(browser, "Affine Cipher Encode", "test input", "njln rbfpn", [2, 1]);
@ -49,8 +49,8 @@ module.exports = {
testOp(browser, "Blowfish Encrypt", "test input", "f0fadbd1d90d774f714248cf26b96410", [{"option": "Hex", "string": "1234567801234567"}, {"option": "Hex", "string": "0011223344556677"}, "CBC", "Raw", "Hex"]); testOp(browser, "Blowfish Encrypt", "test input", "f0fadbd1d90d774f714248cf26b96410", [{"option": "Hex", "string": "1234567801234567"}, {"option": "Hex", "string": "0011223344556677"}, "CBC", "Raw", "Hex"]);
testOp(browser, ["From Hex", "Blur Image", "To Base64"], Images.PNG_HEX, Images.PNG_BLUR_B64); testOp(browser, ["From Hex", "Blur Image", "To Base64"], Images.PNG_HEX, Images.PNG_BLUR_B64);
// testOp(browser, "Bombe", "test input", "test_output"); // testOp(browser, "Bombe", "test input", "test_output");
testOp(browser, "Bzip2 Compress", "test input", "BZh91AY&SYÏ........@..!N. .!.Â.À.3..ß.rE8P.Ï..."); testOp(browser, ["Bzip2 Compress", "To Hex"], "test input", "42 5a 68 39 31 41 59 26 53 59 cf 96 82 1d 00 00 03 91 80 40 00 02 21 4e 00 20 00 21 90 c2 10 c0 88 33 92 8e df 17 72 45 38 50 90 cf 96 82 1d");
testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [true]); testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [[], [true]]);
// testOp(browser, "CRC-16 Checksum", "test input", "test_output"); // testOp(browser, "CRC-16 Checksum", "test input", "test_output");
// testOp(browser, "CRC-32 Checksum", "test input", "test_output"); // testOp(browser, "CRC-32 Checksum", "test input", "test_output");
// testOp(browser, "CRC-8 Checksum", "test input", "test_output"); // testOp(browser, "CRC-8 Checksum", "test input", "test_output");
@ -379,68 +379,43 @@ module.exports = {
* Clears the current recipe and bakes a new operation. * Clears the current recipe and bakes a new operation.
* *
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for pre & post ops * @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text for test * @param {string} input - input text for test
* @param {Array.<string>} args - arguments for test * @param {Array<string>|Array<Array<string>>} args - aarguments, nested if multiple ops
*/ */
function bakeOp(browser, opName, input, args=[]) { function bakeOp(browser, opName, input, args=[]) {
let recipeConfig;
let op, recipeConfig;
/*
* Create recipeConfig as single operation
* or wrapped with a pre-op and
* possibly a post-op too
*/
if (typeof(opName) === "string") { if (typeof(opName) === "string") {
op = opName;
recipeConfig = JSON.stringify([{ recipeConfig = JSON.stringify([{
"op": opName, "op": opName,
"args": args "args": args
}]); }]);
} else if (opName.length === 2) { } else if (opName instanceof Array) {
op = opName[1]; recipeConfig = JSON.stringify(
recipeConfig = JSON.stringify([{ opName.map((op, i) => {
"op": opName[0], return {
"args": [] op: op,
}, { args: args.length ? args[i] : []
"op": opName[1], };
"args": args })
}]); );
} else { } else {
op = opName[1]; throw new Error("Invalid operation type. Must be string or array of strings. Received: " + typeof(opName));
recipeConfig = JSON.stringify([{
"op": opName[0],
"args": []
}, {
"op": opName[1],
"args": args
}, {
"op": opName[2],
"args": []
}]);
} }
browser browser
.useCss() .useCss()
.click("#clr-recipe") .click("#clr-recipe")
.click("#clr-io") .click("#clr-io")
.perform(function() {
console.log("\nCurrent Operation: ", op);
})
.waitForElementNotPresent("#rec-list li.operation") .waitForElementNotPresent("#rec-list li.operation")
.expect.element("#input-text").to.have.property("value").that.equals(""); .expect.element("#input-text").to.have.property("value").that.equals("");
let currentUrl;
browser browser
.urlHash("recipe=" + recipeConfig)
// get the current URL
.url(function(result) {
currentUrl = result;
})
// and put it out
.perform(function() { .perform(function() {
console.log("Current URL: ", currentUrl.value); console.log(`Current test: ${opName}`);
}) })
.urlHash("recipe=" + recipeConfig)
.setValue("#input-text", input) .setValue("#input-text", input)
.waitForElementPresent("#rec-list li.operation") .waitForElementPresent("#rec-list li.operation")
.expect.element("#input-text").to.have.property("value").that.equals(input); .expect.element("#input-text").to.have.property("value").that.equals(input);
@ -458,10 +433,10 @@ function bakeOp(browser, opName, input, args=[]) {
* Clears the current recipe and tests a new operation. * Clears the current recipe and tests a new operation.
* *
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for pre & post ops * @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text for test * @param {string} input - input text
* @param {string} output - expected output * @param {string} output - expected output
* @param {Array.<string>} args - arguments for test * @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
*/ */
function testOp(browser, opName, input, output, args=[]) { function testOp(browser, opName, input, output, args=[]) {
@ -478,14 +453,13 @@ function testOp(browser, opName, input, output, args=[]) {
* Clears the current recipe and tests a new operation. * Clears the current recipe and tests a new operation.
* *
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string} opName - name of operation to be tested * @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} input - input text for test * @param {string} input - input text
* @param {string} cssSelector - CSS selector for HTML output * @param {string} cssSelector - CSS selector for HTML output
* @param {string} output - expected output * @param {string} output - expected output
* @param {Array.<string>} args - arguments for test * @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
*/ */
function testOpHtml(browser, opName, input, cssSelector, output, args=[]) { function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
bakeOp(browser, opName, input, args); bakeOp(browser, opName, input, args);
if (typeof output === "string") { if (typeof output === "string") {