This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
169 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
|
||
class new_browser_window_is_opened(object): | ||
""" | ||
An expectation for checking that a new window is found after requesting | ||
it to be opened | ||
:returns: A BrowserWindow Object | ||
""" | ||
|
||
def __init__(self, selenium, handles): | ||
self.selenium = selenium | ||
self.handles = handles | ||
|
||
def __call__(self, *args, **kwargs): | ||
handles = list(set(self.selenium.window_handles) - set(self.handles)) | ||
if len(handles) == 1: | ||
from .windows.browser import BrowserWindow | ||
return BrowserWindow(self.selenium, handles[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
from .base import BaseWindow # noqa | ||
from .browser import BrowserWindow # noqa | ||
from .window_manager import WindowManager # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
|
||
|
||
class BaseWindow(object): | ||
|
||
_document_element = (By.CSS_SELECTOR, ':root') | ||
|
||
def __init__(self, selenium, handle): | ||
self.selenium = selenium | ||
self.handle = handle | ||
self.wait = WebDriverWait(self.selenium, timeout=10) | ||
|
||
@property | ||
def document_element(self): | ||
""" Returns the inner DOM window element. | ||
:returns: DOM window element. | ||
""" | ||
|
||
return self.selenium.find_element(*self._document_element) | ||
|
||
def close(self): | ||
"""Closes the window""" | ||
self.switch_to() | ||
self.selenium.close() | ||
|
||
def switch_to(self): | ||
"""Switches to the window""" | ||
|
||
self.selenium.switch_to.window(self.handle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
|
||
class WindowManager(object): | ||
|
||
def __init__(self, selenium): | ||
self.selenium = selenium | ||
|
||
@property | ||
def windows(self): | ||
""" | ||
Sets all current window handles to appropriate window instances | ||
:returns: A list of BrowserWindow Instances | ||
""" | ||
from foxpuppet.windows.browser import BrowserWindow | ||
return [BrowserWindow(self.selenium, handle) | ||
for handle in self.selenium.window_handles] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import pytest | ||
|
||
from foxpuppet import FoxPuppet | ||
|
||
|
||
@pytest.fixture | ||
def foxpuppet(selenium): | ||
return FoxPuppet(selenium) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters