90-nodes-select.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* eslint-disable */
  2. var fs = require('fs');
  3. var debug = require('debug')('scope:test:action:90-nodes-select');
  4. function clickIfVisible(list, index) {
  5. var el = list[index++];
  6. el.isDisplayed(function(err, visible) {
  7. if (err) {
  8. debug(err);
  9. } else if (visible) {
  10. el.click();
  11. } else {
  12. if (index < list.length) {
  13. clickIfVisible(list, index);
  14. }
  15. }
  16. });
  17. }
  18. function selectNode(browser) {
  19. debug('select node');
  20. return browser.elementByCssSelector('.nodes-chart-elements .node:nth-child(1) > g', function(err, el) {
  21. return el.click();
  22. });
  23. }
  24. function deselectNode(browser) {
  25. debug('deselect node');
  26. return browser.elementByCssSelector('.fa-times', function(err, el) {
  27. return el.click();
  28. });
  29. }
  30. module.exports = function(cfg) {
  31. var startUrl = 'http://' + cfg.host + '/';
  32. // cfg - The configuration object. args, from the example above.
  33. return function(browser) {
  34. // browser is created using wd.promiseRemote()
  35. // More info about wd at https://github.com/admc/wd
  36. return browser.get('http://' + cfg.host + '/')
  37. .then(function() {
  38. debug('starting run ' + cfg.run);
  39. return browser.sleep(2000);
  40. })
  41. .then(function() {
  42. return browser.execute("localStorage.debugToolbar = 1;");
  43. })
  44. .then(function() {
  45. return browser.sleep(5000);
  46. })
  47. .then(function() {
  48. return browser.elementByCssSelector('.debug-panel button:nth-child(5)');
  49. // return browser.elementByCssSelector('.debug-panel div:nth-child(2) button:nth-child(9)');
  50. })
  51. .then(function(el) {
  52. debug('debug-panel found');
  53. return el.click();
  54. })
  55. .then(function() {
  56. return browser.sleep(2000);
  57. })
  58. .then(function() {
  59. return selectNode(browser);
  60. })
  61. .then(function() {
  62. return browser.sleep(5000);
  63. })
  64. .then(function() {
  65. return deselectNode(browser);
  66. })
  67. .then(function() {
  68. return browser.sleep(2000);
  69. })
  70. .then(function() {
  71. return selectNode(browser);
  72. })
  73. .then(function() {
  74. return browser.sleep(5000);
  75. })
  76. .then(function() {
  77. return deselectNode(browser);
  78. })
  79. .then(function() {
  80. return browser.sleep(2000);
  81. })
  82. .then(function() {
  83. return selectNode(browser);
  84. })
  85. .then(function() {
  86. return browser.sleep(5000);
  87. })
  88. .then(function() {
  89. return deselectNode(browser);
  90. })
  91. .then(function() {
  92. return browser.sleep(2000, function() {
  93. debug('scenario done');
  94. });
  95. })
  96. .fail(function(err) {
  97. debug('exception. taking screenshot', err);
  98. browser.takeScreenshot(function(err, data) {
  99. if (err) {
  100. debug(err);
  101. } else {
  102. var base64Data = data.replace(/^data:image\/png;base64,/,"");
  103. fs.writeFile('90-nodes-select-' + cfg.run + '.png', base64Data, 'base64', function(err) {
  104. if(err) debug(err);
  105. });
  106. }
  107. });
  108. });
  109. }
  110. };