test_utils.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. let model_building_utils = require('./model_building_utils');
  2. function login(client) {
  3. client.execute(
  4. function () {
  5. UserManagement.login('testuser');
  6. }, [], null
  7. );
  8. client.pause(500);
  9. client.getTitle(function (title) {
  10. this.assert.ok(title.includes("AToMPM - [Unnamed]"), "AToMPM is opened");
  11. });
  12. }
  13. function load_model(client, fnames) {
  14. client.waitForElementPresent(model_building_utils.canvas, 2000, "Canvas loaded");
  15. client.pause(500);
  16. for (const name of fnames) {
  17. client.execute(
  18. function (fname) {
  19. _loadModel(fname);
  20. }, [name], null
  21. );
  22. client.pause(1000);
  23. client.element('css selector', '#dialog_btn', function (result) {
  24. if (result.status != -1) {
  25. //Dialog has popped up, so check the text and click the button
  26. client.assert.containsText("#div_dialog_0", "File not found");
  27. client.click("#dialog_btn");
  28. //client.verify.ok(false, "File: " + name + " failed to load!"); //don't stop testing
  29. console.error("File: " + name + " failed to load!");
  30. } else {
  31. //Model loaded, so check the title
  32. client.getTitle(function (title) {
  33. this.assert.ok(title.includes(name), "Check for model: " + name);
  34. });
  35. }
  36. });
  37. }
  38. }
  39. function load_toolbar(client, fnames) {
  40. client.waitForElementPresent(model_building_utils.canvas, 2000, "Canvas loaded");
  41. for (let name of fnames) {
  42. client.execute(
  43. function (fname) {
  44. _loadToolbar(fname);
  45. }, [name], null
  46. );
  47. let toolbar_name = name.replace(/\//g, "\\2f ").replace(/\./g, "\\2e ");
  48. toolbar_name = "#div_toolbar_" + toolbar_name;
  49. //client.verify.ok(true, "Checking for Toolbar: " + toolbar_name);
  50. client.element('css selector', '#dialog_btn', function (result) {
  51. if (result.status != -1) {
  52. //Dialog has popped up, so check the text and click the button
  53. client.assert.containsText("#div_dialog_0", "File not found");
  54. client.click("#dialog_btn");
  55. client.verify.ok(true, "Toolbar: " + toolbar_name + " failed to load!"); //don't stop testing
  56. } else {
  57. //Toolbar loaded, so check for it
  58. client.waitForElementPresent(toolbar_name, 2000, "Check for toolbar: " + name);
  59. }
  60. });
  61. }
  62. }
  63. let user = "./users/testuser/";
  64. let glob = require('glob');
  65. let getFiles = function (client, dir, pattern, load_function, files_to_skip) {
  66. glob(dir + pattern, callback(client, load_function, files_to_skip));
  67. };
  68. function callback(client, load_function, files_to_skip) {
  69. return function (err, res) {
  70. if (err) {
  71. assert(false, "Error in reading directory: " + user + "Toolbars");
  72. } else {
  73. let filenames = [];
  74. for (let i in res) {
  75. let fn = res[i];
  76. fn = "\/" + fn.replace(user, "");
  77. //skip files we know will fail
  78. if (files_to_skip == undefined || !files_to_skip.includes(fn)) {
  79. filenames.push(fn);
  80. }
  81. }
  82. //console.log(filenames);
  83. load_function(client, filenames);
  84. }
  85. };
  86. }
  87. module.exports = {
  88. '@disabled': true,
  89. login,
  90. load_model,
  91. load_toolbar,
  92. getFiles
  93. };