Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. function firstFunction (aaa, callback) {
  2. // do async stuff
  3. callback(result)
  4. }
  5.  
  6. function secondFunction (bbb, callback) {
  7. firstFunction (aaa, function (result) {
  8. // do async stuff
  9. callback(result)
  10. }
  11. }
  12.  
  13. secondFunction (ccc, function (result) {
  14. // script actions/verifications
  15. }
  16.  
  17. exports.getTableColumns = function (tableSelector, callback) {
  18. var columnNames = [];
  19. var tableHeaderSelector = tableSelector + ' > tbody > tr:nth-of-type(1) > th';
  20. client.elements('css selector', tableHeaderSelector, function (objectResults) {
  21. for (var i in objectResults.value) {
  22. this.elementIdAttribute(objectResults.value[i].ELEMENT, 'innerText', function(result) {
  23. columnNames.push(result.value);
  24. if (columnNames.length == objectResults.value.length) {
  25. callback(columnNames);
  26. }
  27. });
  28. }
  29. });
  30. }
  31.  
  32. var path = require('path');
  33. var utils = require( path.resolve( __dirname, "./getTableColumns" ) );
  34.  
  35. exports.getColumnValues = function (columnName, tableSelector, callback) {
  36. utils.getTableColumns(tableSelector, function (columnList) {
  37. var columnIndex = columnList.indexOf(columnName) + 1;
  38. var columnValues = [];
  39. cellSelector = tableSelector + ' > tbody > tr:nth-of-type(3) > td:nth-of-type(' + columnIndex + ')';
  40. client.element('css selector', cellSelector, function (objectResult) {
  41. this.elementIdAttribute(objectResult.value.ELEMENT, 'childElementCount', function(result1) {
  42. for (var j = 2; j < 22; j++) {
  43. cellSelector = tableSelector + ' > tbody > tr:nth-of-type(' + j + ') > td:nth-of-type(' + columnIndex + ')';
  44. client.element('css selector', cellSelector, function (objectResult) {
  45. this.elementIdAttribute(objectResult.value.ELEMENT, 'innerText', function(result) {
  46. columnValues.push(result.value);
  47. if (columnValues.length == 20) {
  48. callback(columnValues);
  49. }
  50. });
  51. });
  52. }
  53. });
  54. });
  55. });
  56. }
  57.  
  58. var utils = require('../../lib/utils/getColumnValues.js');
  59. utils.getColumnValues('Route', 'table.table-striped', function (result) {
  60. //do something
  61. }
  62.  
  63. // utils/awesome.js
  64. // Your utility functions
  65. module.exports = {
  66. firstFunction,
  67. };
  68.  
  69.  
  70. // Another file
  71. const utils = require('./utils/awesome.js');
  72.  
  73. function second(){
  74. utils.firstFunction();
  75. // kaboom
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement