05_creating_dsl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 validate_choice = "#choice_validate";
  287. let constraint_code = "let C_classes = getAllNodes(['/autotest/autotest/ClassC']);\n" +
  288. "C_classes.length <= 2;";
  289. client
  290. .moveToElement(constraint_div, 10, 10)
  291. .mouseButtonClick('middle')
  292. .waitForElementPresent("#dialog_btn", 1000, "Constraint menu opens")
  293. .clearValue(name_field)
  294. .setValue(name_field, "max-two-instances")
  295. .waitForElementPresent(validate_choice, 2000, "Find validate option")
  296. .click(validate_choice)
  297. .moveToElement(pre_create_opt, 0, 0)
  298. .mouseButtonClick('left')
  299. .clearValue(code_field)
  300. .setValue(code_field, constraint_code)
  301. .click("#dialog_btn")
  302. .waitForElementNotPresent("#dialog_btn", 1000, "Constraint menu closes")
  303. .moveToElement(canvas, 0, 100)
  304. .mouseButtonClick('left')
  305. .pause(1000);
  306. //SAVE MODEL
  307. let model_name = "autotest.model";
  308. let folder_name = "autotest";
  309. model_building_utils.save_model(client, folder_name, model_name);
  310. //COMPILE TO ASMM
  311. let metamodel_name = "autotest.metamodel";
  312. model_building_utils.compile_model(client, "AS", folder_name, metamodel_name);
  313. client.pause(500);
  314. },
  315. 'Create CS model': function (client) {
  316. let filename = '/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax.defaultIcons.metamodel';
  317. test_utils.load_toolbar(client, [filename]);
  318. let classIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/IconIcon";
  319. client.waitForElementPresent(classIcon, 2000, "Check for class icon...");
  320. client.click(classIcon);
  321. let canvas = "#div_canvas";
  322. client.waitForElementPresent(canvas, 1000, "Checking for canvas...");
  323. let test_folder = "autotest";
  324. let name_field = "#tr_typename > td:nth-child(2) > textarea";
  325. let num_elements = 0;
  326. //BUILD CLASSES
  327. let icon_type = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/IconIcon\\/";
  328. let start_x = 100;
  329. let x_diff = 225;
  330. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  331. let start_y = 150;
  332. let y_diff = 180;
  333. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  334. let num_classes = x_coords.length * y_coords.length;
  335. num_elements = model_building_utils.create_classes(client, x_coords, y_coords, num_elements, icon_type);
  336. //SET NAMES FOR CLASSES
  337. for (let i = 0; i < num_classes; i++) {
  338. let class_name = "Class" + String.fromCharCode(65 + i) + "Icon";
  339. let attrs = {};
  340. attrs[name_field] = class_name;
  341. model_building_utils.set_attribs(client, i, attrs, icon_type);
  342. }
  343. // BUILD TEXT FOR ICONS
  344. let textIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/TextIcon";
  345. let textType = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/TextIcon\\/";
  346. let textContent_field = "#tr_textContent > td:nth-child(2) > textarea";
  347. client.waitForElementPresent(textIcon, 2000, "Check for text icon...");
  348. client.click(textIcon);
  349. for (let i = 0; i < num_classes; i++) {
  350. let text = "Class" + String.fromCharCode(65 + i);
  351. let textDiv = model_building_utils.build_div(textType, num_elements);
  352. let iconDiv = model_building_utils.build_div(icon_type, i);
  353. let attrs = {};
  354. attrs[textContent_field] = text;
  355. client
  356. .pause(300)
  357. .moveToElement(canvas, 20, 200)
  358. .mouseButtonClick('right')
  359. .pause(500)
  360. .waitForElementPresent(textDiv, 500, "Created text: " + textDiv);
  361. model_building_utils.set_attribs(client, num_elements, attrs, textType);
  362. num_elements++;
  363. client.moveToElement(textDiv, 10, 10)
  364. .mouseButtonClick('left')
  365. .pause(300)
  366. .mouseButtonDown('left')
  367. .pause(300);
  368. model_building_utils.move_to_element_ratio(client, iconDiv, 35, 15);
  369. client.mouseButtonUp('left');
  370. model_building_utils.click_off(client);
  371. //inner link counts as an element
  372. num_elements++;
  373. }
  374. // BUILD SYMBOLS FOR ICONS
  375. let symbols = ["PathIcon", "CircleIcon", "StarIcon", "PolygonIcon", "EllipseIcon", "EllipseIcon", "RectangleIcon", "ImageIcon"];
  376. let getIcon = function (type) {
  377. return "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/" + type;
  378. };
  379. let getType = function (type) {
  380. return "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/" + type + "\\/";
  381. };
  382. for (let i = 0; i < num_classes; i++) {
  383. let currSymbol = symbols[i % symbols.length];
  384. client.waitForElementPresent(getIcon(currSymbol), 2000, "Check for symbol icon...");
  385. client.click(getIcon(currSymbol));
  386. let symbolDiv = model_building_utils.build_div(getType(currSymbol), num_elements);
  387. let iconDiv = model_building_utils.build_div(icon_type, i);
  388. client
  389. .pause(300)
  390. .moveToElement(canvas, 50, 200)
  391. .mouseButtonClick('right')
  392. .pause(1000)
  393. .waitForElementPresent(symbolDiv, 500, "Created symbol: " + symbolDiv);
  394. model_building_utils.click_off(client);
  395. num_elements++;
  396. model_building_utils.move_to_element_ratio(client, symbolDiv, 50, 50);
  397. client
  398. .mouseButtonClick('left')
  399. .pause(300)
  400. .mouseButtonDown('left')
  401. .pause(300);
  402. model_building_utils.move_to_element_ratio(client, iconDiv, 50, 55);
  403. client.pause(300).mouseButtonUp('left');
  404. model_building_utils.click_off(client);
  405. //inner link counts as an element
  406. num_elements++;
  407. }
  408. // BUILD LINKS
  409. let linkIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/LinkIcon";
  410. let linkType = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/LinkIcon\\/";
  411. let link_typename_field = "#tr_typename > td:nth-child(2) > textarea";
  412. let link_y_coords = [];
  413. let link_x_coords = [start_x + 3 * x_diff, start_x + 4 * x_diff];
  414. for (let i = 0; i < assocs.length / 2; i++) {
  415. link_y_coords.push(start_y + i * y_diff);
  416. }
  417. client.waitForElementPresent(linkIcon, 2000, "Check for link icon...");
  418. client.click(linkIcon);
  419. let num_elements_before = num_elements;
  420. model_building_utils.create_classes(client, link_x_coords, link_y_coords, num_elements, linkType);
  421. //SET NAMES FOR LINKS
  422. for (let i = 0; i < assocs.length; i++) {
  423. let link_name = assocs[i][2] + "Link";
  424. let attrs = {};
  425. attrs[link_typename_field] = link_name;
  426. model_building_utils.set_attribs(client, num_elements_before + i, attrs, linkType);
  427. }
  428. //remove unneeded elements
  429. model_building_utils.delete_element(client, model_building_utils.build_div(icon_type, 4));
  430. model_building_utils.delete_element(client, model_building_utils.build_div(linkType, 50));
  431. let folder_name = "autotest";
  432. model_building_utils.save_model(client, folder_name, "autotestCS.model");
  433. model_building_utils.compile_model(client, "CS", folder_name, "autotest.defaultIcons.metamodel");
  434. client.pause(1000);
  435. },
  436. 'Create model': function (client) {
  437. let test_toolbar = '/autotest/autotest.defaultIcons.metamodel';
  438. test_utils.load_toolbar(client, [test_toolbar]);
  439. let class_names = [];
  440. for (let i = 0; i < 9; i++) {
  441. let class_name = "Class" + String.fromCharCode(65 + i) + "Icon";
  442. if (class_name == "ClassEIcon") {
  443. continue; //skip ClassEIcon
  444. }
  445. class_names.push(class_name);
  446. }
  447. //BUILD CLASSES
  448. let class_icon = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e metamodel\\2f ";
  449. let class_type = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ";
  450. let start_x = 200;
  451. let x_diff = 300;
  452. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  453. let start_y = 150;
  454. let y_diff = 180;
  455. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  456. let coords = [];
  457. for (let x of x_coords) {
  458. for (let y of y_coords) {
  459. coords.push([x, y]);
  460. }
  461. }
  462. let num_elements = 0;
  463. let element_map = {};
  464. for (let i = 0; i < class_names.length; i++) {
  465. let class_name = class_names[i];
  466. let class_btn = class_icon + class_name;
  467. client.waitForElementPresent(class_btn, 2000, "Check for class icon: " + class_btn);
  468. client.click(class_btn);
  469. let class_div = class_type + class_name + "\\2f ";
  470. let built_class_div = model_building_utils.create_class(client, coords[i][0], coords[i][1], num_elements, class_div);
  471. element_map[class_name] = built_class_div;
  472. num_elements++;
  473. }
  474. model_building_utils.click_off(client);
  475. // BUILD ASSOCIATIONS
  476. for (let assoc of assocs) {
  477. let from_class_name = "Class" + String.fromCharCode(65 + assoc[0]) + "Icon";
  478. let to_class_name = "Class" + String.fromCharCode(65 + assoc[1]) + "Icon";
  479. if (from_class_name == "ClassEIcon") {
  480. from_class_name = "ClassHIcon";
  481. }
  482. if (to_class_name == "ClassEIcon") {
  483. from_class_name = "ClassFIcon";
  484. }
  485. //select the text of the class
  486. let text_div = " > text:nth-child(1)";
  487. let from_class_div = element_map[from_class_name] + text_div;
  488. let to_class_div = element_map[to_class_name] + text_div;
  489. // console.log(from_class_div);
  490. // console.log(to_class_div);
  491. let isContainAssoc = assoc[3];
  492. if (!isContainAssoc) {
  493. model_building_utils.move_to_element_ratio(client, from_class_div, 20, 50);
  494. client.mouseButtonDown('right');
  495. model_building_utils.move_to_element_ratio(client, to_class_div, 80, 50);
  496. client.mouseButtonUp('right').pause(2000);
  497. } else {
  498. model_building_utils.move_to_element_ratio(client, to_class_div, 30, 50);
  499. client.mouseButtonClick('left').pause(500);
  500. client.mouseButtonDown('left');
  501. model_building_utils.move_to_element_ratio(client, from_class_div, 50, 120);
  502. client.mouseButtonUp('left').pause(2000);
  503. }
  504. num_elements++;
  505. model_building_utils.click_off(client);
  506. }
  507. //SCALE AND ROTATE TESTS
  508. let scale_element_div = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassDIcon\\/3\\.instance";
  509. model_building_utils.move_to_element_ratio(client, scale_element_div, 50, 50);
  510. client.mouseButtonClick('left').pause(300);
  511. //client.setValue(scale_element_div, client.Keys.CONTROL);
  512. //TODO: Can't send CONTROL key
  513. client.execute(function () {
  514. GeometryUtils.showGeometryControlsOverlay();
  515. }, [], null);
  516. let resize_btn_div = "#resize_btn";
  517. let resizeH_btn_div = "#resizeH_btn";
  518. let resizeW_btn_div = "#resizeW_btn";
  519. let rotate_btn_div = "#rotate_btn";
  520. let ok_btn_div = "#ok_btn";
  521. model_building_utils.scroll_geometry_element(client, resize_btn_div, 120, 8);
  522. model_building_utils.scroll_geometry_element(client, resizeH_btn_div, -120, 4);
  523. model_building_utils.scroll_geometry_element(client, resizeW_btn_div, -120, 4);
  524. model_building_utils.scroll_geometry_element(client, rotate_btn_div, 120, 8);
  525. client.click(ok_btn_div).pause(500);
  526. model_building_utils.click_off(client);
  527. //SET ATTRIBUTES
  528. let AClass = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassAIcon\\/";
  529. let AAttribs = {};
  530. AAttribs['int'] = 123;
  531. AAttribs['string'] = "bonjour";
  532. AAttribs['float'] = "123.456";
  533. AAttribs['boolean'] = false;
  534. let attribs = {};
  535. for (let [key, value] of Object.entries(AAttribs)) {
  536. let new_key = "#tr_" + key + " > td:nth-child(2) > textarea:nth-child(1)";
  537. attribs[new_key] = value;
  538. }
  539. //TODO: Set other attribs
  540. model_building_utils.set_attribs(client, 0, attribs, AClass);
  541. // VERIFY MODEL
  542. let verify_btn = "#\\/Toolbars\\/MainMenu\\/MainMenu\\.buttons\\.model\\/validateM";
  543. let dialog_btn = "#dialog_btn";
  544. client.waitForElementPresent(verify_btn, 2000, "Find verify button")
  545. .click(verify_btn)
  546. .waitForElementNotPresent(dialog_btn, 2000, "No constraint violation");
  547. let new_x = start_x + 3 * x_diff;
  548. let class_btn = class_icon + "ClassCIcon";
  549. let CClass_type = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassCIcon\\/";
  550. client.click(class_btn);
  551. model_building_utils.create_class(client, new_x, start_y, num_elements, CClass_type);
  552. model_building_utils.create_class(client, new_x, start_y + y_diff, num_elements, CClass_type);
  553. client.click(verify_btn)
  554. .waitForElementPresent(dialog_btn, 2000, "Constraint violation")
  555. .click(dialog_btn).pause(1000);
  556. model_building_utils.click_off(client);
  557. // SAVE INSTANCE MODEL
  558. let folder_name = "autotest";
  559. model_building_utils.save_model(client, folder_name, "autotest_instance.model");
  560. client.pause(1000);
  561. },
  562. after: function (client) {
  563. client.end();
  564. },
  565. };