From da1cc583636ce9a02032cbd685f494ae8e8cf2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20P=C3=A2rvu?= <4466614+mihaiparvu@users.noreply.github.com> Date: Wed, 27 Mar 2019 09:11:23 +0200 Subject: [PATCH] Added `Set Window Size` and `Get Window Size` keywords (#121) Closes #75 --- .../swing/keyword/window/WindowKeywords.java | 25 +++++++++++++++++++ .../keyword/window/WindowKeywordsSpec.java | 23 +++++++++++++++++ src/test/resources/robot-tests/window.robot | 8 ++++++ 3 files changed, 56 insertions(+) diff --git a/src/main/java/org/robotframework/swing/keyword/window/WindowKeywords.java b/src/main/java/org/robotframework/swing/keyword/window/WindowKeywords.java index b215dca3..253264c4 100644 --- a/src/main/java/org/robotframework/swing/keyword/window/WindowKeywords.java +++ b/src/main/java/org/robotframework/swing/keyword/window/WindowKeywords.java @@ -75,6 +75,31 @@ public void selectWindow(String identifier) { setContext(operator); } + @RobotKeyword("Sets a window size.\n\n" + + "Examples:\n" + + "| `Set Window Size` | Help | 800 | 600 | # Re-sizes the Help window to 800 px width and 600 px height. |\n") + @ArgumentNames({ "identifier", "width", "height" }) + public void setWindowSize(String identifier, String width, String height) { + FrameOperator operator = operatorFactory.createOperator(identifier); + setContext(operator); + operator.resize(Integer.parseInt(width), Integer.parseInt(height)); + } + + @RobotKeyword("Returns a list containing the width and the height of the window.\n\n" + + "Examples:\n" + + "| ${size} | `Get Window Size` | Help | # Gets the size of the Help window. |\n" + + "| `Should Be Equal As Integers` | ${size[0]} | 800 |\n" + + "| `Should Be Equal As Integers` | ${size[1]} | 600 |\n") + @ArgumentNames({ "identifier" }) + public List getWindowSize(String identifier) { + FrameOperator operator = operatorFactory.createOperator(identifier); + setContext(operator); + List result = new ArrayList(); + result.add(String.valueOf(operator.getWidth())); + result.add(String.valueOf(operator.getHeight())); + return result; + } + @RobotKeyword("Closes a window.\n\n" + "*N.B.* Regular expression can be used to close the window by prefixing the identifier with ``regexp=``.\n" + "See more details in `Regular expressions` section.\n\n" diff --git a/src/test/java/org/robotframework/swing/keyword/window/WindowKeywordsSpec.java b/src/test/java/org/robotframework/swing/keyword/window/WindowKeywordsSpec.java index 761bf16e..1466ea02 100644 --- a/src/test/java/org/robotframework/swing/keyword/window/WindowKeywordsSpec.java +++ b/src/test/java/org/robotframework/swing/keyword/window/WindowKeywordsSpec.java @@ -90,6 +90,29 @@ public void selectWindowSetsDesignatedWindowAsContext() { specify(Context.getContext(), must.equal(frameOperator)); } + public void setSize() { + checking(new Expectations() { + { + one(frameOperator).getFocus(); + one(frameOperator).resize(800,600); + } + }); + context.setWindowSize(windowIdentifier, "800", "600"); + } + + public void getSize() { + checking(new Expectations() { + { + one(frameOperator).getFocus(); + one(frameOperator).getWidth();will(returnValue(800)); + one(frameOperator).getHeight();will(returnValue(600)); + } + }); + java.util.List size = context.getWindowSize(windowIdentifier); + specify(size.get(0), "800"); + specify(size.get(1), "600"); + } + public void closesWindow() { checking(new Expectations() { { diff --git a/src/test/resources/robot-tests/window.robot b/src/test/resources/robot-tests/window.robot index 669ebffd..49ad3696 100644 --- a/src/test/resources/robot-tests/window.robot +++ b/src/test/resources/robot-tests/window.robot @@ -41,6 +41,14 @@ List Windows Should be equal @{windows}[0] Test App [teardown] closeWindow Test Window +Resize Window + ${initial_size} Get Window Size Test App + Set Window Size Test App 1280 720 + ${resized_size} Get Window Size Test App + Should Be Equal As Integers ${resized_size[0]} 1280 + Should Be Equal As Integers ${resized_size[1]} 720 + [Teardown] Set Window Size Test App ${initial_size[0]} ${initial_size[1]} + Close Window selectFromMainMenu Test Menu|Show Test Window Select Window Test Window