Question

I'm busy with the UI-automation of an application where a drawing in a style comparable to the Paint-application can be made. In the application under test this area is made via a canvas-element.

My goal is to make a kind of drawing on this canvas via Selenium and the Robot Framework, e.g. like drawing a line:

  1. mouse press on certain position
  2. mouse move to the new position
  3. release mouse on the new position

In the official documentation of the Selenium2Library for the Robot Framework I saw that there is no keyword which fits my needs (the keyword 'Click Element At Coordinates' didn't work). However, via a search I found out that there is a keyword 'mouse_down_at', but this keyword is not accessible in the standard Robot Framework. However, the keyword 'mouse_down_at' is present in the file selenium.py which is in Selenium-folder (Python site-packages).

Now, I'm looking for a way to access this keyword 'mouse_down_at' in the Robot Framework. I already tried by myself to write a wrapper library around this, but was unsuccessful so far.

Était-ce utile?

La solution

You could create your own version of Selenium2Library and use that instead of the standard Selenium2Lib. Something like this:

from Selenium2Library import Selenium2Library
from selenium.webdriver.common.action_chains import ActionChains

class Selenium2Improved(Selenium2Library):
    '''Sometimes Selenium2Library just dont go far enough.'''

    def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot'):
        super(Selenium2Improved, self).__init__()

    def mouse_down_at(self, locator, coordx, coordy):
        element = self._element_find(locator, True, False)
        if element is None:
            raise AssertionError("ERROR: Element %s not found." % (locator))
        ActionChains(self._current_browser()).move_to_element(element).move_by_offset(coordx, coordy).click_and_hold().perform()

    def mouse_up_at(self, locator, coordx, coordy):
        element = self._element_find(locator, True, False)
        if element is None:
            raise AssertionError("ERROR: Element %s not found." % (locator))
        ActionChains(self._current_browser()).move_to_element(element).move_by_offset(coordx, coordy).release().perform()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top