MinkExtension icon indicating copy to clipboard operation
MinkExtension copied to clipboard

Shrink down nodes - implement context

Open ScreamingDev opened this issue 7 years ago • 0 comments

Currently with every step the feature step implementations look on the whole HTML tree. This leads to problems (esp. in lists) as some buttons, labels and other could be duplicate. It would be lovely to shrink down the set of nodes so that further steps in the feature only look up things there.

Imagine this test:

Given I look at the first item
And I press "Delete"

The first step would be arbitrary implemented like:

// Dunno if this is completely valid but ...
$this->contextPath = '//table/tbody/tr[0]/';

Anyone can setup anything he likes there ("I look at {...} number {...}"). And the second step would apply to this:

$this->getDriver()->find( $this->context . "a[text()='Delete']" );

Or something like that.

Is that possible? How hard is it to implement? Will it be in the MinkExtension?

Seems like a little hack for \Behat\Mink\Selector\SelectorsHandler::selectorToXpath . Just:

// Keep global selector.
if ( substr($locator, 0,2) == "//" ) { return $locator; } 

// Handle relative
return $this->context . '/' . ltrim(locator, '/');

Where the initial context could be protected $context = '/'; which makes every relative request global unless some real context is defined. The context should reset on every new scenario. A Mink-Step like I look at the whole site could reset context within a scenario.

Would be great! :)

ScreamingDev avatar Mar 20 '17 09:03 ScreamingDev