Behat/Mink — Issue #160: Add support for 'mousedown' and 'mouseup' or for firing custom events
Author: khepin
Created: 2012-01-04 17:13:29+00:00
State: open

I'm using Sahi right now and need to send a mousedown event and then a mouseup event on different elements. Kind of a cell selection in an excel sheet for example. Right now the only way to do it is quite complicated:

public function testPlanning()
{
$session = $this->getSession('sahi');
$session->visit($this->base . '/planning');
$page = $session->getPage();
$els = $page->findAll('css', '.selectable');
// everything was standard so far
// get the session driver
$d = $session->getDriver();
// Here I just mimicked what is done for other events such as click. Since "prepareXPath" is
// a private method of the driver, I also had to copy that here, then I get the 'ByXPathAccessor'
// for my element.
$accessor = $d->getClient()->findByXPath($this->prepareXPath($els[10]->getXPath()));
// Once I have that accessor I can reproduce what's done in the Sahi client to send events
$accessor->getConnection()->executeStep(sprintf('_sahi._mouseDown(%s)', $accessor->getAccessor()));

// Rince and repeat for 'mouseup'
$accessor = $d->getClient()->findByXPath($this->prepareXPath($els[20]->getXPath()));
$accessor->getConnection()->executeStep(sprintf('_sahi._mouseUp(%s)', $accessor->getAccessor()));

// ... Keep testing stuff
}

/**
* I need to reproduce this here because the Driver has this as a private method.
*/
public function prepareXPath($xpath)
{
return strtr($xpath, array('"' => '\\"'));
}

Would be great to directly have the possibility to use `$el->mouseDown()` and `$el->mouseUp()` or otherwise to have a general purpose `$el->fireEvent($eventName|$eventDefinition)` to be used here.