LuluTest
LuluTest copied to clipboard
Add drag and drop functionality
Extend either the Page class or BaseElement class to support drag and drop functionality. This needs to include:
- finding a place to drag an element
- perhaps a way to see if the drag was successful?
- finding a website which would allow us to test this
- write tests to make sure this works as expected
Hey. I think I can pick this up.
@wangonya nice, that would be awesome!
Hey @erik-whiting. Seems like Selenium's drag and drop method only accepts WebElements - which I'm assuming are what you get when you use the native methods like findByElement. The methods we've implemented on our side (like page.get_element() return PageElements. So trying to pass in elements from page.get_element() to drag and drop raises AttributeError: move_to requires a WebElement.
I'm kinda stuck. Any ideas?
Overriding the class to make it pretend to be a WebElement might be possible according to this suggestion on a semi-related issue. Not sure if this would have an effect on the existing functionality (if it might break stuff for example).
@wangonya I'm not sure if this helps as I haven't dove too deep into it but consider this:
Look at action/element_actions.py and note how a lot of the methods start off with driver_element = load_element(self.driver, element). That load_element method comes from page_element_interface/IPageElement.py and returns Selenium's WebElement object; that's the object we work with when writing Selenium specific code. The purpose of PageElement is more or less to wrap Selenium WebElements so we can abstract away some of the complexity of working with them.
Take a look at the test_dropdown test in tests/test_other_pages.py for example. As a user of LuluTest, you only have to write actions.select_drop_down(page_element_in_question, 'Criteria to select'). LuluTest takes the PageElement (defined by us) and sends it to action/element_actions.py's select_drop_down method. Here, our PageElement object gets transformed into a WebElement (defined by Selenium) via the load_element method on line 28. Lines 29 and 30 are Selenium-specific code. Does that make sense?
There's several reasons it's designed to work like this. Most importantly, it lets users define the elements they're going to use before they're present on the page. Loading a driver element on a page you haven't yet navigated to returns an error, so in a lot of automated-web-tests you get stuff like
driver.go_to(page)
link = driver.get(link_element)
link.click()
link_on_new_page = driver.get(new_link_element)
yadda yadda yadda. With the way LuluTest is designed, the link elements in the previous example can be defined before the driver element is actually on the page. The elements "just-in-time" (JIT) loaded, i.e., turned into WebElements the split second before they're needed.
So this issue would likely involve adding a method to element_actions that starts with driver_element = load_element(self.driver, element) and then do whatever other magic needs to be done with Selenium to make it work. This way, the resulting test case would essentially be like actions.drag_and_drop(element, location) or something. Does that help?
Super helpful, thanks. The issue was that I wasn't using load_element.
Just getting the tests right. I'll be opening a PR for review soon.
If anyone wanted to take a stab at this, the issue is still open. Here's my current attempt at the feature:
https://github.com/erik-whiting/LuluTest/tree/add-drag-and-drop-functionality
Super weird behavior, not real sure what to do.
Not sure why I never followed through with this. Seems like I had made some progress (looking at my last comment). I'll have a quick look when I find some time and compare what I had done with what you have. Happy to have anyone else chip in though!
no rush! thanks for taking a look
@erik-whiting I tried to build on what you had done on your branch and I think I'm facing the same issues you were. Seems pretty straightforward but for some reason it just doesn't work.
I don't have time at the moment to look at it some more so I'm just putting it out there - incase someone else can pick this up and try it out, that'd be great.
@wangonya thanks for your efforts!