From aca85ef0ffb001373223ace34fd4edfeb70ec405 Mon Sep 17 00:00:00 2001 From: pturchinetz Date: Tue, 7 Mar 2023 16:08:58 -0500 Subject: [PATCH 1/4] Adding drag and drop to windows elements, not using the javascript script --- .../dougnoel/sentinel/elements/Element.java | 2 +- .../sentinel/elements/WindowsElement.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dougnoel/sentinel/elements/Element.java b/src/main/java/com/dougnoel/sentinel/elements/Element.java index 22319139..7d8a386a 100644 --- a/src/main/java/com/dougnoel/sentinel/elements/Element.java +++ b/src/main/java/com/dougnoel/sentinel/elements/Element.java @@ -488,7 +488,7 @@ public Element dragAndDrop(Element target) throws IOException { JavascriptExecutor executor = (JavascriptExecutor)WebDriverFactory.getWebDriver(); executor.executeScript(script, this.element(), target.element()); - return this; + return this; } /** diff --git a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java index fbb69489..4122c512 100644 --- a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java +++ b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java @@ -4,6 +4,7 @@ import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.File; +import java.io.IOException; import java.util.Map; import com.dougnoel.sentinel.configurations.Time; @@ -13,6 +14,7 @@ import com.dougnoel.sentinel.system.FileManager; import com.dougnoel.sentinel.webdrivers.Driver; +import com.dougnoel.sentinel.webdrivers.WebDriverFactory; import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.*; @@ -26,6 +28,8 @@ */ public class WindowsElement extends Element { + private WebDriver driver() { return Driver.getWebDriver(); } + /** * Default Windows Element constructor. An override of the Element constructor. * @@ -202,6 +206,24 @@ public Color getColorAtOffset() { return getColorAtOffset(1, 1); } + /** + * Drags the current element on top of the target element. + * @param target Element the element the target is being dragged and dropped onto + * @return Element (for chaining) + * @throws IOException if the drag and drop javascript file cannot be loaded + */ + @Override + public Element dragAndDrop(Element target) throws IOException { + //String script = FileManager.loadJavascript("src/main/resources/scripts/DragDrop.js"); + + //JavascriptExecutor executor = (JavascriptExecutor) WebDriverFactory.getWebDriver(); + //executor.executeScript(script, this.element(), target.element()); + //new Actions(driver()).moveToElement(element, point.getX(), point.getY()).click().build().perform(); + new Actions(driver()).dragAndDrop(this.element(), target.element()).build().perform(); + + return this; + } + /** * Returns true if the element has an attribute equal to the value passed; * otherwise returns false. From 3bba8c7ab46ccea50da77d204b865d1e4f7775da Mon Sep 17 00:00:00 2001 From: pturchinetz Date: Tue, 7 Mar 2023 16:11:20 -0500 Subject: [PATCH 2/4] fixes --- .../java/com/dougnoel/sentinel/elements/WindowsElement.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java index 4122c512..3059a1ea 100644 --- a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java +++ b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java @@ -14,7 +14,6 @@ import com.dougnoel.sentinel.system.FileManager; import com.dougnoel.sentinel.webdrivers.Driver; -import com.dougnoel.sentinel.webdrivers.WebDriverFactory; import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.*; @@ -214,11 +213,6 @@ public Color getColorAtOffset() { */ @Override public Element dragAndDrop(Element target) throws IOException { - //String script = FileManager.loadJavascript("src/main/resources/scripts/DragDrop.js"); - - //JavascriptExecutor executor = (JavascriptExecutor) WebDriverFactory.getWebDriver(); - //executor.executeScript(script, this.element(), target.element()); - //new Actions(driver()).moveToElement(element, point.getX(), point.getY()).click().build().perform(); new Actions(driver()).dragAndDrop(this.element(), target.element()).build().perform(); return this; From 33f8e3687fd7780e3246ebc4e54b04657a459977 Mon Sep 17 00:00:00 2001 From: pturchinetz Date: Wed, 8 Mar 2023 13:02:53 -0500 Subject: [PATCH 3/4] adding drag and drop test --- src/main/java/com/dougnoel/sentinel/elements/Element.java | 2 +- .../com/dougnoel/sentinel/elements/WindowsElement.java | 2 -- src/test/java/com/microsoft/NotepadApp.yml | 4 +++- .../239 Initial WinAppDriver Implementation.feature | 8 +++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/dougnoel/sentinel/elements/Element.java b/src/main/java/com/dougnoel/sentinel/elements/Element.java index 7d8a386a..0b7ffe0e 100644 --- a/src/main/java/com/dougnoel/sentinel/elements/Element.java +++ b/src/main/java/com/dougnoel/sentinel/elements/Element.java @@ -67,7 +67,7 @@ public class Element { protected Map selectors; protected String name; protected final String elementType; - private WebDriver driver() { return Driver.getWebDriver(); } + protected WebDriver driver() { return Driver.getWebDriver(); } /** * The constructor for a WebElement to initialize how an element is going to be diff --git a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java index 3059a1ea..fb22767c 100644 --- a/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java +++ b/src/main/java/com/dougnoel/sentinel/elements/WindowsElement.java @@ -27,8 +27,6 @@ */ public class WindowsElement extends Element { - private WebDriver driver() { return Driver.getWebDriver(); } - /** * Default Windows Element constructor. An override of the Element constructor. * diff --git a/src/test/java/com/microsoft/NotepadApp.yml b/src/test/java/com/microsoft/NotepadApp.yml index 2d9a4f81..8406bae5 100644 --- a/src/test/java/com/microsoft/NotepadApp.yml +++ b/src/test/java/com/microsoft/NotepadApp.yml @@ -9,4 +9,6 @@ elements: accessibilityid: 1025 class: msctls_statusbar32 file_menu_dropdown: - name: File \ No newline at end of file + name: File + edit_menu_dropdown: + name: Edit \ No newline at end of file diff --git a/src/test/java/features/239 Initial WinAppDriver Implementation.feature b/src/test/java/features/239 Initial WinAppDriver Implementation.feature index e8a0d8e9..e3d50393 100644 --- a/src/test/java/features/239 Initial WinAppDriver Implementation.feature +++ b/src/test/java/features/239 Initial WinAppDriver Implementation.feature @@ -68,4 +68,10 @@ Feature: 239 Implement WinAppDriver to automate windows When I take a screenshot of the Text Editor field And I clear the Text Editor field And I enter test the element screenshot no longer matches in the Text Editor field - Then I verify the Text Editor field does not match the previous image \ No newline at end of file + Then I verify the Text Editor field does not match the previous image + + @239F + Scenario: 239F Verify drag and drop works for windows + This is a bad test and lacks a verification because notepad does not have a drag and drop element + Given I switch to the Notepad App + Then I drag the file menu dropdown to the edit menu dropdown \ No newline at end of file From e03dd954e87d1762a0e919ca447230f92eced041 Mon Sep 17 00:00:00 2001 From: pturchinetz Date: Wed, 8 Mar 2023 13:15:13 -0500 Subject: [PATCH 4/4] removing drag and drop test --- .../239 Initial WinAppDriver Implementation.feature | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/test/java/features/239 Initial WinAppDriver Implementation.feature b/src/test/java/features/239 Initial WinAppDriver Implementation.feature index e3d50393..e8a0d8e9 100644 --- a/src/test/java/features/239 Initial WinAppDriver Implementation.feature +++ b/src/test/java/features/239 Initial WinAppDriver Implementation.feature @@ -68,10 +68,4 @@ Feature: 239 Implement WinAppDriver to automate windows When I take a screenshot of the Text Editor field And I clear the Text Editor field And I enter test the element screenshot no longer matches in the Text Editor field - Then I verify the Text Editor field does not match the previous image - - @239F - Scenario: 239F Verify drag and drop works for windows - This is a bad test and lacks a verification because notepad does not have a drag and drop element - Given I switch to the Notepad App - Then I drag the file menu dropdown to the edit menu dropdown \ No newline at end of file + Then I verify the Text Editor field does not match the previous image \ No newline at end of file