diff --git a/src/Command/CommandRunner.php b/src/Command/CommandRunner.php index 78858460..8ad4cb70 100644 --- a/src/Command/CommandRunner.php +++ b/src/Command/CommandRunner.php @@ -58,4 +58,9 @@ protected function getSelect(WebDriverElement $element): WebDriverSelect { return new WebDriverSelect($element); } + + public function validateTarget(CommandInterface $command): bool + { + return $command->getTarget() && $this->isValidSelector($command->getTarget()); + } } diff --git a/src/Command/Runner/CustomCommandRunner.php b/src/Command/Runner/CustomCommandRunner.php new file mode 100644 index 00000000..aa9d9395 --- /dev/null +++ b/src/Command/Runner/CustomCommandRunner.php @@ -0,0 +1,54 @@ +getAllCommands(); + } + + public function getCommandsRequireValue(): array + { + return $this->getAllCommands(); + } + + public function run(CommandInterface $command, ValuesInterface $values, RemoteWebDriver $driver): void + { + switch ($command->getCommand()) { + case self::UPLOAD: + $driver + ->findElement($this->getSelector($command->getTarget())) + ->setFileDetector(new LocalFileDetector()) + ->sendKeys($this->getFilePath($command)); + break; + default: + break; + } + } + + protected function getFilePath(CommandInterface $command): string + { + return $this->uploadDir . DIRECTORY_SEPARATOR . (string) $command->getValue(); + } +} diff --git a/src/Command/Runner/KeyboardCommandRunner.php b/src/Command/Runner/KeyboardCommandRunner.php index 21ef7a38..4ffb072a 100644 --- a/src/Command/Runner/KeyboardCommandRunner.php +++ b/src/Command/Runner/KeyboardCommandRunner.php @@ -51,11 +51,6 @@ public function run(CommandInterface $command, ValuesInterface $values, RemoteWe } } - public function validateTarget(CommandInterface $command): bool - { - return $command->getTarget() && $this->isValidSelector($command->getTarget()); - } - /** * Don't allow to upload local file. */ diff --git a/src/Command/Runner/MouseCommandRunner.php b/src/Command/Runner/MouseCommandRunner.php index 8a2e5e60..5ac4be08 100644 --- a/src/Command/Runner/MouseCommandRunner.php +++ b/src/Command/Runner/MouseCommandRunner.php @@ -219,11 +219,6 @@ public function run(CommandInterface $command, ValuesInterface $values, RemoteWe } } - public function validateTarget(CommandInterface $command): bool - { - return $command->getTarget() && $this->isValidSelector($command->getTarget()); - } - protected function getPoint(string $target): WebDriverPoint { list($x, $y) = explode(',', $target); diff --git a/src/Command/Runner/WaitCommandRunner.php b/src/Command/Runner/WaitCommandRunner.php index 6873fa3b..8ac874f0 100644 --- a/src/Command/Runner/WaitCommandRunner.php +++ b/src/Command/Runner/WaitCommandRunner.php @@ -87,9 +87,4 @@ public function run(CommandInterface $command, ValuesInterface $values, RemoteWe break; } } - - public function validateTarget(CommandInterface $command): bool - { - return $command->getTarget() && $this->isValidSelector($command->getTarget()); - } } diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index e7e6e956..906fbb9a 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -19,6 +19,7 @@ use Tienvx\Bundle\MbtBundle\Command\CommandRunnerManagerInterface; use Tienvx\Bundle\MbtBundle\Command\Runner\AlertCommandRunner; use Tienvx\Bundle\MbtBundle\Command\Runner\AssertionRunner; +use Tienvx\Bundle\MbtBundle\Command\Runner\CustomCommandRunner; use Tienvx\Bundle\MbtBundle\Command\Runner\KeyboardCommandRunner; use Tienvx\Bundle\MbtBundle\Command\Runner\MouseCommandRunner; use Tienvx\Bundle\MbtBundle\Command\Runner\ScriptCommandRunner; @@ -196,6 +197,8 @@ ->autoconfigure(true) ->set(WindowCommandRunner::class) ->autoconfigure(true) + ->set(CustomCommandRunner::class) + ->autoconfigure(true) // Repositories ->set(BugRepository::class)