Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param   Behat\Mink\Driver\Zombie\Connection $conn       a Zombie.js connection
  * @param   Behat\Mink\Driver\Zombie\Server     $server     a Zombie.js server
  * @param   Boolean                             $autoServer automatically create Zombie.js server
  */
 public function __construct(Connection $conn = null, Server $server = null, $autoServer = true)
 {
     if (null === $conn) {
         $conn = new Connection();
     }
     if ($autoServer && null === $server) {
         $server = new Server($conn->getHost(), $conn->getPort());
     } elseif (!$autoServer) {
         $server = null;
     }
     $this->conn = $conn;
     $this->server = $server;
 }
Exemplo n.º 2
0
    /**
     * Triggers a keyboard event
     *
     * @param   string  $type      The event name
     * @param   string  $xpath     The xpath of the element to trigger this event on
     * @param   mixed   $char      could be either char ('b') or char-code (98)
     * @param   string  $modifier  keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
     */
    protected function triggerKeyEvent($name, $xpath, $char, $modifier)
    {
        if (!($ref = $this->getNativeRefForXPath($xpath))) {
            return;
        }
        $char = is_numeric($char) ? $char : ord($char);
        $isCtrlKeyArg = $modifier == 'ctrl' ? "true" : "false";
        $isAltKeyArg = $modifier == 'alt' ? "true" : "false";
        $isShiftKeyArg = $modifier == 'shift' ? "true" : "false";
        $isMetaKeyArg = $modifier == 'meta' ? "true" : "false";
        $js = <<<JS
var node = {$ref},
    window = browser.window,
    e = window.document.createEvent("UIEvents");
e.initUIEvent("{$name}", true, true, window, 1);
e.ctrlKey = {$isCtrlKeyArg};
e.altKey = {$isAltKeyArg};
e.shiftKey = {$isShiftKeyArg};
e.metaKey = {$isMetaKeyArg};
e.keyCode = {$char};
node.dispatchEvent(e);
stream.end();
JS;
        $this->conn->evalJS($js);
    }