Skip to content

Commit

Permalink
#1035 - positive test signature for v6.46
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed Jun 16, 2021
1 parent c91347d commit 9f5582d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
31 changes: 21 additions & 10 deletions src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ var r_count = 0; var py_count = 0; var sikuli_count = 0; var chrome_id = 0;
// chrome context for frame handling and targetid for popup handling
var chrome_context = 'document'; var chrome_targetid = '';

// to track download path if set by user using 'download to location' step
var download_path = '';

// variables to track frame offset if current context is within a frame
var frame_step_offset_x = 0; var frame_step_offset_y = 0;
var original_frame_step_offset_x = 0; var original_frame_step_offset_y = 0;
Expand Down Expand Up @@ -374,7 +377,7 @@ function get_text(source_text, left_marker, right_marker, optional_count) {
return source_text.slice(left_position + left_marker.length, right_position).trim();}

// remove all occurrences of given characters from a given string
function remove_char(source_text, characters) {
function remove_chars(source_text, characters) {
if (!source_text) return ''; else if (!characters) return source_text;
characters = characters.replace(/\\n/g,'\n').replace(/\\r/g,'\r').replace(/\\t/g,'\t');
characters = characters.replace(/\\f/g,'\f').replace(/\\v/g,'\v').replace(/\\\\/g,'\\');
Expand Down Expand Up @@ -690,11 +693,18 @@ ws_json = JSON.parse(ws_message);
ws_message = chrome_step('DOM.disable'); // disable invoked DOM agent from running and firing events
} catch(e) {casper.echo('ERROR - unable to upload ' + selector + ' as ' + filename);}};

/* // backup of previous download implementation to switch to new download to location syntax
chrome.download = function(url,filename) { // download function for downloading url resource to file
// casper download cannot be used for urls which requires login as casperjs engine can't access chrome
// the chromium issue 696481 is moving well, else an alternative may be to inject casper clientutils.js
// TagUI by default auto-sets to allow downloads for headless Chrome (otherwise it prevents downloads)
casper.echo('ERROR - for headless and visible Chrome, download file using normal webpage interaction');};
casper.echo('ERROR - for headless and visible Chrome, download file using normal webpage interaction');}; */

chrome.download = function(location) { // download function for setting location of downloaded files
download_path = location; // to store the default download location for subsequent URL visits
// below replacement line to set path correctly on Windows to be sent to Chrome browser method
if (location.indexOf(':')>0) location = location.replace(/\//g,'\\').replace(/\\/g,'\\');
chrome_step('Page.setDownloadBehavior',{behavior: 'allow', downloadPath: location});}

chrome.evaluate = function(fn_statement,eval_json) { // evaluate expression in browser dom context
// chrome runtime.evaluate is different from casperjs evaluate, do some processing to reduce gap
Expand Down Expand Up @@ -1140,10 +1150,11 @@ else return "this.echo('ERROR - cannot find " + param1 + "')";}

function down_intent(raw_intent) {raw_intent = eval("'" + escape_bs(raw_intent) + "'"); // support dynamic variables
var params = ((raw_intent + ' ').substr(1+(raw_intent + ' ').indexOf(' '))).trim();
var param1 = (params.substr(0,params.indexOf(' to '))).trim();
var param2 = (params.substr(4+params.indexOf(' to '))).trim();
if ((param1 == '') || (param2 == '')) return "this.echo('ERROR - url/filename missing for " + raw_intent + "')";
else return "this.download('" + param1 + "','" + abs_file(param2) + "')";}
if (params.substr(0,3) != 'to ') params = 'to ' + params; // handle user missing out to separator
var param1 = (params.substr(0,params.indexOf('to '))).trim();
var param2 = (params.substr(3+params.indexOf('to '))).trim();
if (param2 == '') return "this.echo('ERROR - location missing for " + raw_intent + "')";
else return "this.download('" + abs_file(param2) + "')";}

function receive_intent(raw_intent) {raw_intent = eval("'" + escape_bs(raw_intent) + "'"); // support dynamic variables
return "this.echo('ERROR - step not supported in live mode, it requires creating CasperJS event')";}
Expand Down Expand Up @@ -2746,11 +2757,11 @@ function timeout() {this.capture('/full_path/positive_test_error.png');
this.echo('ERROR - cannot find #css_selector').exit(); this.wait(0);});}});

// test download
casper.then(function() {{techo('download http://www.dummytestsite.com/report/month.txt to filename.txt');
this.download('http://www.dummytestsite.com/report/month.txt','/full_path/filename.txt');}});
casper.then(function() {{techo('download to C:\Downloads\RPA');
this.download('C:/Downloads/RPA');}});

casper.then(function() {{techo('download http://www.dummytestsite.com/report/month.txt to /tmp/filename.txt');
this.download('http://www.dummytestsite.com/report/month.txt','/tmp/filename.txt');}});
casper.then(function() {{techo('download to /Users/username/Desktop');
this.download('/Users/username/Desktop');}});

// test receive
casper.then(function() {{techo('receive report to filename.txt');
Expand Down
4 changes: 2 additions & 2 deletions src/test/positive_test.tag
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ upload #css_selector as abc.png
upload #css_selector as /tmp/abc.png

// test download
download http://www.dummytestsite.com/report/month.txt to filename.txt
download http://www.dummytestsite.com/report/month.txt to /tmp/filename.txt
download to C:\Downloads\RPA
download to /Users/username/Desktop

// test receive
receive report to filename.txt
Expand Down

0 comments on commit 9f5582d

Please sign in to comment.