Skip to content

Commit

Permalink
step to save window handles (#21)
Browse files Browse the repository at this point in the history
* step to save window handles
  • Loading branch information
mario-s authored Oct 16, 2023
1 parent 5227193 commit 84f5f3c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The following Gauge steps are implemented in this module:
- [Save placeholder \<placeholder> = \<value>](#save-placeholder-placeholder--value)
- [Save placeholder \<placeholder> from \<by> = \<by_value>](#save-placeholder-placeholder-from-by--by_value)
- [Save placeholder \<placeholder> from attribute \<attribute> of \<by> = \<by_value>](#save-placeholder-placeholder-from-attribute-attribute-of-by--by_value)
- [Save window handles](#save-window-handles)
- [Set timeout \<seconds>](#set-timeout-seconds)
- [Reset timeout](#reset-timeout)
- [Assert window handles is \<windows_num>](#assert-window-handles-is-windows_num)
Expand Down Expand Up @@ -1174,6 +1175,18 @@ Support
|:-----:|:--------------:|:----------:|
||||

## Save window handles

> \* Save window handles
Saves all current window handles in a placeholder with the name "\_window_handles".

Support

|Desktop|Android (Chrome)|iOS (Safari)|
|:-----:|:--------------:|:----------:|
||||

## Set timeout \<seconds>

> \* Set timeout "1"
Expand Down
6 changes: 6 additions & 0 deletions gauge_web_app_steps/web_app_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
app_context_key = "_app_ctx"
basic_auth_key = "_basic_auth"
timeout_key = "_timeout"
window_handles_key = "_window_handles"


@before_suite
Expand Down Expand Up @@ -694,6 +695,11 @@ def save_placeholder_from_element_attribute(placeholder_name_param: str, attribu
data_store.scenario[placeholder_name] = attribute_value


@step("Save window handles")
def save_window_handles() -> None:
data_store.scenario[window_handles_key] = driver().window_handles


@step("Set timeout <seconds>")
def set_timeout(seconds_param: str):
seconds = _substitute(seconds_param)
Expand Down
10 changes: 8 additions & 2 deletions tests/test_web_app_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
before_step_hook,
execute_async_script, execute_async_script_on_element, execute_async_script_on_element_save_result, execute_async_script_save_result,
execute_script, execute_script_on_element, execute_script_on_element_save_result, execute_script_save_result,
reset_timeout, save_placeholder, set_timeout, switch_to_frame,
_substitute, timeout_key
reset_timeout, save_placeholder, save_window_handles, set_timeout, switch_to_frame,
_substitute, timeout_key, window_handles_key
)


Expand Down Expand Up @@ -97,6 +97,12 @@ def test_save_placeholder(self):
result = data_store.scenario.get("placeholder-key")
self.assertEqual("placeholder_value", result)

def test_save_window_handles(self):
self.app_context.driver.window_handles.return_value = ["foo"]
save_window_handles()
result = data_store.scenario.get(window_handles_key).return_value
self.assertEqual(["foo"], result)

def test_reset_timeout(self):
set_timeout("2")
reset_timeout()
Expand Down

0 comments on commit 84f5f3c

Please # to comment.