splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Remote WebDriverElement seems more limited than it could be

Open cuducos opened this issue 7 years ago β€’ 3 comments

According to the implementation of the remote web driver it will always use the splinter.driver.webdriver.remote.WebDriverElement as it's element class. This class, for instance, limits the possibility of certain actions, such as mouse over.

It turns out that it is actually possible to perform a mouse over using Chrome remote driver. I'm coding this solution in a current project, it merely replaces splinter.driver.webdriver.remote.WebDriverElement by splinter.driver.webdriver.WebDriverElement in the remote web driver class:

from splinter.driver.webdriver import WebDriverElement
from splinter.driver.webdriver.remote import WebDriver


class RemoteWebDriver(WebDriver):
    """A clone of the default remote web driver class, but using the non-remote
    web driver element class."""

    def __init__(self, *args, **kwargs):
        super(RemoteWebDriver, self).__init__(*args, **kwargs)
        self.element_class = WebDriverElement  # overrides the element class

browser = RemoteWebDriver(browser='chrome', url=DRIVE_URL)
browser.find_by_css('#tooltip').mouse_over()

That said, my hunch is that maybe we might be too restrict with the limitations imposed by the remote WebDriverElement class. From this experiment it seems that at least remote Chrome can handle mouse overs… does that make sense?

If so, I suggest a roadmap to address this issue:

  • [x] Test which of the limitations (mouse_over, mouse_out, double_click, right_click and drag_and_drop) are still present in remote Chrome driver
  • [x] Test which of the limitations (mouse_over, mouse_out, double_click, right_click and drag_and_drop) are still present in remote Firefox driver
  • [x] Refactor splinter.driver.webdriver.WebDriverElement to allow users to perform actions supported in the tests from steps 1 and 2 (we might write two different classes, but details of the implementation are to be discussed latter IMHO)

~~We can edit~~ I just editted this table with the results of the tests:

Action Remote Chrome Remote Firefox
mouse_over βœ… βœ…
mouse_out 🚫 🚫
double_click βœ… βœ…
right_click βœ… βœ…
drag_and_drop βœ… βœ…

What do you think?

cuducos avatar Jan 28 '19 19:01 cuducos

I'm +1 for this. We already does a little of it in the WebDriver subclasses, but not for WebDriverElement.

andrewsmedina avatar Feb 09 '19 21:02 andrewsmedina

Great. I just ran some tests and can confirm that the 4 out of the 5 features listed in the table above work for Chrome and Firefox using the remote web driver. I used these 4 files to perform these tests, not sure if I tested it properly though:

  1. index.html a single page with JS to trigger something on the 5 features listed (mouse over and out, double click, right click and drag and drop)
  2. app.py a Pyhton app using Splinter to test these features in both browsers and print on the screen the result (if they succeeded or not)
  3. docker-compose.yml to start up
    1. a simple web server serving the index.html
    2. a standalone Chrome instance
    3. a standalone Firefox instance
    4. a Python container to run app.py
  4. A Dockerfile setting up app.py to run

The output I got says mouse_out failed in both browsers:

[ x ] mouse_over chrome
[   ] mouse_out chrome
[ x ] double_click chrome
[ x ] right_click chrome
[ x ] drag_and_drop chrome
[ x ] mouse_over firefox
[   ] mouse_out firefox
[ x ] double_click firefox
[ x ] right_click firefox

What's next?

I would like to discuss how can we introduce tests for these new features. I mean, I see we can throw away my dirty jQuery impregnated HTML file and use the static/ ones already in the test suite. Yay! But my doubts concern the remote web driver setup:

  • Should we add a tag to sip the test if the remote web driver is not running at WebDriver.DEFAULT_URL? Or maybe if os.environ.get('REMOTE_WEBDRIVER_URL') fails?
  • Should we really have a remote web driver or should we just mock it? The tests would basically be mocked_method.assert_called_once_with(…) to make sure we're properly delegating the method call in this case.
  • Any other ideas for how to implement tests for these features?

cuducos avatar Feb 12 '19 18:02 cuducos

As of #873, we're now testing Firefox and Chrome Remote as part of the unit tests, and all of these methods pass.

javascript-error avatar Apr 06 '21 19:04 javascript-error