无法在Symfony2应用程序中使用Sahi/Mink/Behat上传文件

COi*_*Oil 7 php sahi symfony behat mink

我在Symfony2应用程序中使用Mink和Sahi进行用户界面测试.但实际上我无法使用Sahi上传文件.

我的Sahi服务器启动并运行:

[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
-----
Run Code Online (Sandbox Code Playgroud)

我的步骤实现:

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

请注意,如果我使用的文件不是/home/coil/Webdev/sahi/userdata目录,则会出现以下错误:

$element->attachFile('toto');
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)

因此,Sahi可以"找到"该文件,因为它不会引发有效和现有文件的任何错误.但是当提交表单时,Sahi代理不会上传该文件.

其他检查:

  • 我删除了客户端HTML5和JavaScript验证,以确保没有副作用.
  • 我所有的其他Sahi测试都没问题,只有3个上传的测试没有通过
  • 代理在我的测试浏览器中设置
  • 我可以毫无问题地在浏览器中打开Sahi控制器
  • MaxOsX和Ubuntu上的问题相同
  • 每次运行上传测试时,我都会在/ userdata/temp/download中找到一个名为like的新条目 sahi_11a83f8806be8046fc0aaa80eac076110b95__fr-fr-2-0.bdic

真正奇怪的是,我确信那些测试已经过去了一些,我的应用程序或配置中的某些内容必须已经改变,这打破了Sahi文件上传但我无法找到.之前在Sahi控制台中我记录了它上传的文件,现在根本没有日志.

Nar*_*man 1

表单发布到的 url 是否与网页的 url 不同?_setFile 和 _setFile2 采用第三个参数,可以将其配置为指向操作 URL(Sahi 代理应附加文件的 URL)http://sahi.co.in/w/_setFile