Skip to content

Commit

Permalink
#972 - get_text() between 2 anchors in text
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed May 27, 2021
1 parent 731a735 commit 7a69560
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/tagui_global.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OBJECT,DEFINITION
email,myEmail
password,myPassword
email,name@mail.com
password,secret123
30 changes: 20 additions & 10 deletions src/tagui_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,28 @@ function sanitise_csv_cell(cell_data) {
* encode as a CSV row
*/
function csv_row(original_row_data) {
var row_data = original_row_data.slice()
// if row_data has at least 1 element, extract and sanitise first element
// else start_element is empty string
var start_element = (row_data.length > 0)
? sanitise_csv_cell(row_data.shift())
: ''
// concat each row_data with a comma
return row_data.reduce(function(accumulator, currentValue) {
return accumulator + ',' + sanitise_csv_cell(currentValue)
}, start_element)
var row_data = original_row_data.slice()
// if row_data has at least 1 element, extract and sanitise first element
// else start_element is empty string
var start_element = (row_data.length > 0)
? sanitise_csv_cell(row_data.shift())
: ''
// concat each row_data with a comma
return row_data.reduce(function(accumulator, currentValue) {
return accumulator + ',' + sanitise_csv_cell(currentValue)
}, start_element)
}

// retrieve text between 2 provided anchors in given text content
function get_text(source_text, left_marker, right_marker, optional_count) {
if (!source_text || !left_marker || !right_marker) return '';
var left_position = source_text.indexOf(left_marker); if (left_position == -1) return '';
var right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';
if (optional_count > 1) {var occurrence_count = 2; while(occurrence_count <= optional_count) {occurrence_count++;
left_position = source_text.indexOf(left_marker, right_position+1); if (left_position == -1) return '';
right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';}}
return source_text.slice(left_position + left_marker.length, right_position).trim();}

// for initialising integration with sikuli visual automation
function sikuli_handshake() { // techo('[connecting to sikuli process]');
var ds; if (flow_path.indexOf('/') !== -1) ds = '/'; else ds = '\\'; clear_sikuli_text();
Expand Down
34 changes: 21 additions & 13 deletions src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,28 @@ function sanitise_csv_cell(cell_data) {
* encode as a CSV row
*/
function csv_row(original_row_data) {
var row_data = original_row_data.slice()
// if row_data has at least 1 element, extract and sanitise first element
// else start_element is empty string
var start_element = (row_data.length > 0)
? sanitise_csv_cell(row_data.shift())
: ''
// concat each row_data with a comma
return row_data.reduce(function(accumulator, currentValue) {
return accumulator + ',' + sanitise_csv_cell(currentValue)
}, start_element)
var row_data = original_row_data.slice()
// if row_data has at least 1 element, extract and sanitise first element
// else start_element is empty string
var start_element = (row_data.length > 0)
? sanitise_csv_cell(row_data.shift())
: ''
// concat each row_data with a comma
return row_data.reduce(function(accumulator, currentValue) {
return accumulator + ',' + sanitise_csv_cell(currentValue)
}, start_element)
}

// retrieve text between 2 provided anchors in given text content
function get_text(source_text, left_marker, right_marker, optional_count) {
if (!source_text || !left_marker || !right_marker) return '';
var left_position = source_text.indexOf(left_marker); if (left_position == -1) return '';
var right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';
if (optional_count > 1) {var occurrence_count = 2; while(occurrence_count <= optional_count) {occurrence_count++;
left_position = source_text.indexOf(left_marker, right_position+1); if (left_position == -1) return '';
right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';}}
return source_text.slice(left_position + left_marker.length, right_position).trim();}

// for initialising integration with sikuli visual automation
function sikuli_handshake() { // techo('[connecting to sikuli process]');
var ds; if (flow_path.indexOf('/') !== -1) ds = '/'; else ds = '\\'; clear_sikuli_text();
Expand Down Expand Up @@ -877,7 +887,7 @@ if (lc_raw_intent.substr(0,4) == 'api ') return 'api';
if (lc_raw_intent.substr(0,4) == 'run ') return 'run';
if (lc_raw_intent.substr(0,4) == 'dom ') return 'dom';
if (lc_raw_intent.substr(0,3) == 'js ') return 'js';
if (lc_raw_intent.substr(0,2) == 'r ') return 'r';
if ((lc_raw_intent.substr(0,2) == 'r ') && (lc_raw_intent.substr(0,3) != 'r =')) return 'r';
if (lc_raw_intent.substr(0,3) == 'py ') return 'py';
if (lc_raw_intent.substr(0,7) == 'vision ') return 'vision';
if (lc_raw_intent.substr(0,8) == 'timeout ') return 'timeout';
Expand Down Expand Up @@ -1466,8 +1476,6 @@ phantom.onError = function(msg, trace) {if (msg.indexOf('Error:') !== -1) { // c
msg = msg.substring(msg.indexOf('Error:')+6).trim(); msg = msg.charAt(0).toLowerCase() + msg.slice(1);}
casper.echo('ERROR - ' + msg).exit();}

// define repository and datatable variables

// flow path for save_text and snap_image
var flow_path = '/full_path';

Expand Down

0 comments on commit 7a69560

Please sign in to comment.