Created
September 20, 2018 12:12
-
-
Save matt-halliday/fd7ebb6e8ab49776dffb8e55dde4e0c8 to your computer and use it in GitHub Desktop.
Append files to file input in Behat with Selenium2 Driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Given I attach the file :path | |
* @param string $path | |
*/ | |
public function iAttachTheFile(string $path) | |
{ | |
// Get absolute local path | |
$localFile = '/var/www/html/' . $path; | |
// Convert to zip file | |
$tempZip = tempnam('', 'WebDriverZip'); | |
$zip = new \ZipArchive(); | |
$zip->open($tempZip, \ZipArchive::CREATE); | |
$zip->addFile($localFile, basename($localFile)); | |
$zip->close(); | |
$remotePath = $this->minkContext->getSession()->getDriver()->getWebDriverSession()->file([ | |
'file' => base64_encode(file_get_contents($tempZip)) | |
]); | |
$input = $this->minkContext->getSession()->getPage()->find('xpath', '//input[@type=\'file\']'); | |
$input->attachFile($remotePath); | |
unlink($tempZip); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment