我想附加一个CSV文件到一个输入字段类型" file“使用Behat Framework(Mink扩展名)。
输入字段的Html --输入id=“编辑-ab-csv-文件”class=-文件“type=”文件“size="60”name="filesab_csv_file">
我们已经尝试过在Driverinterface中使用attachfile()方法
/**
* Attaches file to field with specified id|name|label|value.
*
* @When /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
*/
public function attachFileToField($field, $path)
{
$field = $this->fixStepArgument($field);
if ($this->getMinkParameter('files_path')) {
$fullPath = rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$path;
if (is_file($fullPath)) {
$path = $fullPath;
}
}
$this->getSession()->getPage()->attachFileToField($field, $path);
}
}第二种方法--我们尝试使用Java脚本
$jscript = "document.getElementById('edit-ab-csv-file').value='//home//developer//build//tools//behat//Invaliduploadfile.csv';";
$this->getSession()->getDriver()->executeScript($jscript);我有个例外说
The operation is insecure. (WARNING: The server did not provide any stack trace information)
Command duration or timeout: 10 milliseconds有人能帮我解决这个问题吗。
发布于 2013-09-22 17:55:52
第一种方法对我有用。不要忘记使用文件的完整路径或使用files_path Mink配置设置。
查看此论坛帖子:https://groups.google.com/forum/#!topic/behat/vxZAssi2Nf8
Mink需要一个绝对路径才能上传文件,但是很明显,这个路径在其他环境中可能行不通。相反,您可以向Yaml配置文件提供一个"file_paths“属性: 延期: Behat\MinkExtension\ files_path:“path/to/file”
https://stackoverflow.com/questions/17366258
复制相似问题