test_utils.js 3.2 KB

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