Upload file with Mink

32 Views Asked by At

In a Symfony 3.4 project using behat and Mink, I'm trying to upload a file with the attachFile method :

    public function iAddAFileInElementIfAvailable($arg)
    {
        if (!$fileInput = $this->getSession()->getPage()->find('css', $arg)) {
            return;
        }
        $filePath = __DIR__ . '/../../../AppBundle/Tests/Images/image-test.png';
        $imagePath = realpath($filePath);

        if ($imagePath === false) {
            throw new \RuntimeException(sprintf('Image file "%s" not found.', $filePath));
        }

        $fileInput->attachFile($imagePath);
    }

I have an Exception at the last line :

invalid argument: File not found : /tmp/aa7321558352b807e461cdfb451a4a0b/upload3799584816431765297file/image-test.png

However, the file is located in the specified folder. I checked the rights and permissions of /tmp, everything seems ok. I also tried specifying the files_path in the behat.yml file as follows:

  extensions:
    Behat\Symfony2Extension:
      kernel: ~
    Behat\MinkExtension:
      files_path: '%paths.base%/test'

...but the files are always moved to the /tmp folder.

0

There are 0 best solutions below