0

I am writing a Behat test that would download a .txt file. Figuring out how to handle the browser download dialog is a pain as it is not something Selenium can directly interact with. Since I am just doing this for one type of file I figured it'd be okay to avoid that problem by setting the browser default action for plain text files to save. Unfortunately it seems that each time Selenium starts up Firefox it has all preferences reset.

Is there any way to set default action and location for downloads, either in behat.yml, or when starting the selenium-standalone-server?

treep
  • 1
  • 1
  • Just a clarification: I looked at Firefox first, but the reset also happens with Chrome and I assume the others as well. I am looking for a generic way to set browser download preferences when starting with Selenium. – treep Jul 27 '15 at 16:23

1 Answers1

0

Why dont you use cURL or Guzzle for such task as downloading?

I would propose you get the file link using behat and then

$content = file_get_contents("file_link.txt");

Or another stackoverflow solution using Guzzle

use GuzzleHttp\Client;

$client = new Client([
  'base_url' => 'http://example.com',
  'defaults' => [
    'auth'    => ['user', 'pass'],
]]);

$xmlData = $client->get('/file.xml');
Community
  • 1
  • 1
Igor Lantushenko
  • 1,771
  • 10
  • 19
  • Ah I guess I forgot to mention: on the page there is a Download button. I want to verify that download starts _upon clicking the button_. I wanted to do it this way so that I am sticking to what actual user interaction would look like. I can make it work with file_get_contents if instead of actually clicking, I just get the button link and get contents from there. If you look at the browser as the test is going though, this wouldn't even show as a click.. actually you wouldn't see anything of the "download" happening. – treep Jul 27 '15 at 22:09