05_creating_dsl.js 26 KB

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