Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window state error improvements and argument rename #141

Merged
merged 4 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions atests/attach_application.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*** Settings ***
Library WhiteLibrary
Library Process
Test Setup Start Test Application
Test Teardown Terminate Process ${handle} kill=true
Resource resource.robot

*** Test Cases ***
Attach To A Running Application By Name
Attach Application By Name ${TEST APPLICATION NAME}
Application Should Be Attached

Attach To A Running Application By Id
Attach Application By Id ${test application id}
Application Should Be Attached

*** Keywords ***
Start Test Application
${handle} = Start Process ${TEST APPLICATION}
Set Test Variable ${handle}
${test application id} = Get Process Id ${handle}
Set Test Variable ${test application id}

Application Should Be Attached
Attach Window UI Automation Test Window
Verify Label lblA Value 1
70 changes: 0 additions & 70 deletions atests/attatch_application.robot

This file was deleted.

49 changes: 49 additions & 0 deletions atests/feature_tests/window.robot
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,55 @@ Attach Window Object
Attach Window ${windows[3]}
Window Title Should Be Test title - 2

Attach Nonexisting Window
Set White Find Window Timeout 2 s
${status} ${error_msg} Run Keyword And Ignore Error Attach Window Bogus Window
Should Contain ${error_msg} after waiting for 2.0 seconds
[Teardown] Set White Find Window Timeout 30 s

Close Nonexisting Window
Set White Find Window Timeout 2 s
Attach Main Window
${status} ${error_msg} Run Keyword And Ignore Error Close Window Bogus Window
Should Contain ${error_msg} after waiting for 2.0 seconds
[Teardown] Set White Find Window Timeout 30 s

Minimize Current Window
Maximize Window
Minimize Window
Window Should Be Minimized ${TEST APPLICATION WINDOW TITLE}
[Teardown] Restore Window

Maximize Current Window
Minimize Window
Maximize Window
Window Should Be Maximized
[Teardown] Restore Window

Restore Current Window
Maximize Window
Restore Window
Window Should Be Restored
[Teardown] Restore Window

Failing Restored Check
Maximize Window
${status} ${error_msg} Run Keyword And Ignore Error Window Should Be Restored
Should Contain ${error_msg} Expected window state to be Restored, but found Maximized
[Teardown] Restore Window

Failing Minimized Check
Restore Window
${status} ${error_msg} Run Keyword And Ignore Error Window Should Be Minimized
Should Contain ${error_msg} Expected window state to be Minimized, but found Restored
[Teardown] Restore Window

Failing Maximized Check
Minimize Window
${status} ${error_msg} Run Keyword And Ignore Error Window Should Be Maximized
Should Contain ${error_msg} Expected window state to be Maximized, but found Minimized
[Teardown] Restore Window

*** Keywords ***
Window Test Suite Setup
Attach Main Window
Expand Down
5 changes: 2 additions & 3 deletions src/WhiteLibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pylint: disable=invalid-name
import os
from robot.api import logger # noqa: F401 #pylint: disable=unused-import
from robot.utils import is_truthy
import clr
DLL_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bin', 'TestStack.White.dll')
Expand All @@ -9,13 +8,13 @@
from System.Windows.Automation import AutomationElement, ControlType # noqa: E402
from TestStack.White.UIItems.Finders import SearchCriteria # noqa: E402
from TestStack.White.UIItems import UIItem # noqa: E402
from WhiteLibrary.keywords import ApplicationKeywords, KeyboardKeywords, WindowKeywords, ScreenshotKeywords, WhiteConfigurationKeywords # noqa: E402
from WhiteLibrary.keywords import (ApplicationKeywords, KeyboardKeywords, MouseKeywords,
WindowKeywords, ScreenshotKeywords, WhiteConfigurationKeywords) # noqa: E402
from WhiteLibrary.keywords.items import (ButtonKeywords,
LabelKeywords,
ListKeywords,
ListViewKeywords,
MenuKeywords,
MouseKeywords,
ProgressbarKeywords,
SliderKeywords,
TabKeywords,
Expand Down
5 changes: 3 additions & 2 deletions src/WhiteLibrary/keywords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .application import ApplicationKeywords # noqa: F401 #pylint: disable=unused-import
from .configuration import WhiteConfigurationKeywords # noqa: F401 #pylint: disable=unused-import
from .keyboard import KeyboardKeywords # noqa: F401 #pylint: disable=unused-import
from .window import WindowKeywords # noqa: F401 #pylint: disable=unused-import
from .mouse import MouseKeywords # noqa: F401 #pylint: disable=unused-import
from .screenshot import ScreenshotKeywords # noqa: F401 #pylint: disable=unused-import
from .configuration import WhiteConfigurationKeywords # noqa: F401 #pylint: disable=unused-import
from .window import WindowKeywords # noqa: F401 #pylint: disable=unused-import
1 change: 0 additions & 1 deletion src/WhiteLibrary/keywords/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from .listcontrols import ListKeywords # noqa: F401 #pylint: disable=unused-import
from .listview import ListViewKeywords # noqa: F401 #pylint: disable=unused-import
from .menu import MenuKeywords # noqa: F401 #pylint: disable=unused-import
from .mouse import MouseKeywords # noqa: F401 #pylint: disable=unused-import
from .progressbar import ProgressbarKeywords # noqa: F401 #pylint: disable=unused-import
from .slider import SliderKeywords # noqa: F401 #pylint: disable=unused-import
from .tab import TabKeywords # noqa: F401 #pylint: disable=unused-import
Expand Down
65 changes: 32 additions & 33 deletions src/WhiteLibrary/keywords/window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from robot.api import logger # noqa: F401 #pylint: disable=unused-import
from System import Enum
from TestStack.White import AutomationException, Desktop
from TestStack.White.Configuration import CoreAppXmlConfiguration
from TestStack.White.Factory import InitializeOption # noqa: E402
Expand Down Expand Up @@ -129,82 +129,77 @@ def maximize_window(self, locator=None):
window.DisplayState = DisplayState.Maximized

@keyword
def window_should_be_maximized(self, locator=None):
"""Verifies that a window is maximized.
def minimize_window(self, locator=None):
"""Minimizes a window.

``locator`` is the locator of the window or a window object (optional).

If no ``locator`` value is given, the status of the currently attached window is verified.
If no ``locator`` value is given, the currently attached window is minimized.
See `Attach Window` for details about attaching a window and window locator syntax.
"""
if locator is not None:
window = self._get_window(locator)
else:
window = self.state.window
if window.DisplayState != DisplayState.Maximized:
raise AssertionError("Expected window state to be maximized, but found {}".format(str(window.DisplayState)))
window.DisplayState = DisplayState.Minimized

@keyword
def minimize_window(self, locator=None):
"""Minimizes a window.
def restore_window(self, window_title=None):
"""Restores a window.

``locator`` is the locator of the window or a window object (optional).

If no ``locator`` value is given, the currently attached window is minimized.
If no ``locator`` value is given, the currently attached window is restored.
See `Attach Window` for details about attaching a window and window locator syntax.
"""
if locator is not None:
window = self._get_window(locator)
if window_title is not None:
window = self._get_window(window_title)
else:
window = self.state.window
window.DisplayState = DisplayState.Minimized
window.DisplayState = DisplayState.Restored

@keyword
def window_should_be_minimized(self, locator=None):
"""Verifies that a window is minimized.
def window_should_be_maximized(self, locator=None):
"""Verifies that a window is maximized.

``locator`` is the locator of the window or a window object (optional).

If no ``locator`` value is given, the status of the currently attached window is verified.
See `Attach Window` for details about attaching a window and window locator syntax.
"""
if locator is not None:
window = self._get_window(locator)
else:
window = self.state.window
if window.DisplayState != DisplayState.Minimized:
raise AssertionError("Expected window state to be minimized, but found {}".format(str(window.DisplayState)))
self._verify_window_state("Maximized", locator)

@keyword
def restore_window(self, window_title=None):
"""Restores a window.
def window_should_be_minimized(self, locator=None):
"""Verifies that a window is minimized.

``locator`` is the locator of the window or a window object (optional).

If no ``locator`` value is given, the currently attached window is restored.
If no ``locator`` value is given, the status of the currently attached window is verified.
See `Attach Window` for details about attaching a window and window locator syntax.
"""
if window_title is not None:
window = self._get_window(window_title)
else:
window = self.state.window
window.DisplayState = DisplayState.Restored
self._verify_window_state("Minimized", locator)

@keyword
def window_should_be_restored(self, window_title=None):
def window_should_be_restored(self, locator=None):
"""Verifies that a window is restored.

``locator`` is the locator of the window or a window object (optional).

If title is not given, currently attached window status is queried.
See `Attach Window` for more details.
"""
if window_title is not None:
window = self._get_window(window_title)
self._verify_window_state("Restored", locator)

def _verify_window_state(self, expected_state, locator):
if locator is not None:
window = self._get_window(locator)
else:
window = self.state.window
if window.DisplayState != DisplayState.Restored:
raise AssertionError("Expected window state to be restored, but found {}".format(str(window.DisplayState)))
actual_state = window.DisplayState
if actual_state != getattr(DisplayState, expected_state):
raise AssertionError("Expected window state to be {}, but found {}"
.format(expected_state, self._window_state_to_str(actual_state)))

def _get_window(self, locator):
if isinstance(locator, Window):
Expand Down Expand Up @@ -238,3 +233,7 @@ def _parse_window_locator(locator):
locator = "title:" + locator
idx = locator.index(":")
return locator[:idx], locator[(idx + 1):]

@staticmethod
def _window_state_to_str(state):
return Enum.GetName(DisplayState, state)