05_creating_dsl.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. let test_utils = require('./test_utils');
  2. let model_building_utils = require('./model_building_utils');
  3. let user = "./users/testuser/";
  4. function get_all_attrs() {
  5. return "[\n" +
  6. " {\n" +
  7. " \"name\": \"int\",\n" +
  8. " \"type\": \"int\",\n" +
  9. " \"default\": 0\n" +
  10. " },\n" +
  11. " {\n" +
  12. " \"name\": \"string\",\n" +
  13. " \"type\": \"string\",\n" +
  14. " \"default\": \"hello\"\n" +
  15. " },\n" +
  16. " {\n" +
  17. " \"name\": \"float\",\n" +
  18. " \"type\": \"float\",\n" +
  19. " \"default\": 0\n" +
  20. " },\n" +
  21. " {\n" +
  22. " \"name\": \"boolean\",\n" +
  23. " \"type\": \"boolean\",\n" +
  24. " \"default\": true\n" +
  25. " },\n" +
  26. " {\n" +
  27. " \"name\": \"code\",\n" +
  28. " \"type\": \"code\",\n" +
  29. " \"default\": \"\"\n" +
  30. " },\n" +
  31. " {\n" +
  32. " \"name\": \"file_html\",\n" +
  33. " \"type\": \"file<*.html>\",\n" +
  34. " \"default\": \"\"\n" +
  35. " },\n" +
  36. " {\n" +
  37. " \"name\": \"map_int_string\",\n" +
  38. " \"type\": \"map<int,string>\"\n" +
  39. " },\n" +
  40. " {\n" +
  41. " \"name\": \"list_int\",\n" +
  42. " \"type\": \"list<int>\",\n" +
  43. " \"default\": [\n" +
  44. " 1,\n" +
  45. " 2\n" +
  46. " ]\n" +
  47. " },\n" +
  48. " {\n" +
  49. " \"name\": \"enum\",\n" +
  50. " \"type\": \"ENUM(Red,Green,Blue)\"\n" +
  51. " },\n" +
  52. " {\n" +
  53. " \"name\": \"enum2\",\n" +
  54. " \"type\": \"ENUM(Four,Five,Six,Seven)\"\n" +
  55. " }\n" +
  56. "]";
  57. }
  58. function get_all_attrs2() {
  59. return "[\n" +
  60. " {\n" +
  61. " \"name\": \"name\",\n" +
  62. " \"type\": \"string\",\n" +
  63. " \"default\": \"test\"\n" +
  64. " },\n" +
  65. " {\n" +
  66. " \"name\": \"\",\n" +
  67. " \"type\": \"\",\n" +
  68. " \"default\": \"\"\n" +
  69. " }\n" +
  70. "]";
  71. }
  72. let assocs = [
  73. //from, to, name, isContain, out_card, in_card
  74. [0, 1, "testAssoc", false, null, null],
  75. [1, 3, "oneToOne", false,
  76. [{
  77. "dir": "out",
  78. "type": "oneToOne",
  79. "min": "1",
  80. "max": "1"
  81. }],
  82. [{
  83. "dir": "in",
  84. "type": "oneToOne",
  85. "min": "1",
  86. "max": "1"
  87. }]
  88. ],
  89. [4, 5, "ManyToOne", false,
  90. null,
  91. [{
  92. "dir": "in",
  93. "type": "ManyToOne",
  94. "min": "0",
  95. "max": "1"
  96. }]
  97. ],
  98. [6, 7, "Containment", true,
  99. null, null
  100. ],
  101. [8, 8, "self", false,
  102. null, null
  103. ]
  104. ];
  105. module.exports = {
  106. beforeEach: function (client, done) {
  107. client.url('http://localhost:8124/atompm').pause(300).maximizeWindow(done);
  108. },
  109. 'Login': function (client) {
  110. test_utils.login(client);
  111. },
  112. 'Create AS model': function (client) {
  113. let filename = '/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.umlIcons.metamodel';
  114. test_utils.load_toolbar(client, [filename]);
  115. let classIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/SimpleClassDiagram\\/SimpleClassDiagram\\.umlIcons\\.metamodel\\/ClassIcon";
  116. client.waitForElementPresent(classIcon, 2000, "Check for class icon...");
  117. client.click(classIcon);
  118. let canvas = "#div_canvas";
  119. client.waitForElementPresent(canvas, 1000, "Checking for canvas...");
  120. let test_folder = "autotest";
  121. let name_field = "#tr_name > td:nth-child(2) > textarea";
  122. let num_elements = 0;
  123. //BUILD CLASSES
  124. let start_x = 50;
  125. let x_diff = 350;
  126. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  127. let start_y = 200;
  128. let y_diff = 150;
  129. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  130. let num_classes = x_coords.length * y_coords.length;
  131. num_elements = model_building_utils.create_classes(client, x_coords, y_coords, num_elements);
  132. // SET NAMES FOR CLASSES
  133. for (let i = 0; i < num_classes; i++) {
  134. let class_name = "Class" + String.fromCharCode(65 + i);
  135. let attrs = {};
  136. attrs[name_field] = class_name;
  137. model_building_utils.set_attribs(client, i, attrs);
  138. }
  139. // SET ATTRIBUTES
  140. let class_div = model_building_utils.get_class_div(0);
  141. let attrib_field = "#tr_attributes > td:nth-child(2) > textarea";
  142. client.moveToElement(class_div, 10, 10)
  143. .mouseButtonClick('middle')
  144. .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
  145. .clearValue(attrib_field)
  146. .setValue(attrib_field, get_all_attrs())
  147. .click("#dialog_btn")
  148. .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
  149. .moveToElement(canvas, 0, 100)
  150. .mouseButtonClick('left')
  151. .pause(1000)
  152. ;
  153. let abstract_class = 4;
  154. let class_div2 = model_building_utils.get_class_div(abstract_class);
  155. let attrib_field2 = "#tr_attributes > td:nth-child(2) > textarea";
  156. let checkbox = "#tr_abstract > td:nth-child(2) > input[type=\"checkbox\"]";
  157. model_building_utils.move_to_element_ratio(client, class_div2, 50, 50);
  158. client.mouseButtonClick('middle')
  159. .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
  160. .clearValue(attrib_field2)
  161. .setValue(attrib_field2, get_all_attrs2())
  162. .moveToElement(checkbox, 0, 0)
  163. .mouseButtonClick('left')
  164. .click("#dialog_btn")
  165. .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
  166. .moveToElement(canvas, 0, 100)
  167. .mouseButtonClick('left')
  168. .pause(1000)
  169. ;
  170. //CREATE INHERITANCE
  171. let inheri_classes = [
  172. [abstract_class, abstract_class + 1],
  173. [abstract_class, abstract_class + 3]];
  174. for (let inheri_set of inheri_classes) {
  175. let sup = model_building_utils.get_class_div(inheri_set[0]);
  176. let sub = model_building_utils.get_class_div(inheri_set[1]);
  177. let inheri_relation = "#div_dialog_0 > select > option:nth-child(2)";
  178. //tiny offset to not hit other arrows
  179. let offset = 2 * inheri_set[1];
  180. client
  181. .moveToElement(sub, 50, 50)
  182. .mouseButtonDown('right')
  183. .moveToElement(sup, 50 + offset, 50 + offset)
  184. .mouseButtonUp('right')
  185. .pause(500)
  186. .click(inheri_relation)
  187. .waitForElementPresent("#dialog_btn", 1000, "Inheri menu opens")
  188. .click("#dialog_btn")
  189. .pause(500)
  190. .waitForElementNotPresent("#dialog_btn", 1000, "Inheri menu closes")
  191. .moveToElement(canvas, 0, 100)
  192. .mouseButtonClick('left')
  193. .pause(500)
  194. ;
  195. num_elements++;
  196. }
  197. //SET ASSOCS
  198. client.pause(500);
  199. let assoc_num = 0;
  200. for (let assoc of assocs) {
  201. let from_ele = model_building_utils.get_class_div(assoc[0]);
  202. let to_ele = model_building_utils.get_class_div(assoc[1]);
  203. let name = assoc[2];
  204. let isContain = assoc[3];
  205. let out_card = assoc[4];
  206. let in_card = assoc[5];
  207. let cardinality_field = "#tr_cardinalities > td:nth-child(2) > textarea";
  208. let assoc_div = model_building_utils.get_assoc_div(num_elements);
  209. assoc_num++;
  210. num_elements++;
  211. let assoc_relation = "#div_dialog_0 > select > option:nth-child(1)";
  212. //tiny offset to not hit other arrows
  213. let offset = 2 * assoc[0] + 2 * assoc[1];
  214. client
  215. .moveToElement(from_ele, 20, 20)
  216. .mouseButtonDown('right')
  217. .moveToElement(to_ele, 20 + offset, 20 + offset)
  218. .mouseButtonUp('right')
  219. .pause(500)
  220. .click(assoc_relation)
  221. .waitForElementPresent("#dialog_btn", 1000, "Assoc menu opens")
  222. .click("#dialog_btn")
  223. .pause(500)
  224. .waitForElementNotPresent("#dialog_btn", 1000, "Assoc menu closes")
  225. .moveToElement(canvas, 0, 100)
  226. .mouseButtonClick('left')
  227. .pause(500)
  228. .waitForElementPresent(assoc_div, 1000, "Assoc name present: " + assoc_div);
  229. if (out_card) {
  230. model_building_utils.move_to_element_ratio(client, from_ele, 50, 50);
  231. client.mouseButtonClick('middle')
  232. .waitForElementPresent("#dialog_btn", 1000, "Out card menu opens")
  233. .clearValue(cardinality_field)
  234. .setValue(cardinality_field, JSON.stringify(out_card))
  235. .click("#dialog_btn")
  236. .waitForElementNotPresent("#dialog_btn", 1000, "Out card menu closes")
  237. .moveToElement(canvas, 0, 100)
  238. .mouseButtonClick('left')
  239. .pause(500);
  240. }
  241. if (in_card) {
  242. model_building_utils.move_to_element_ratio(client, to_ele, 50, 50);
  243. client.mouseButtonClick('middle')
  244. .waitForElementPresent("#dialog_btn", 1000, "Out card menu opens")
  245. .clearValue(cardinality_field)
  246. .setValue(cardinality_field, JSON.stringify(in_card))
  247. .click("#dialog_btn")
  248. .waitForElementNotPresent("#dialog_btn", 1000, "Out card menu closes")
  249. .moveToElement(canvas, 0, 100)
  250. .mouseButtonClick('left')
  251. .pause(500);
  252. }
  253. client.getElementSize(assoc_div, function (result) {
  254. model_building_utils.move_to_element_ratio(client, assoc_div, 50, 50);
  255. client.mouseButtonClick('middle')
  256. .waitForElementPresent("#dialog_btn", 1000, "Editing assoc name opens")
  257. .clearValue(name_field)
  258. .setValue(name_field, name);
  259. if (isContain) {
  260. let contain_opt = "#tr_linktype > td:nth-child(2) > select > option:nth-child(2)";
  261. client
  262. .moveToElement(contain_opt, 0, 0)
  263. .mouseButtonClick('left');
  264. }
  265. client
  266. .click("#dialog_btn")
  267. .waitForElementNotPresent("#dialog_btn", 1000, "Editing assoc name closes")
  268. .moveToElement(canvas, 0, 100)
  269. .mouseButtonClick('left')
  270. .pause(500);
  271. })
  272. ;
  273. }
  274. //CREATE CONSTRAINT
  275. let constraint_div = model_building_utils.get_element_div("GlobalConstraintIcon", num_elements);
  276. let constraintIcon = "#\\2f Formalisms\\2f __LanguageSyntax__\\2f SimpleClassDiagram\\2f SimpleClassDiagram\\2e umlIcons\\2e metamodel\\2f GlobalConstraintIcon";
  277. client.waitForElementPresent(constraintIcon, 2000, "Check for constraint icon...");
  278. client.click(constraintIcon);
  279. client
  280. .moveToElement(canvas, 100, 150)
  281. .mouseButtonClick('right')
  282. .pause(500)
  283. .waitForElementPresent(constraint_div, 500, "Created class: " + constraint_div);
  284. let pre_create_opt = "#tr_event > td:nth-child(2) > select > option:nth-child(2)";
  285. let code_field = "#tr_code > td:nth-child(2) > textarea";
  286. let constraint_code = "let C_classes = getAllNodes(['Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram/umlIcons/ClassIcon']);\n" +
  287. "C_classes.length <= 2;";
  288. client
  289. .moveToElement(constraint_div, 10, 10)
  290. .mouseButtonClick('middle')
  291. .waitForElementPresent("#dialog_btn", 1000, "Constraint menu opens")
  292. .clearValue(name_field)
  293. .setValue(name_field, "max-two-instances")
  294. .moveToElement(pre_create_opt, 0, 0)
  295. .mouseButtonClick('left')
  296. .clearValue(code_field)
  297. .setValue(code_field, constraint_code)
  298. .click("#dialog_btn")
  299. .waitForElementNotPresent("#dialog_btn", 1000, "Constraint menu closes")
  300. .moveToElement(canvas, 0, 100)
  301. .mouseButtonClick('left')
  302. .pause(1000);
  303. //SAVE MODEL
  304. let model_name = "autotest.model";
  305. let folder_name = "autotest";
  306. model_building_utils.save_model(client, folder_name, model_name);
  307. //COMPILE TO ASMM
  308. let metamodel_name = "autotest.metamodel";
  309. model_building_utils.compile_model(client, "AS", folder_name, metamodel_name);
  310. client.pause(500);
  311. },
  312. 'Create CS model': function (client) {
  313. let filename = '/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax.defaultIcons.metamodel';
  314. test_utils.load_toolbar(client, [filename]);
  315. let classIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/IconIcon";
  316. client.waitForElementPresent(classIcon, 2000, "Check for class icon...");
  317. client.click(classIcon);
  318. let canvas = "#div_canvas";
  319. client.waitForElementPresent(canvas, 1000, "Checking for canvas...");
  320. let test_folder = "autotest";
  321. let name_field = "#tr_typename > td:nth-child(2) > textarea";
  322. let num_elements = 0;
  323. //BUILD CLASSES
  324. let icon_type = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/IconIcon\\/";
  325. let start_x = 200;
  326. let x_diff = 250;
  327. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  328. let start_y = 150;
  329. let y_diff = 180;
  330. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  331. let num_classes = x_coords.length * y_coords.length;
  332. num_elements = model_building_utils.create_classes(client, x_coords, y_coords, num_elements, icon_type);
  333. //SET NAMES FOR CLASSES
  334. for (let i = 0; i < num_classes; i++) {
  335. let class_name = "Class" + String.fromCharCode(65 + i) + "Icon";
  336. let attrs = {};
  337. attrs[name_field] = class_name;
  338. model_building_utils.set_attribs(client, i, attrs, icon_type);
  339. }
  340. // BUILD TEXT FOR ICONS
  341. let textIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/TextIcon";
  342. let textType = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/TextIcon\\/";
  343. let textContent_field = "#tr_textContent > td:nth-child(2) > textarea";
  344. client.waitForElementPresent(textIcon, 2000, "Check for text icon...");
  345. client.click(textIcon);
  346. for (let i = 0; i < num_classes; i++) {
  347. let text = "Class" + String.fromCharCode(65 + i);
  348. let textDiv = model_building_utils.build_div(textType, num_elements);
  349. let iconDiv = model_building_utils.build_div(icon_type, i);
  350. let attrs = {};
  351. attrs[textContent_field] = text;
  352. client
  353. .pause(300)
  354. .moveToElement(canvas, 20, 200)
  355. .mouseButtonClick('right')
  356. .pause(500)
  357. .waitForElementPresent(textDiv, 500, "Created text: " + textDiv);
  358. model_building_utils.set_attribs(client, num_elements, attrs, textType);
  359. num_elements++;
  360. client.moveToElement(textDiv, 10, 10)
  361. .mouseButtonClick('left')
  362. .pause(300)
  363. .mouseButtonDown('left')
  364. .pause(300);
  365. model_building_utils.move_to_element_ratio(client, iconDiv, 35, 15);
  366. client.mouseButtonUp('left');
  367. model_building_utils.click_off(client);
  368. //inner link counts as an element
  369. num_elements++;
  370. }
  371. // BUILD SYMBOLS FOR ICONS
  372. let symbols = ["PathIcon", "CircleIcon", "StarIcon", "PolygonIcon", "EllipseIcon", "EllipseIcon", "RectangleIcon", "ImageIcon"];
  373. let getIcon = function (type) {
  374. return "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/" + type;
  375. };
  376. let getType = function (type) {
  377. return "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/" + type + "\\/";
  378. };
  379. for (let i = 0; i < num_classes; i++) {
  380. let currSymbol = symbols[i % symbols.length];
  381. client.waitForElementPresent(getIcon(currSymbol), 2000, "Check for symbol icon...");
  382. client.click(getIcon(currSymbol));
  383. let symbolDiv = model_building_utils.build_div(getType(currSymbol), num_elements);
  384. let iconDiv = model_building_utils.build_div(icon_type, i);
  385. client
  386. .pause(300)
  387. .moveToElement(canvas, 50, 200)
  388. .mouseButtonClick('right')
  389. .pause(1000)
  390. .waitForElementPresent(symbolDiv, 500, "Created symbol: " + symbolDiv);
  391. model_building_utils.click_off(client);
  392. num_elements++;
  393. model_building_utils.move_to_element_ratio(client, symbolDiv, 50, 50);
  394. client
  395. .mouseButtonClick('left')
  396. .pause(300)
  397. .mouseButtonDown('left')
  398. .pause(300);
  399. model_building_utils.move_to_element_ratio(client, iconDiv, 50, 55);
  400. client.pause(300).mouseButtonUp('left');
  401. model_building_utils.click_off(client);
  402. //inner link counts as an element
  403. num_elements++;
  404. }
  405. // BUILD LINKS
  406. let linkIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/LinkIcon";
  407. let linkType = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/LinkIcon\\/";
  408. let link_typename_field = "#tr_typename > td:nth-child(2) > textarea";
  409. let link_y_coords = [];
  410. let link_x_coords = [start_x + 3 * x_diff, start_x + 4 * x_diff];
  411. for (let i = 0; i < assocs.length / 2; i++) {
  412. link_y_coords.push(start_y + i * y_diff);
  413. }
  414. client.waitForElementPresent(linkIcon, 2000, "Check for link icon...");
  415. client.click(linkIcon);
  416. let num_elements_before = num_elements;
  417. model_building_utils.create_classes(client, link_x_coords, link_y_coords, num_elements, linkType);
  418. //SET NAMES FOR LINKS
  419. for (let i = 0; i < assocs.length; i++) {
  420. let link_name = assocs[i][2] + "Link";
  421. let attrs = {};
  422. attrs[link_typename_field] = link_name;
  423. model_building_utils.set_attribs(client, num_elements_before + i, attrs, linkType);
  424. }
  425. //remove unneeded elements
  426. model_building_utils.delete_element(client, model_building_utils.build_div(icon_type, 4));
  427. model_building_utils.delete_element(client, model_building_utils.build_div(linkType, 50));
  428. let folder_name = "autotest";
  429. model_building_utils.save_model(client, folder_name, "autotestCS.model");
  430. model_building_utils.compile_model(client, "CS", folder_name, "autotest.defaultIcons.metamodel");
  431. client.pause(1000);
  432. },
  433. 'Create model': function (client) {
  434. let test_toolbar = '/autotest/autotest.defaultIcons.metamodel';
  435. test_utils.load_toolbar(client, [test_toolbar]);
  436. let class_names = [];
  437. for (let i = 0; i < 9; i++) {
  438. let class_name = "Class" + String.fromCharCode(65 + i) + "Icon";
  439. if (class_name == "ClassEIcon") {
  440. continue; //skip ClassEIcon
  441. }
  442. class_names.push(class_name);
  443. }
  444. //BUILD CLASSES
  445. let class_icon = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e metamodel\\2f ";
  446. let class_type = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ";
  447. let start_x = 200;
  448. let x_diff = 300;
  449. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  450. let start_y = 150;
  451. let y_diff = 180;
  452. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  453. let coords = [];
  454. for (let x of x_coords) {
  455. for (let y of y_coords) {
  456. coords.push([x, y]);
  457. }
  458. }
  459. let num_elements = 0;
  460. let element_map = {};
  461. for (let i = 0; i < class_names.length; i++) {
  462. let class_name = class_names[i];
  463. let class_btn = class_icon + class_name;
  464. client.waitForElementPresent(class_btn, 2000, "Check for class icon: " + class_btn);
  465. client.click(class_btn);
  466. let class_div = class_type + class_name + "\\2f ";
  467. let built_class_div = model_building_utils.create_class(client, coords[i][0], coords[i][1], num_elements, class_div);
  468. element_map[class_name] = built_class_div;
  469. num_elements++;
  470. }
  471. model_building_utils.click_off(client);
  472. // BUILD ASSOCIATIONS
  473. for (let assoc of assocs) {
  474. let from_class_name = "Class" + String.fromCharCode(65 + assoc[0]) + "Icon";
  475. let to_class_name = "Class" + String.fromCharCode(65 + assoc[1]) + "Icon";
  476. if (from_class_name == "ClassEIcon") {
  477. from_class_name = "ClassHIcon";
  478. }
  479. if (to_class_name == "ClassEIcon") {
  480. from_class_name = "ClassFIcon";
  481. }
  482. //select the text of the class
  483. let text_div = " > text:nth-child(1)";
  484. let from_class_div = element_map[from_class_name] + text_div;
  485. let to_class_div = element_map[to_class_name] + text_div;
  486. // console.log(from_class_div);
  487. // console.log(to_class_div);
  488. let isContainAssoc = assoc[3];
  489. if (!isContainAssoc) {
  490. model_building_utils.move_to_element_ratio(client, from_class_div, 30, 50);
  491. client.mouseButtonDown('right');
  492. model_building_utils.move_to_element_ratio(client, to_class_div, 70, 50);
  493. client.mouseButtonUp('right').pause(2000);
  494. } else {
  495. model_building_utils.move_to_element_ratio(client, to_class_div, 30, 50);
  496. client.mouseButtonClick('left').pause(500);
  497. client.mouseButtonDown('left');
  498. model_building_utils.move_to_element_ratio(client, from_class_div, 50, 120);
  499. client.mouseButtonUp('left').pause(2000);
  500. }
  501. model_building_utils.click_off(client);
  502. }
  503. //SCALE AND ROTATE TESTS
  504. let scale_element_div = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassDIcon\\/3\\.instance";
  505. model_building_utils.move_to_element_ratio(client, scale_element_div, 50, 50);
  506. client.mouseButtonClick('left').pause(300);
  507. //client.setValue(scale_element_div, client.Keys.CONTROL);
  508. //TODO: Can't send CONTROL key
  509. client.execute(function () {
  510. GeometryUtils.showGeometryControlsOverlay();
  511. }, [], null);
  512. let resize_btn_div = "#resize_btn";
  513. let resizeH_btn_div = "#resizeH_btn";
  514. let resizeW_btn_div = "#resizeW_btn";
  515. let rotate_btn_div = "#rotate_btn";
  516. let ok_btn_div = "#ok_btn";
  517. model_building_utils.scroll_geometry_element(client, resize_btn_div, 120, 8);
  518. model_building_utils.scroll_geometry_element(client, resizeH_btn_div, -120, 4);
  519. model_building_utils.scroll_geometry_element(client, resizeW_btn_div, -120, 4);
  520. model_building_utils.scroll_geometry_element(client, rotate_btn_div, 120, 8);
  521. client.click(ok_btn_div).pause(500);
  522. model_building_utils.click_off(client);
  523. //SET ATTRIBUTES
  524. let AClass = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassAIcon\\/";
  525. let AAttribs = {};
  526. AAttribs['int'] = 123;
  527. AAttribs['string'] = "bonjour";
  528. AAttribs['float'] = "123.456";
  529. AAttribs['boolean'] = false;
  530. let attribs = {};
  531. for (let [key, value] of Object.entries(AAttribs)) {
  532. let new_key = "#tr_" + key + " > td:nth-child(2) > textarea:nth-child(1)";
  533. attribs[new_key] = value;
  534. }
  535. //TODO: Set other attribs
  536. model_building_utils.set_attribs(client, 0, attribs, AClass);
  537. // SAVE INSTANCE MODEL
  538. let folder_name = "autotest";
  539. model_building_utils.save_model(client, folder_name, "autotest_instance.model");
  540. client.pause(1000);
  541. },
  542. after: function (client) {
  543. client.end();
  544. },
  545. };