add ability to re-run replace#659
Conversation
|
Please explain use case of proposed code change. You should be registering new selectors in constructor prior to parent constructor call instead. |
|
How can I owerride default class when it is constructed in SelectorsHandler constructor explicite? Furthermore I think that this is better than extending parent class. For example I add new selector and also I want to use another developer selector. There is no way to combine this two class besides copy&paste. |
You can register your own selectors handler (that might extend default one if you wish) under same name as any of build-in selectors handlers. Any use case besides just extending? I suppose default behavior of doing partial match first and exact match send isn't what you need. In that case you need to use // for exact match only
$registerForm = $page->find('named_exact', array('field', 'field-name-here');
// for partial match only
$registerForm = $page->find('named_partial', array('field', 'field-name-here');
// for partial and then exactly if partial didn't find anything match only
$registerForm = $page->find('named', array('field', 'field-name-here'); |
|
OK, but this is hell. For example I have two new selectors(MySelector, AnotherSelector) so I need to make 2 new classes(MyNamedSelector, AnotherNamedSelector). When I want tu use exact and partial matches I need 4 classes(MyNamedSelectorExact, MyNamedSelectorPartial, AnotherNamedSelectorExact, AnotherNamedSelectorPartial). And when I want to use it i need to do it like this: // for my selector exact match
$registerForm = $page->find('my_named_selector_exact', array('my_selector', 'field-name-here');
// for my selector partial match
$registerForm = $page->find('my_named_selector_partial', array('my_selector', 'field-name-here');
// for another selector exact match
$registerForm = $page->find('another_named_selector_exact', array('another_selector', 'field-name-here');
// for another selector partial match
$registerForm = $page->find('another_named_selector_partial', array('another_selector', 'field-name-here'); |
|
Sorry for confusion. Let's start over if you don't mind. Please explain problem you're trying to solve (use case) forgetting for a moment about this PR and |
|
Sorry for the delay @fugi . If I get you right you want to add new That is partially possible with this code: $selectorsHandler = new \Behat\Mink\Selector\SelectorsHandler();
$namedPartialSelector = $selectorsHandler->getSelector('named_partial');
$namedPartialSelector->registerNamedXpath('new_name', 'new_xpath');
$namedExactSelector = $selectorsHandler->getSelector('named_exact');
$namedExactSelector->registerNamedXpath('new_name', 'new_xpath');
$session = new \Behat\Mink\Session($driver, $selectorsHandler);The only issue with above approach (that doesn't involve extending classes) is fact, that If that is what you're after, then please update PR to fix behavior of |
Usefull especialy when register new replacement or selector.