0

I am testing an AngularJS site using Selenium.

A test involves downloading a file from the site.

My original plan was to download the file directly using Selenium (by clicking on the export button via Selenium and then waiting for the file to download using Wait for finished download file in selenium and c#this answer or similar). However, this is explicitly discouraged by Selenium (https://selenium.dev/documentation/en/worst_practices/file_downloads/).

Inspecting the export button reveals that it calls a function named export:

<button type="button" class="btn btn-warning" ng-click="export()">{{'export' | translate}}</button>

By observation, it appears that the export button creates a file server-side with a fresh GUID and then starts a download using that file.

My new plan is to obtain the download link and then download it using How to download a file from a website in C#this answer or similar. However, the link to the file is only valid if you are logged in, so I would also need to simulate that somehow.

Authentication is performed by requiring an OAuth bearer token on each request.

How can I find the download link of a file (given that it is obscured by a function) and then download it (given that access to file is restricted to logged-in users)?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Sepia
  • 447
  • 6
  • 21
  • 1
    It really depends on the authentication scheme used by the file provider. If it is just basic auth, you might be able to append your credentials either in "https://username:password@mywebsite.com" given the file download URL. but this is entirely dependent on the configuration of party who is requesting authentication. – CEH Nov 25 '19 at 15:07
  • @Christine Good point. I've edited the authentication scheme into the question. – Sepia Nov 25 '19 at 15:25
  • If the website used OAuth, you'll need some kind of interaction with the website to obtain a token via OAuth "handshake". If you can get a valid Oauth token, you can probably just make a request to the download URL & append your Oauth token in the auth headers. – CEH Nov 25 '19 at 15:34
  • 1
    I can't fathom why they are saying clicking the link is bad practice. That is exactly what you should be doing to test the site. You could have a bug there that is only exposed by clicking the button. – pcalkins Nov 25 '19 at 21:36

0 Answers0