Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
/bin/
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ private void loadJSHelperFiles() throws IOException {
* @param url
* @return Javascript string
*/
private String getDownloadJsCallScript(URL url) {
return ";return seleniumDownloadHelper.getB64Binary('" + url + "');";
private String getDownloadJsCallScript(URL url, String method, String param) {
return ";return seleniumDownloadHelper.getB64Binary('" + url + "','" + method + "','" + param + "');";
}

/**
Expand All @@ -87,14 +87,27 @@ private String getDownloadJsCallScript(URL url) {
* @return raw data
*/
public FileData getFileFromUrlRaw(URL url) {
return getFileFromUrlRaw(url, "GET", "null");
}

/**
* Executes XHR request trough JavaScript to download the given file in the context of the current WebDriver
* session.
*
* @param url
* @param method POST or GET
* @param param Parameters for the Post Request
* @return raw data
*/
public FileData getFileFromUrlRaw(URL url, String method, String param) {
String scriptCollection;
if (js instanceof InternetExplorerDriver) {
scriptCollection = ieHackTestJs + ieHackJs + base64Js + dlHelperJs + getDownloadJsCallScript(url);
scriptCollection = ieHackTestJs + ieHackJs + base64Js + dlHelperJs + getDownloadJsCallScript(url, method, param);
} else if (js instanceof HtmlUnitDriver) {
//throw new BrowserNotSupportedException("JS download hack is not working on HTMLUnit");
scriptCollection = skipIeHackTestJS + base64Js + dlHelperJs + getDownloadJsCallScript(url);
scriptCollection = skipIeHackTestJS + base64Js + dlHelperJs + getDownloadJsCallScript(url, method, param);
} else {
scriptCollection = ieHackTestJs + base64Js + dlHelperJs + getDownloadJsCallScript(url);
scriptCollection = ieHackTestJs + base64Js + dlHelperJs + getDownloadJsCallScript(url, method, param);
}
String jsRetVal = (String) js.executeScript(scriptCollection);
String[] jsRetArr = jsRetVal.split(":contentstarts:", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@


var seleniumDownloadHelper = {
getBinary: function (url) {
getBinary: function (url, method, param) {
// Mozilla/Safari/IE7+
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
// IE6
} else if (window.ActiveXObject) {
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
}

xhr.open("GET", url, false);
xhr.open(method, url, false);
if (xhr.overrideMimeType) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
} else {
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
}

xhr.send(null);
if (method == 'POST') {
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
xhr.send(param);

if (xhr.status != 200) return '';

Expand All @@ -43,8 +44,8 @@ var seleniumDownloadHelper = {
}
},

getB64Binary: function (url) {
var content = seleniumDownloadHelper.getBinary(url);
getB64Binary: function (url, method, param) {
var content = seleniumDownloadHelper.getBinary(url, method, param);
return content[0] + ":contentstarts:" + base64Encode(content[1]);
}
};