Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing autocompleters #188

Open
derrabus opened this issue Nov 26, 2014 · 5 comments
Open

Testing autocompleters #188

derrabus opened this issue Nov 26, 2014 · 5 comments

Comments

@derrabus
Copy link

I'm testing an application with Behat, Mink and Selenium 2 that has some input fields with autocompleters. A typical autocompleter is rendered as a <div> below the input field that is displayed as long a the input field is focused.

Before v1.2 of the driver, we could test those as described in the example in the manual. With v1.2, due to PR #146, the driver automatically sends a tab key after filling in the value into the input field, which causes a blur event on the input field which closes my autocompleter.

Sending the tab automatically probably triggers the expected behavior (= change event) in 98% of the cases people use your driver in, but in my case it breaks my test. Now, I was looking for a way to fill text into an input field without triggering a blur event, but I really have no idea how to do this, since this behavior is hard-wired to the setValue() method of the driver.

@aik099
Copy link
Member

aik099 commented Nov 26, 2014

Interesting case indeed. @stof , any ideas?

@jdt
Copy link

jdt commented Dec 5, 2014

I've run into similar problems testing an autocomplete using typeahead.js. You can use the following code to work around the issue (from a RawMinkContext-extending class)

$el = $this->getSession()->getDriver()->getWebDriverSession()->element("xpath", <selector>);
$el->postValue(array('value' => array(<input>)));
//now wait for the data to load and autocomplete to show, substitute for actual code
sleep(5);
//select the first element
$el->postValue(array('value' => array(Key::DOWN_ARROW)));
$el->postValue(array('value' => array(Key::ENTER)));

This basically enters data, waits for the autocomplete keeping the focus and then selects the first item by simulating keyboard input. It will work for typeahead but might need some adaptation for other autocompletes.

The thing is, this solution is tied to the implementation of the Selenium-driver. We are trying to find a way to input data into a textbox but without losing the focus. Looking at the implementations of the other drivers I'm not even sure that the concept of 'enter data but keep the focus' can be ported to those drivers! You might be stuck using this code and tying your tests in strongly with Selenium...

@stof
Copy link
Member

stof commented Dec 6, 2014

IMO, the new behavior is the expected one for Element::setValue().

The case of testting an autocompleter is that you are testing something happening during setting the value, not after setting it.
And indeed, write into the field without loosing focus is not something we can fit into Mink because I think only Selenium allows to implement it.

@derrabus
Copy link
Author

derrabus commented Dec 6, 2014

Thanks for the explanation, @stof. So, @jdt's workaround would actually be the way to go now? That's ugly, but I can live with that, I guess.

However, you should remove that example from the docs, then.

@stof
Copy link
Member

stof commented Dec 6, 2014

yeah, it is probably the way to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants