Downloading a File via Redirect Link
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Downloading a File via Redirect Link
Greetings,
I am trying to construct a test for downloading a file from my employer's site in different browsers (IE, FireFox, Chrome) and I am using the Javascript solution provided here:
https://support.smartbear.com/viewarticle/8999/?st=0
However, I receive an error when I provide the download URL as the target URL (strFileURL). It may or may not be important to note that the URL I provide to the Javascript function is a redirect URL: https://[site]/common/redirect.cfm?/tcmain/common/filedownload.cfm+Filename=[FileName].xls&Path=//carrier%20rosters/Medical/&AdminPath=true
Here is the error I receive when executing the javascript function:
Error: 0x80072ee6
Error location:
Line: 20 Column: 11.
// Download the file
objHTTP.open("GET", SrcFileURL, false);
Any advice would be greatly appreciated. Thank you.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I read correctly, all you want to determine is if the file downloads correctly, right?
That's not a browser specific task... that's just making sure that, when a request is sent, the file properly downloads... That's a web server side, not a client side task, if I'm understanding things properly.
So... what I would do is this.
1) Split the test... test 1 is to verify that the link you intend to click on has the proper URL for doing the redirect
2) Run the download test in a browser that you CAN actually run it in (Chrome, Firefox... not IE) to verify that the file is downloaded properly.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Yes, Robert is correct.
Just several more notes:
a) TestComplete perfectly supports cross-browser testing and Save File dialog handling. See help for the .SaveFile() method for more details and code samples;
b) One of the recommended ways when working with files download from the web is not to do actual download, but just to check if the web server can return requested file. This is done with the help of the HEAD request. If the HEAD request succeeds this means that the server will be able to provide requested file.
c) Your code misses part with ADO.Stream from the referenced article. This part is essential if you need to store downloaded file to hard drive;
d) I would recommend to use some recording proxy (Fiddler, for example) and record the generated traffic when you download the file from web browser. Then you need to analyse recorded traffic to figure out if some request header and/or authorization is required;
e) MSXML2.ServerXMLHTTP and WinHTTP.WinHttpRequest.5.1 objects that are usually used to issue web requests from test code have .Option property. In the past I used this property to ignore certificate errors. I think that some similair option to automatically handle redirects exists as well. Check the documentation for the object you'd like to use.
Just for a reference, the relevant code in my case looked like this:
http = HTTPObjectGet('WinHTTP.WinHttpRequest.5.1', false); http.open('POST', cWebServiceURL, false); // or // http.open('POST', cWebServiceURL, false, '<login>', 'password'); // http.setRequestHeader("Authorization", 'Basic abc123='); // Base64-encoded login/password, depending on the call requirements // http.setRequestHeader("Content-Type", 'application/xml'); // or some other required request header(s) http.send(strBody); // for POST calls // or // http.send(); // for GET calls ... //---------------------------------------------------------------------------- function HTTPObjectGet(strObjectId, bIgnoreServerCertErrors) { // Ignore errors like 'invalid certificate' on the server var SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056; var cDefaultHTTP = 'MSXML2.ServerXMLHTTP'; var oHTTP; strObjectId = strObjectId || cDefaultHTTP;
if ('undefined' == typeof bIgnoreServerCertErrors)
bIgnoreServerCertErrors = true; try { oHTTP = Sys.OleObject(strObjectId); } catch(e) { Log.Error(aqString.Format('Failure to create requested %s object. Test stopped.', aqString.Quote(strObjectId)), strObjectId + '\n' + e.Message); // Runner.Stop(true); // stop current test only } if (bIgnoreServerCertErrors) { try { oHTTP.setOption(2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS); // MSXML2.ServerXMLHTTP version } catch(e) { try { oHTTP.Option(4) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS; // WinHTTP.WinHttpRequest.5.1 version } catch(e) { // Log.Error('Failure to set option to ignore http server errors', e.Message); } } } return oHTTP; } //----------------------------------------------------------------------------
/Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for your advice.

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »