05_creating_dsl.js 29 KB

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