Skip to content

Commit

Permalink
Add new_window() and new_tab() methods to SwitchTo class (#225)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Kidman <[email protected]>
  • Loading branch information
ElSnoMan and Carlos Kidman authored Oct 28, 2021
1 parent f978fcf commit 79373c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 13 additions & 3 deletions pylenium/switch_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, pylenium):
self._py = pylenium

def frame(self, name_or_id: str, timeout: int = 0):
"""Switch the driver's context to the new frame given the name or id of the element.
"""Switch the driver's context to a frame given the name or id of the element.
Args:
name_or_id: The frame's `id` or `name` attribute value
Expand Down Expand Up @@ -66,11 +66,21 @@ def default_content(self):
self._py.webdriver.switch_to.default_content()
return self._py

def new_window(self):
"""Open a new Browser Window and switch the driver's context (aka focus) to it."""
self._py.webdriver.switch_to.new_window("window")
return self._py

def new_tab(self):
"""Open a new Browser Tab and switch the driver's context (aka focus) to it."""
self._py.webdriver.switch_to.new_window("tab")
return self._py

def window(self, name_or_handle="", index=0):
"""Switch the driver's context to the specified Window or Browser Tab.
"""Switch the driver's context (aka focus) to the specified Browser Window or Browser Tab.
Args:
name_or_handle: The name or window handle of the Window to switch to.
name_or_handle: The name or window handle of the Window or Tab to switch to.
index: The index position of the Window Handle.
* `index=0` would be the default content.
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/test_pydriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def test_execute_script(py: Pylenium):
assert py.execute_script("return arguments[0].parentNode;", webelement)


def test_google_search(py: Pylenium):
py.visit("https://google.com")
py.get("[name='q']").type("puppies", py.Keys.ENTER)
assert py.should().contain_title("puppies")
def test_new_window_and_tab(py: Pylenium):
py.switch_to.new_window()
assert len(py.window_handles) == 2

py.switch_to.new_tab()
assert len(py.window_handles) == 3


def test_cookies(py: Pylenium):
Expand Down

0 comments on commit 79373c9

Please sign in to comment.