Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function firstFunction (aaa, callback) {
- // do async stuff
- callback(result)
- }
- function secondFunction (bbb, callback) {
- firstFunction (aaa, function (result) {
- // do async stuff
- callback(result)
- }
- }
- secondFunction (ccc, function (result) {
- // script actions/verifications
- }
- exports.getTableColumns = function (tableSelector, callback) {
- var columnNames = [];
- var tableHeaderSelector = tableSelector + ' > tbody > tr:nth-of-type(1) > th';
- client.elements('css selector', tableHeaderSelector, function (objectResults) {
- for (var i in objectResults.value) {
- this.elementIdAttribute(objectResults.value[i].ELEMENT, 'innerText', function(result) {
- columnNames.push(result.value);
- if (columnNames.length == objectResults.value.length) {
- callback(columnNames);
- }
- });
- }
- });
- }
- var path = require('path');
- var utils = require( path.resolve( __dirname, "./getTableColumns" ) );
- exports.getColumnValues = function (columnName, tableSelector, callback) {
- utils.getTableColumns(tableSelector, function (columnList) {
- var columnIndex = columnList.indexOf(columnName) + 1;
- var columnValues = [];
- cellSelector = tableSelector + ' > tbody > tr:nth-of-type(3) > td:nth-of-type(' + columnIndex + ')';
- client.element('css selector', cellSelector, function (objectResult) {
- this.elementIdAttribute(objectResult.value.ELEMENT, 'childElementCount', function(result1) {
- for (var j = 2; j < 22; j++) {
- cellSelector = tableSelector + ' > tbody > tr:nth-of-type(' + j + ') > td:nth-of-type(' + columnIndex + ')';
- client.element('css selector', cellSelector, function (objectResult) {
- this.elementIdAttribute(objectResult.value.ELEMENT, 'innerText', function(result) {
- columnValues.push(result.value);
- if (columnValues.length == 20) {
- callback(columnValues);
- }
- });
- });
- }
- });
- });
- });
- }
- var utils = require('../../lib/utils/getColumnValues.js');
- utils.getColumnValues('Route', 'table.table-striped', function (result) {
- //do something
- }
- // utils/awesome.js
- // Your utility functions
- module.exports = {
- firstFunction,
- };
- // Another file
- const utils = require('./utils/awesome.js');
- function second(){
- utils.firstFunction();
- // kaboom
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement