2475

How to efficiently test accessing a large file with Behat/Mink?

I'd like to write Behat/Mink scenarios to check whether certain user accounts can download a large file. I can use the When I follow "largefile.zip" event, but that appears to download the entire file.

Rather than wasting time and resources streaming the large file, I'd like to (for example) just check the result of an HTTP HEAD request, or just try to start downloading the file with an HTTP GET request and then cancel it immediately and check the response status code.

How can I do that with Behat/Mink?

Answer1:

I agree with @NathanStretch regarding extending, so here's what i did.

This example is based on using http://download.thinkbroadband.com/5MB.zip as the download url. Not perfect since i don't see the file name in the response headers, but it does have Content Length.

<?php class DownloadContext extends Behat\MinkExtension\Context\RawMinkContext { private $headers = []; /** * @When /^I try to download "([^"]*)"$/ */ public function iTryToDownload($url) { $this->headers = get_headers($url); } /** * @Then /^I should see in the header "([^"]*)"$/ */ public function iShouldSeeInTheHeader($header) { assert(in_array($header, $this->headers), "Did not see \"$header\" in the headers."); } }

With a .feature file that had the following:

Scenario: Try to download a file When I try to download https://www.e-learn.cn/content/wangluowenzhang/"http://download.thinkbroadband.com/5MB.zip" Then I should see in the header "Content-Length: 5242880"

If you have control over the downloads themselves then you can set the filename in the headers and check for that instead of the size. Certainly better if the size can be variable since i think that would mean having to split the content length string, converting to an int and then doing a comparison. Ugh. There's probably a more elegant solution to that.

Hope that helps somewhat.

Recommend

  • how to create a downloadable csv file in appengine
  • WCF hosting issues
  • Memory usage and time for execution for another process using C#?
  • Meteor: Block access to application if user's email is not verified
  • Authentication - JavaScript - Logout issue
  • phpmailer - How to verify a sent email arrived at its destination
  • dismiss Progress Dialog in another Activity … Android
  • Using an STL Iterator without initialising it
  • Caliburn Micro, How to use ContentControl (or display 'sub' ViewModel) using ViewModel Fir
  • Perspective projection, 4 points
  • Can't remove headers after they are sent
  • Tell Git to stop prompting me for conflicts when none really exist?
  • How to use JavaScript to determine whether a file exists in a directory?
  • How to suppress a dialog
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Jquery UI tool tip close icon
  • Cancel a live stream “fast motion” catch-up in Flash
  • Display issues when we change from one jquery mobile page to another in firefox
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Symfony2: How to get request parameter
  • Numpy divide by zero. Why?
  • php design question - will a Helper help here?
  • Is there a mandatory requirement to switch app.yaml?
  • bootstrap to use multiple ng-app
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to get icons for entities from eclipse?
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • log4net write single file for each call to log.info
  • python regex in pyparsing
  • Getting error when using KSoap library to consume .NET web services
  • Android Google Maps API OnLocationChanged only called once
  • Turn off referential integrity in Derby? is it possible?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • JaxB to read class hierarchy
  • How to Embed XSL into XML
  • How can I use threading to 'tick' a timer to be accessed by other threads?