public function DrupalSelenium2Driver::attachFile in Drupal 9
File
- core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php, line 49
Class
- DrupalSelenium2Driver
- Provides a driver for Selenium testing.
Namespace
Drupal\FunctionalJavascriptTests
Code
public function attachFile($xpath, $path) {
$element = $this
->getWebDriverSession()
->element('xpath', $xpath);
if ('input' !== strtolower($element
->name()) || 'file' !== strtolower($element
->attribute('type'))) {
$message = 'Impossible to %s the element with XPath "%s" as it is not a %s input';
throw new DriverException(sprintf($message, 'attach a file on', $xpath, 'file'));
}
try {
$remotePath = $this
->uploadFileAndGetRemoteFilePath($path);
} catch (\Exception $e) {
$remotePath = $path;
}
$element
->postValue([
'value' => [
$remotePath,
],
]);
}