Repository navigation
Description
I am working with a legacy codebase and I'm having trouble getting mouseOver() to trigger a :hover css event. This code is used all over the place and currently my only workaround is having to run executeScript() and manually remove the .dropout and .dropout-trigger classes. Please help me figure out what I can do to solve this.
I've set up a barebones repository containing a single, basic, HTML file, the CSS I have managed to isolate, and a test.
I have included the vendor/ folder simply so you can get up to speed straight away. I run selenium-server-standalone and phpunit:
java -jar bin/selenium-server-standalone-2.40.0.jar -Dwebdriver.chrome.driver=bin/chromedriver-2.9
bin/phpunit.phar --colors --bootstrap bootstrap.php --filter testMouseOverFail src/
My test is as follows:
public function testMouseOverFail()
{
$driver = new \Behat\Mink\Driver\Selenium2Driver("chrome", array(), "http://localhost:4444/wd/hub");
$session = new \Behat\Mink\Session($driver);
$session->start();
// I placed this all in /var/www/mouseoverfail
$session->visit("http://localhost/mouseoverfail");
$page = $session->getPage();
$services = $page->find('xpath', '//*[@id="nav_services"]');
var_dump("Services visibility: " . $services->isVisible());
$services->mouseOver(); // Nothing is hovered over :(
sleep(5);
$session->stop();
}
Like I said, I'm working with legacy code here and the css is all over the place. It's highly likely that it's our css / html that is the issue and not mink / selenium2driver, but I would just like to find out how I can solve this, as my manual executeScript() haxx are just terrible.
Activity
aik099 commentedon Apr 9, 2014
Regardless to your case it's obvious why the ":hover" doesn't work: the "mouseover" event has been triggered by the Syn() library while the mouse cursor isn't even moved.
We can do a native "moveTo" call of WebDriver in hopes that it will trigger the "mouseover" JS event. Or we can trigger "mouseover" JS event ourselves after the "moveTo" call has finished.
Can you please try that out and send a PR+tests for that?
J7mbo commentedon Apr 9, 2014
Following your advice I have gotten it working by retrieving the element using WebDriver and calling
moveto()withinmouseOver()before the syn event is executed.Could you suggest the best way to submit tests alongside this PR? I saw mink has some tests in there but this is a separate repo... Do I need to submit this and a test fixture in the main mink repo?
aik099 commentedon Apr 9, 2014
There should 2 PR in total:
Problem is, that you won't see the added tests running in the driver tests on Travis, until that mink repo PR is merged.
Also since you're adding tests to common test class, then please run these tests on all existing drivers and make sure that they also pass.
To make both PR's associated I usually mention driver repo issue/pr for which the tests are for in the mink pr.
And also add a test (this one will be Selenium2 specific in driver repo), that
mouseoverevent isn't fired more than once.J7mbo commentedon Apr 9, 2014
I've added the test that needs to pass and a fixture for it in a fork.
I'm not sure about the other existing drivers though, I may need a little help with that :-) (I've only used Selenium2Driver).
Here's the code change to the driver.
How are these looking?
aik099 commentedon Apr 9, 2014
You can send a PR in any case. Even if it breaks something then we can discuss that right on PR page.
J7mbo commentedon Apr 10, 2014
A problem I have found is that, in order for
movetoto work, and for themouseOver()call to work with:hover, the code looks as follows:This requires that the element in question has an
idattribute - which not all of them do. Is there any way around this? I have also seenxOffsetas an option but this does not seem feasible. Can we pass an xpath instead of the id?aik099 commentedon Apr 10, 2014
Are you sure that
getIDmethod is returning the found DOM element's ID (from HTML) and not WebDriver/Selenium's internal identificator?stof commentedon Apr 10, 2014
it is indeed a webdriver identifier
J7mbo commentedon Apr 10, 2014
My bad, I'm still testing the code change myself before I submit a PR.
aik099 commentedon Apr 10, 2014
If I have enough time this week, then I plan to submit massive PR in #126 issue, that will fix all mouse-related problems once and for all. To make this happen I'll collect all mouse-related PRs and incorporate them into my single PR.
I'm warning you ahead, so you won't be surprised when PR gets closed instead of merged.
J7mbo commentedon Apr 10, 2014
No that's great, I just want the issue fixed for when I do a
composer update.I'm looking forward to seeing it if you have chance to get it done this weekend :-)
aik099 commentedon Apr 10, 2014
I bet that both SeleniumRC and WebDriver will work, but I'm not sure about Sahi or PhantomJS.
kenden commentedon Apr 10, 2014
Note if you don't want to wait for a composer update, you can add a method to your class:
https://gist.github.com/delphian/6255239
J7mbo commentedon Apr 14, 2014
@aik099 Any updates on this - weekend's gone, just thought I'd ask :P
aik099 commentedon Apr 14, 2014
Sorry, this was already merged for click/doubleclick/rightclick/mouseover methods (see #126 task).
aik099 commentedon Apr 14, 2014
I'll close this task since functionality is already merged in the #126. Feel free to reopen if needed.