-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QE-13818 Helper template for 2 interacting elements, added draggables (…
…#381) ### Helper function I was looking to implement steps in cucu for draggable elements and I looked a little deeper at the helper code and found that there is a potential enhancement that cucu could have, templatized steps for 2 interacting elements. I started by implementing draggables as a proof of concept as a custom step on e2e-test branch. I then transferred that code over to cucu framework and had it working without any helper function implementation. That same code is now embedded in a helper function called `define_interaction_on_thing_with_name_steps` (final name pending) basically this is what it does... It intertwines 3 functions. 1. find function for finding the element you want to make the action with 2. find function for the finding the element you want the above element to interact with 3. Action function that defines what happens between the two found elements, in my case I found a draggable element, I found another generic element and I performed a drag action between them. It will be easiest to start on the `src/cucu/steps/draggable_steps.py` and then see how the helper function from here `src/cucu/helpers.py` is being used to allow for modularity across different applications. ### Draggable function After going through some trials on different browsers I noticed that the implementations for ActionChains was not consistent enough to be used in cucu. I then pivoted and created a JS_DRAG_DROP global variable that is then referenced in the `drag_element_to_element` function. This took a bit of refining to get right. Waits needs to be put in place to prevent the browser from executing too fast for the Webdriver to realize anything has happened. And with that we need to stay synchronous with python code that is being executed in tandem. That is where the Webdriver wait comes in. I setup a Webdriver wait to keep python executions and javascript executions in sync. `WebDriverWait(driver, 10).until(lambda driver: driver.execute_script("return window.dragAndDropCompleted;"))` This allows the drag and drop to be very consistent across all browser types.
- Loading branch information
1 parent
656ecc7
commit 8829462
Showing
9 changed files
with
499 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
.draggable { | ||
width: 100px; | ||
height: 100px; | ||
background-color: lightblue; | ||
text-align: center; | ||
padding: 10px; | ||
margin: 10px; | ||
} | ||
|
||
.target { | ||
width: 400px; | ||
height: 500px; | ||
background-color: lightgray; | ||
margin: 10px; | ||
float: left; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="draggable1" class="draggable" draggable="true" ondragstart="dragStart(event)">Drag Me 1</div> | ||
<div id="draggable2" class="draggable" draggable="true" ondragstart="dragStart(event)">Drag Me 2</div> | ||
<div id="draggable3" class="draggable" draggable="true" ondragstart="dragStart(event)">Drag Me 3</div> | ||
|
||
|
||
<div id="target1" class="target" ondragover="dragOver(event)" ondrop="drop(event)">Drop Here 1</div> | ||
<div id="target2" class="target" ondragover="dragOver(event)" ondrop="drop(event)">Drop Here 2</div> | ||
<div id="target3" class="target" ondragover="dragOver(event)" ondrop="drop(event)">Drop Here 3</div> | ||
<div id="target4" class="target" >Drop Here 4</div> | ||
|
||
<script> | ||
function dragStart(e) { | ||
e.dataTransfer.effectAllowed = "move"; | ||
e.dataTransfer.setData("Text", e.target.getAttribute("id")); | ||
} | ||
|
||
function dragOver(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
|
||
function drop(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
var data = e.dataTransfer.getData("Text"); | ||
e.target.appendChild(document.getElementById(data)); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Feature: Draggables | ||
As a developer I want to make sure the test writer can interact with different | ||
draggable elements | ||
|
||
Background: HTML page with draggables | ||
Given I start a webserver at directory "data/www" and save the port to the variable "PORT" | ||
And I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/draggables.html" | ||
|
||
Scenario: User can drag element | ||
When I wait to see the text "Drag" | ||
Then I should immediately see the "2nd" element "Drag Me" is draggable | ||
And I drag the element "Drag Me 1" to the element "Drop Here 2" | ||
And I drag the element "Drag Me 2" to the element "Drop Here 1" | ||
And I drag the element "Drag Me 3" to the element "Drop Here 3" | ||
And I should immediately see the "2nd" element "Drop Here" is not draggable | ||
|
||
@negative | ||
Scenario: User cannot drag element | ||
When I wait to see the text "Drag" | ||
Then I should immediately see the element "Drop Here 2" is not draggable | ||
And I expect the following step to fail with "Unable to find the element \"Nonexistent drop\"" | ||
""" | ||
When I drag the element "Drag Me 1" to the element "Nonexistent drop" | ||
""" | ||
And I expect the following step to fail with "Unable to find the element \"Nonexistent drag\"" | ||
""" | ||
When I drag the element "Nonexistent drag" to the element "Drop Here 1" | ||
""" | ||
And I expect the following step to fail with "Unable to find the element \"Nonexistent drag\", Unable to find the element \"Nonexistent drop\"" | ||
""" | ||
When I drag the element "Nonexistent drag" to the element "Nonexistent drop" | ||
""" | ||
And I expect the following step to fail with "Drag element Drag Me 1 position did not change" | ||
""" | ||
When I drag the element "Drag Me 1" to the element "Drop Here 4" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Feature: Duplicate Draggables | ||
As a developer I want to make sure the test writer can interact with duplicate | ||
draggable elements. | ||
|
||
Background: HTML page with draggables | ||
Given I start a webserver at directory "data/www" and save the port to the variable "PORT" | ||
And I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/draggables.html" | ||
|
||
Scenario: User can drag nth element | ||
When I wait to see the text "Drag" | ||
Then I should immediately see the "2nd" element "Drag Me" is draggable | ||
And I drag the "1st" element "Drag Me" to the "2nd" element "Drop Here" | ||
And I drag the "2nd" element "Drag Me" to the "1st" element "Drop Here" | ||
And I should immediately see the "2nd" element "Drop Here" is not draggable | ||
|
||
@negative | ||
Scenario: User cannot drag nth elements | ||
Then I should immediately see the "3rd" element "Drop Here" is not draggable | ||
And I expect the following step to fail with "Unable to find the \"3rd\" element \"Nonexistent drop\"" | ||
""" | ||
When I drag the "2nd" element "Drag Me" to the "3rd" element "Nonexistent drop" | ||
""" | ||
And I expect the following step to fail with "Unable to find the \"2nd\" element \"Nonexistent drag\"" | ||
""" | ||
When I drag the "2nd" element "Nonexistent drag" to the "3rd" element "Drop Here" | ||
""" | ||
And I expect the following step to fail with "Unable to find the \"2nd\" element \"Nonexistent drag\", Unable to find the \"3rd\" element \"Nonexistent drop\"" | ||
""" | ||
When I drag the "2nd" element "Nonexistent drag" to the "3rd" element "Nonexistent drop" | ||
""" | ||
And I expect the following step to fail with "Drag element Drag Me 1 position did not change" | ||
""" | ||
When I drag the "1st" element "Drag Me" to the "4th" element "Drop Here" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "cucu" | ||
version = "0.172.0" | ||
version = "0.173.0" | ||
license = "MIT" | ||
description = "Easy BDD web testing" | ||
authors = ["Domino Data Lab <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.