首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用Behat Mink扩展框架在输入字段中附加文件(csv文件)

无法使用Behat Mink扩展框架在输入字段中附加文件(csv文件)
EN

Stack Overflow用户
提问于 2013-06-28 13:50:26
回答 1查看 2.8K关注 0票数 2

我想附加一个CSV文件到一个输入字段类型" file“使用Behat Framework(Mink扩展名)。

输入字段的Html --输入id=“编辑-ab-csv-文件”class=-文件“type=”文件“size="60”name="filesab_csv_file">

我们已经尝试过在Driverinterface中使用attachfile()方法

代码语言:javascript
运行
复制
/**
 * 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脚本

代码语言:javascript
运行
复制
$jscript = "document.getElementById('edit-ab-csv-file').value='//home//developer//build//tools//behat//Invaliduploadfile.csv';";
  $this->getSession()->getDriver()->executeScript($jscript);

我有个例外说

代码语言:javascript
运行
复制
 The operation is insecure. (WARNING: The server did not provide any stack trace information)
      Command duration or timeout: 10 milliseconds

有人能帮我解决这个问题吗。

EN

回答 1

Stack Overflow用户

发布于 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”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17366258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档