Repository: robotframework/SeleniumLibrary
Pull request #1741 (2021-08-30 10:47:18)

Added minimize keyword
Added the access to minimize method, symmetrical to the maximize one.

aaltat: Please write test, acceptance or unit, for the new keyword.
lmartorella: Hello, I would like to edit/copy the tests for the existing `maximize_browser_window`, the sister keyword. Could you please point me to the acceptance tests for that one?
Thx, L 
aaltat: It seems that we do not have one. But easy way would be to use https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Set%20Window%20Size and set window size something small Then use new keyword and verify that size is bigger. 
lmartorella: Added an acceptance test, using the underlying selenium tests as inspiration. However it seems that even in the selenium library such tests are disabled, perhaps due to instability or unable to access to the browser's maximized/minimized state on all the platforms and OSes.

The minimize test is only checking for `windows.hidden`. It seems that accessing to window position and size doesn't provide correct information (position unchanged, horizontal size changes to a random value but height is not).
The maximize test is more robust and size/pos can be used as reference.

aaltat: Looks good for me. @emanlove what you want to do with the PR? 

Patch:
diff --git a/src/SeleniumLibrary/keywords/window.py b/src/SeleniumLibrary/keywords/window.py
index 43588d7d..01feee1f 100644
--- a/src/SeleniumLibrary/keywords/window.py
+++ b/src/SeleniumLibrary/keywords/window.py
@@ -186,6 +186,11 @@ class WindowKeywords(LibraryComponent):
         """Maximizes current browser window."""
         self.driver.maximize_window()
 
+    @keyword
+    def minimize_browser_window(self):
+        """Minimizes current browser window."""
+        self.driver.minimize_window()
+
     @keyword
     def get_window_size(self, inner: bool = False) -> Tuple[float, float]:
         """Returns current window width and height as integers.


Test patch:
diff --git a/atest/acceptance/windows.robot b/atest/acceptance/windows.robot
index 733d59d1..29d76734 100644
--- a/atest/acceptance/windows.robot
+++ b/atest/acceptance/windows.robot
@@ -114,6 +114,30 @@ Set Window Position using strings
     Should Be Equal    ${x}    ${200}
     Should Be Equal    ${y}    ${100}
 
+Test Minimize and Maximize Will Actually Move and Resize Window
+    Set Window Position    300    200
+    Set Window Size    400    300
+    ${isHidden}=    Execute Javascript   return document.hidden;
+    Should Not Be True  ${isHidden}
+
+    Minimize Browser Window
+
+    ${isHidden}=    Execute Javascript   return document.hidden;
+    Should Be True  ${isHidden}
+
+    Maximize Browser Window
+
+    ${isHidden}=    Execute Javascript   return document.hidden;
+    Should Not Be True  ${isHidden}
+
+    ${x}    ${y}=    Get Window Position
+    ${width}    ${height}=    Get Window Size
+    # Windows: Can't test for zero in multi-monitor setups
+    Should Not Be Equal    ${x}    ${300}
+    Should Not Be Equal    ${y}    ${200}
+    Should Be True   ${width} > 400
+    Should Be True   ${height} > 300
+
 Select Window By Title After Close Window
     [Tags]    Known Issue Internet Explorer    Known Issue Safari
     Cannot Be Executed in IE
diff --git a/utest/test/api/test_plugins.py b/utest/test/api/test_plugins.py
index 89e33c24..9b5a34f4 100644
--- a/utest/test/api/test_plugins.py
+++ b/utest/test/api/test_plugins.py
@@ -22,7 +22,7 @@ class ExtendingSeleniumLibrary(unittest.TestCase):
     def test_no_libraries(self):
         for item in [None, "None", ""]:
             sl = SeleniumLibrary(plugins=item)
-            self.assertEqual(len(sl.get_keyword_names()), 177)
+            self.assertEqual(len(sl.get_keyword_names()), 178)
 
     def test_parse_library(self):
         plugin = "path.to.MyLibrary"