Can't upload a file with Sahi / Mink / Behat in a Symfony2 application
Asked Answered
C

2

7

I am using Mink and Sahi for my user interface tests inside a Symfony2 application. But actually I can't manage to upload a file with Sahi.

My Sahi server is up and running:

[09:51:33] coil@ubuntu:~/Webdev/sahi/bin$ ./sahi.sh 
--------
SAHI_HOME: ..
SAHI_USERDATA_DIR: ../userdata
SAHI_EXT_CLASS_PATH:
--------
Sahi properties file = /home/coil/Webdev/sahi/config/sahi.properties
Sahi user properties file = /home/coil/Webdev/sahi/userdata/config/userdata.properties
Added shutdown hook.
>>>> Sahi started. Listening on port: 9999
>>>> Configure your browser to use this server and port as its proxy
>>>> Browse any page and CTRL-ALT-DblClick on the page to bring up the Sahi Controller
-----
Reading browser types from: /home/coil/Webdev/sahi/userdata/config/browser_types.xml
-----

My step implementation:

    // $element->getXpath() --> (//html/descendant-or-self::*[@id = 'attachment'])[1]
$element->attachFile($file);

Note here that if I use a file that is not /home/coil/Webdev/sahi/userdata directory, I get the following error:

$element->attachFile('toto');
error:_setFile2(_byXPath("(//html/descendant-or-self::*[@id = 'attachment'])[1]"), "toto")
      Error: File not found: toto; Base directory is userdata directory: /home/coil/Webdev/sahi/userdata
      Error: File not found: toto; Base directory is userdata directory: /home/coil/Webdev/sahi/userdata
      at Sahi._setFile (http://dev.project.com/_s_/spr/concat.js:1398:12)
      at Sahi._setFile2 (http://dev.project.com/_s_/spr/concat.js:1367:7)
      at eval (eval at <anonymous> (http://dev.project.com/_s_/spr/concat.js:3480:14), <anonymous>:1:7)
      at Sahi.ex (http://dev.project.com/_s_/spr/concat.js:3480:9)
      at <anonymous>:1:11
      <a href='/_s_/dyn/Log_getBrowserScript?href=null&n=-1'><b>Click for browser script</b></a>

So, Sahi can "find" the file as it doesn't raise any error with a valid and existing file. But when the form is submitted, the file is never uploaded by the Sahi proxy.

Other checks:

  • I removed the client side HTML5 and JavaScript validation to be sure there is no side effect.
  • All my other Sahi tests are Ok, only the 3 with an Upload don't pass
  • The proxy is set in my testing browser
  • I can open the Sahi controller in the browser without problem
  • Same problem on MaxOsX and Ubuntu
  • Each time I run an upload test, I've got a new entry in /userdata/temp/download named like sahi_11a83f8806be8046fc0aaa80eac076110b95__fr-fr-2-0.bdic

What is really weird, is that I am sure that those tests passed some times ago, something must have changed in my application or configuration that breaks the Sahi file upload but I can't find what. And before in the Sahi console I had logs about the files that it was uploading, now there is no log at all.

Corker answered 14/2, 2013 at 9:41 Comment(2)
Are you running the application in "dev" or in "production" environment? That may be the reason why you don't see any logs?Brazenfaced
It uses the test environment. But I am talking about the Sahi logs not the application logs.Corker
I
1

Is the url to which the form is posted different from the url of the web page? _setFile and _setFile2 take a third parameter which can be configured to point to the action URL (the url to which the file should be attached by the Sahi Proxy) http://sahi.co.in/w/_setFile

Icaria answered 14/2, 2013 at 12:36 Comment(2)
The form post in the same URL as the form itself: <form id="apply" action="/app_test.php/postuler-1" method="post" enctype="multipart/form-data" xmlns="http://www.w3.org/1999/html">Corker
I also tried with _setFile2 on the last version of Sahi, without success.Corker
R
2

Use absolute system path to which Sahi server has access.

Reubenreuchlin answered 14/2, 2013 at 9:54 Comment(3)
I tried with /tmp/file.doc without success. I really feel that something is not well configured at the proxy level.Corker
Might be. But I'm sure uploading works as SahiDriver test suite passes. And it has file upload test case :/Reubenreuchlin
If you run only the upload test, do you have a log in the /bin/sahi.sh console showing what file is being uploaded ?Corker
I
1

Is the url to which the form is posted different from the url of the web page? _setFile and _setFile2 take a third parameter which can be configured to point to the action URL (the url to which the file should be attached by the Sahi Proxy) http://sahi.co.in/w/_setFile

Icaria answered 14/2, 2013 at 12:36 Comment(2)
The form post in the same URL as the form itself: <form id="apply" action="/app_test.php/postuler-1" method="post" enctype="multipart/form-data" xmlns="http://www.w3.org/1999/html">Corker
I also tried with _setFile2 on the last version of Sahi, without success.Corker

© 2022 - 2024 — McMap. All rights reserved.