diff --git a/src/Zoomba/GUILibrary.py b/src/Zoomba/GUILibrary.py index b92db0da..34d9c799 100644 --- a/src/Zoomba/GUILibrary.py +++ b/src/Zoomba/GUILibrary.py @@ -436,3 +436,22 @@ def get_react_list_labels(self, locator): react_select_container = self.find_element(locator) options = RS.ReactSelect(react_select_container).options() return [opt.text for opt in options] + + @keyword("Select From Search Field") + def select_from_search_field(self, locator, text, timeout=None): + """This is a Selenium keyword that that first waits for an element to be on the DOM, executes + Focus on it, then it waits for it to be visible, clears it, and then inputs text. + Subsequently, it selects the first item in the search dropdown. + + locator: (string) A selenium locator(CSS, XPATH, ID, NAME, etc) + + text: (string) Text to be typed into the input field. + + timeout: (float) Time in seconds to wait, will use global timeout if not set. + """ + self.wait_for_and_focus_on_element(locator, timeout) + self.clear_element_text(locator) + self.input_text(locator, text) + self.wait_until_javascript_is_complete() + self.press_keys(locator, "ARROW_DOWN") + self.press_keys(locator, "RETURN") diff --git a/test/GUI/GUITests.robot b/test/GUI/GUITests.robot index 15828b8d..97fe4b4c 100644 --- a/test/GUI/GUITests.robot +++ b/test/GUI/GUITests.robot @@ -174,6 +174,13 @@ Wait Until Window Tests Wait Until Window Opens Popup Example 10 Wait For And Select Window Popup Example 10 +Select From Search Field Test + Go To https://jquery.com/ + Wait For Page To Load + Select From Search Field //input[@type='search'] css() + Wait Until Javascript Is Complete + Page Should Contain css() + *** Keywords *** Test Case Setup Open Browser browser=Chrome diff --git a/test/GUI/GUITestsEdge.robot b/test/GUI/GUITestsEdge.robot index 65941ca3..8607ff20 100644 --- a/test/GUI/GUITestsEdge.robot +++ b/test/GUI/GUITestsEdge.robot @@ -174,6 +174,13 @@ Wait Until Window Tests Wait Until Window Opens Popup Example 10 Wait For And Select Window Popup Example 10 +Select From Search Field Test + Go To https://jquery.com/ + Wait For Page To Load + Select From Search Field //input[@type='search'] css() + Wait Until Javascript Is Complete + Page Should Contain css() + *** Keywords *** Test Case Setup Open Browser browser=Edge diff --git a/test/GUI/test_gui.py b/test/GUI/test_gui.py index 225919a6..6eb212c1 100644 --- a/test/GUI/test_gui.py +++ b/test/GUI/test_gui.py @@ -441,3 +441,10 @@ def test_react_select_expand_select_list_already_expanded(self): with patch('Zoomba.Helpers.ReactSelect.ReactSelect.is_expanded', return_value=True): ReactSelect.ReactSelect(mock_webelement).expand_select_list() mock_webelement.click.assert_not_called() + + def test_select_from_search_field(self): + mock_gui = Mock() + GUILibrary.select_from_search_field(mock_gui, "some_locator", "some_text", 1) + mock_gui.clear_element_text.assert_called_with("some_locator") + mock_gui.input_text.assert_called_with("some_locator", "some_text") + mock_gui.press_keys.assert_called_with("some_locator", "RETURN")