05_creating_dsl.js 27 KB

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