Skip to content

Commit

Permalink
#191 - update snap logic to work for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed May 31, 2018
1 parent 5890e77 commit 072ede7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/tagui_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ chrome.captureSelector = function(filename,selector) { // capture screenshot of
// first capture entire screen, then use casperjs / phantomjs browser to crop image base on selector dimensions
chrome.capture(filename); var selector_rect = chrome.getRect(selector); // so that there is no extra dependency
if (selector_rect.width > 0 && selector_rect.height > 0) // from using other libraries or creating html canvas
casper.thenOpen(filename, function() {casper . capture(filename, // spaces around . intentional to avoid replacing
casper.thenOpen(file_url(filename), function() {casper . capture(filename, // spaces around . to avoid replacing
{top: selector_rect.top, left: selector_rect.left, width: selector_rect.width, height: selector_rect.height});
casper.thenOpen('about:blank');});}; // reset phantomjs browser state

Expand Down Expand Up @@ -760,6 +760,11 @@ if ((raw_intent.substr(0,2) == '//') || (raw_intent.charAt(raw_intent.length-1)
// assume = is assignment statement, kinda acceptable as this is checked at the very end
if (raw_intent.indexOf('=') > -1) return true; return false;}

function file_url(absolute_filename) { // helper function to append file:// according for opening local files
if (!absolute_filename || absolute_filename == '') return '';
if (absolute_filename.substr(0,1) == '/') return 'file://' + absolute_filename;
if (absolute_filename.substr(1,1) == ':') return 'file:///' + absolute_filename; return absolute_filename;}

function abs_file(filename) { // helper function to return absolute filename
if (filename == '') return ''; // unlike tagui_parse.php not deriving path from script variable
if (filename.substr(0,1) == '/') return filename; // return mac/linux absolute filename directly
Expand Down
49 changes: 48 additions & 1 deletion src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ if (casper.exists(x('//*[@href="'+locator+'"]'))) return true;
if (casper.exists(x('//*[contains(@href,"'+locator+'")]'))) return true;
return false;}

/**
* Extra TagUI helper methods
*/

// friendlier name to use check_tx() in if condition in flow
function present(element_locator) {if (!element_locator) return false; else return check_tx(element_locator);}

Expand Down Expand Up @@ -255,6 +259,44 @@ function sleep(ms) { // helper to add delay during loops
var time_now = new Date().getTime(); var time_end = time_now + ms;
while(time_now < time_end) {time_now = new Date().getTime();}}

/**
* string cell data sanitiser, returns a CSV formatted string
* @param {string} cell_data
*/
function sanitise_csv_cell(cell_data) {
// Replace all double quotes with 2 double quotes
cell_data = cell_data.replace(/"/g, '\"\"')
var whitespaceCheckRegex = /\s/
// if cell_data has a comma, or new line, or its first or last character is a
// whitespace, then wrap the entire expression in double quotes
if (
cell_data.indexOf(',') >= 0
|| cell_data.indexOf('\n') >= 0
|| whitespaceCheckRegex.test(cell_data.charAt(0))
|| whitespaceCheckRegex.test(cell_data.charAt(cell_data.length - 1))
) {
cell_data = '\"' + cell_data + '\"'
}
return cell_data
}

/**
* Returns a CSV-formatted string that denotes a row in a CSV file
* @param {string[]} row_data a 1-D array of strings denoting data to
* encode as a CSV row
*/
function csv_row(row_data) {
// 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)
}

// 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 @@ -501,7 +543,7 @@ chrome.captureSelector = function(filename,selector) { // capture screenshot of
// first capture entire screen, then use casperjs / phantomjs browser to crop image base on selector dimensions
chrome.capture(filename); var selector_rect = chrome.getRect(selector); // so that there is no extra dependency
if (selector_rect.width > 0 && selector_rect.height > 0) // from using other libraries or creating html canvas
casper.thenOpen(filename, function() {casper . capture(filename, // spaces around . intentional to avoid replacing
casper.thenOpen(file_url(filename), function() {casper . capture(filename, // spaces around . to avoid replacing
{top: selector_rect.top, left: selector_rect.left, width: selector_rect.width, height: selector_rect.height});
casper.thenOpen('about:blank');});}; // reset phantomjs browser state

Expand Down Expand Up @@ -745,6 +787,11 @@ if ((raw_intent.substr(0,2) == '//') || (raw_intent.charAt(raw_intent.length-1)
// assume = is assignment statement, kinda acceptable as this is checked at the very end
if (raw_intent.indexOf('=') > -1) return true; return false;}

function file_url(absolute_filename) { // helper function to append file:// according for opening local files
if (!absolute_filename || absolute_filename == '') return '';
if (absolute_filename.substr(0,1) == '/') return 'file://' + absolute_filename;
if (absolute_filename.substr(1,1) == ':') return 'file:///' + absolute_filename; return absolute_filename;}

function abs_file(filename) { // helper function to return absolute filename
if (filename == '') return ''; // unlike tagui_parse.php not deriving path from script variable
if (filename.substr(0,1) == '/') return filename; // return mac/linux absolute filename directly
Expand Down

0 comments on commit 072ede7

Please sign in to comment.