Skip to content

Commit d1e7ee7

Browse files
Relative imports processed with futurized:
RefactoringTool: Files that were modified: RefactoringTool: .\src\Selenium2Library\__init__.py RefactoringTool: .\src\Selenium2Library\webdrivermonkeypatches.py RefactoringTool: .\src\Selenium2Library\keywords\__init__.py RefactoringTool: .\src\Selenium2Library\keywords\_alert.py RefactoringTool: .\src\Selenium2Library\keywords\_browsermanagement.py RefactoringTool: .\src\Selenium2Library\keywords\_cookie.py RefactoringTool: .\src\Selenium2Library\keywords\_element.py RefactoringTool: .\src\Selenium2Library\keywords\_formelement.py RefactoringTool: .\src\Selenium2Library\keywords\_javascript.py RefactoringTool: .\src\Selenium2Library\keywords\_logging.py RefactoringTool: .\src\Selenium2Library\keywords\_runonfailure.py RefactoringTool: .\src\Selenium2Library\keywords\_screenshot.py RefactoringTool: .\src\Selenium2Library\keywords\_selectelement.py RefactoringTool: .\src\Selenium2Library\keywords\_tableelement.py RefactoringTool: .\src\Selenium2Library\keywords\_waiting.py RefactoringTool: .\src\Selenium2Library\locators\__init__.py RefactoringTool: .\src\Selenium2Library\locators\tableelementfinder.py RefactoringTool: .\src\Selenium2Library\utils\__init__.py RefactoringTool: .\src\Selenium2Library\utils\librarylistener.py RefactoringTool: .\src\Selenium2Library\utils\events\__init__.py RefactoringTool: .\src\Selenium2Library\utils\events\scope_event.py RefactoringTool: .\test\lib\mockito\__init__.py RefactoringTool: .\test\lib\mockito\inorder.py RefactoringTool: .\test\lib\mockito\invocation.py RefactoringTool: .\test\lib\mockito\mocking.py RefactoringTool: .\test\lib\mockito\mockito.py RefactoringTool: .\test\lib\mockito\spying.py Imports in single lines and on top of files. PEP8 E401 and E402
1 parent f5229cf commit d1e7ee7

30 files changed

+250
-206
lines changed

build_dist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env python
22

3-
import os, sys, shutil, subprocess, argparse
3+
import argparse
4+
import os
5+
import shutil
6+
import subprocess
7+
import sys
8+
49

510
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
611
DIST_DIR = os.path.join(THIS_DIR, "dist")

src/Selenium2Library/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from __future__ import absolute_import
12
import os
2-
from keywords import *
3-
from version import VERSION
4-
from utils import LibraryListener
3+
from .keywords import *
4+
from .version import VERSION
5+
from .utils import LibraryListener
56

67
__version__ = VERSION
78

src/Selenium2Library/keywords/__init__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
from _logging import _LoggingKeywords
2-
from _runonfailure import _RunOnFailureKeywords
3-
from _browsermanagement import _BrowserManagementKeywords
4-
from _element import _ElementKeywords
5-
from _tableelement import _TableElementKeywords
6-
from _formelement import _FormElementKeywords
7-
from _selectelement import _SelectElementKeywords
8-
from _javascript import _JavaScriptKeywords
9-
from _cookie import _CookieKeywords
10-
from _screenshot import _ScreenshotKeywords
11-
from _waiting import _WaitingKeywords
12-
from _alert import _AlertKeywords
1+
from __future__ import absolute_import
2+
from ._logging import _LoggingKeywords
3+
from ._runonfailure import _RunOnFailureKeywords
4+
from ._browsermanagement import _BrowserManagementKeywords
5+
from ._element import _ElementKeywords
6+
from ._tableelement import _TableElementKeywords
7+
from ._formelement import _FormElementKeywords
8+
from ._selectelement import _SelectElementKeywords
9+
from ._javascript import _JavaScriptKeywords
10+
from ._cookie import _CookieKeywords
11+
from ._screenshot import _ScreenshotKeywords
12+
from ._waiting import _WaitingKeywords
13+
from ._alert import _AlertKeywords
1314

1415
__all__ = [
1516
"_LoggingKeywords",
Lines changed: 137 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,137 @@
1-
from selenium.common.exceptions import WebDriverException
2-
from selenium.webdriver.support.ui import WebDriverWait
3-
from selenium.webdriver.support import expected_conditions as EC
4-
from keywordgroup import KeywordGroup
5-
6-
7-
class _AlertKeywords(KeywordGroup):
8-
9-
def __init__(self):
10-
self._cancel_on_next_confirmation = False
11-
12-
# Public
13-
14-
def input_text_into_prompt(self, text):
15-
"""Types the given `text` into alert box. """
16-
alert = None
17-
try:
18-
alert = self._wait_alert()
19-
alert.send_keys(text)
20-
except WebDriverException:
21-
raise RuntimeError('There were no alerts')
22-
23-
def alert_should_be_present(self, text=''):
24-
"""Verifies an alert is present and dismisses it.
25-
26-
If `text` is a non-empty string, then it is also verified that the
27-
message of the alert equals to `text`.
28-
29-
Will fail if no alert is present. Note that following keywords
30-
will fail unless the alert is dismissed by this
31-
keyword or another like `Get Alert Message`.
32-
"""
33-
alert_text = self.get_alert_message()
34-
if text and alert_text != text:
35-
raise AssertionError("Alert text should have been "
36-
"'%s' but was '%s'"
37-
% (text, alert_text))
38-
39-
def choose_cancel_on_next_confirmation(self):
40-
"""Cancel will be selected the next time `Confirm Action` is used."""
41-
self._cancel_on_next_confirmation = True
42-
43-
def choose_ok_on_next_confirmation(self):
44-
"""Undo the effect of using keywords `Choose Cancel On Next Confirmation`. Note
45-
that Selenium's overridden window.confirm() function will normally
46-
automatically return true, as if the user had manually clicked OK, so
47-
you shouldn't need to use this command unless for some reason you need
48-
to change your mind prior to the next confirmation. After any
49-
confirmation, Selenium will resume using the default behavior for
50-
future confirmations, automatically returning true (OK) unless/until
51-
you explicitly use `Choose Cancel On Next Confirmation` for each
52-
confirmation.
53-
54-
Note that every time a confirmation comes up, you must
55-
consume it by using a keywords such as `Get Alert Message`, or else
56-
the following selenium operations will fail.
57-
"""
58-
self._cancel_on_next_confirmation = False
59-
60-
def confirm_action(self):
61-
"""Dismisses currently shown confirmation dialog and returns it's message.
62-
63-
By default, this keyword chooses 'OK' option from the dialog. If
64-
'Cancel' needs to be chosen, keyword `Choose Cancel On Next
65-
Confirmation` must be called before the action that causes the
66-
confirmation dialog to be shown.
67-
68-
Examples:
69-
| Click Button | Send | # Shows a confirmation dialog |
70-
| ${message}= | Confirm Action | # Chooses Ok |
71-
| Should Be Equal | ${message} | Are your sure? |
72-
| | | |
73-
| Choose Cancel On Next Confirmation | | |
74-
| Click Button | Send | # Shows a confirmation dialog |
75-
| Confirm Action | | # Chooses Cancel |
76-
"""
77-
text = self._close_alert(not self._cancel_on_next_confirmation)
78-
self._cancel_on_next_confirmation = False
79-
return text
80-
81-
def get_alert_message(self, dismiss=True):
82-
"""Returns the text of current JavaScript alert.
83-
84-
By default the current JavaScript alert will be dismissed.
85-
This keyword will fail if no alert is present. Note that
86-
following keywords will fail unless the alert is
87-
dismissed by this keyword or another like `Get Alert Message`.
88-
"""
89-
if dismiss:
90-
return self._close_alert()
91-
else:
92-
return self._read_alert()
93-
94-
def dismiss_alert(self, accept=True):
95-
""" Returns true if alert was confirmed, false if it was dismissed
96-
97-
This keyword will fail if no alert is present. Note that
98-
following keywords will fail unless the alert is
99-
dismissed by this keyword or another like `Get Alert Message`.
100-
"""
101-
return self._handle_alert(accept)
102-
103-
# Private
104-
105-
def _close_alert(self, confirm=True):
106-
try:
107-
text = self._read_alert()
108-
self._handle_alert(confirm)
109-
return text
110-
except WebDriverException:
111-
raise RuntimeError('There were no alerts')
112-
113-
def _read_alert(self):
114-
alert = None
115-
try:
116-
alert = self._wait_alert()
117-
# collapse new lines chars
118-
return ' '.join(alert.text.splitlines())
119-
except WebDriverException:
120-
raise RuntimeError('There were no alerts')
121-
122-
def _handle_alert(self, confirm=True):
123-
try:
124-
alert = self._wait_alert()
125-
if not confirm:
126-
alert.dismiss()
127-
return False
128-
else:
129-
alert.accept()
130-
return True
131-
except WebDriverException:
132-
raise RuntimeError('There were no alerts')
133-
134-
def _wait_alert(self):
135-
return WebDriverWait(self._current_browser(), 1).until(
136-
EC.alert_is_present())
1+
from __future__ import absolute_import
2+
from selenium.common.exceptions import WebDriverException
3+
from selenium.webdriver.support.ui import WebDriverWait
4+
from selenium.webdriver.support import expected_conditions as EC
5+
from .keywordgroup import KeywordGroup
6+
7+
8+
class _AlertKeywords(KeywordGroup):
9+
10+
def __init__(self):
11+
self._cancel_on_next_confirmation = False
12+
13+
# Public
14+
15+
def input_text_into_prompt(self, text):
16+
"""Types the given `text` into alert box. """
17+
alert = None
18+
try:
19+
alert = self._wait_alert()
20+
alert.send_keys(text)
21+
except WebDriverException:
22+
raise RuntimeError('There were no alerts')
23+
24+
def alert_should_be_present(self, text=''):
25+
"""Verifies an alert is present and dismisses it.
26+
27+
If `text` is a non-empty string, then it is also verified that the
28+
message of the alert equals to `text`.
29+
30+
Will fail if no alert is present. Note that following keywords
31+
will fail unless the alert is dismissed by this
32+
keyword or another like `Get Alert Message`.
33+
"""
34+
alert_text = self.get_alert_message()
35+
if text and alert_text != text:
36+
raise AssertionError("Alert text should have been "
37+
"'%s' but was '%s'"
38+
% (text, alert_text))
39+
40+
def choose_cancel_on_next_confirmation(self):
41+
"""Cancel will be selected the next time `Confirm Action` is used."""
42+
self._cancel_on_next_confirmation = True
43+
44+
def choose_ok_on_next_confirmation(self):
45+
"""Undo the effect of using keywords `Choose Cancel On Next Confirmation`. Note
46+
that Selenium's overridden window.confirm() function will normally
47+
automatically return true, as if the user had manually clicked OK, so
48+
you shouldn't need to use this command unless for some reason you need
49+
to change your mind prior to the next confirmation. After any
50+
confirmation, Selenium will resume using the default behavior for
51+
future confirmations, automatically returning true (OK) unless/until
52+
you explicitly use `Choose Cancel On Next Confirmation` for each
53+
confirmation.
54+
55+
Note that every time a confirmation comes up, you must
56+
consume it by using a keywords such as `Get Alert Message`, or else
57+
the following selenium operations will fail.
58+
"""
59+
self._cancel_on_next_confirmation = False
60+
61+
def confirm_action(self):
62+
"""Dismisses currently shown confirmation dialog and returns it's message.
63+
64+
By default, this keyword chooses 'OK' option from the dialog. If
65+
'Cancel' needs to be chosen, keyword `Choose Cancel On Next
66+
Confirmation` must be called before the action that causes the
67+
confirmation dialog to be shown.
68+
69+
Examples:
70+
| Click Button | Send | # Shows a confirmation dialog |
71+
| ${message}= | Confirm Action | # Chooses Ok |
72+
| Should Be Equal | ${message} | Are your sure? |
73+
| | | |
74+
| Choose Cancel On Next Confirmation | | |
75+
| Click Button | Send | # Shows a confirmation dialog |
76+
| Confirm Action | | # Chooses Cancel |
77+
"""
78+
text = self._close_alert(not self._cancel_on_next_confirmation)
79+
self._cancel_on_next_confirmation = False
80+
return text
81+
82+
def get_alert_message(self, dismiss=True):
83+
"""Returns the text of current JavaScript alert.
84+
85+
By default the current JavaScript alert will be dismissed.
86+
This keyword will fail if no alert is present. Note that
87+
following keywords will fail unless the alert is
88+
dismissed by this keyword or another like `Get Alert Message`.
89+
"""
90+
if dismiss:
91+
return self._close_alert()
92+
else:
93+
return self._read_alert()
94+
95+
def dismiss_alert(self, accept=True):
96+
""" Returns true if alert was confirmed, false if it was dismissed
97+
98+
This keyword will fail if no alert is present. Note that
99+
following keywords will fail unless the alert is
100+
dismissed by this keyword or another like `Get Alert Message`.
101+
"""
102+
return self._handle_alert(accept)
103+
104+
# Private
105+
106+
def _close_alert(self, confirm=True):
107+
try:
108+
text = self._read_alert()
109+
self._handle_alert(confirm)
110+
return text
111+
except WebDriverException:
112+
raise RuntimeError('There were no alerts')
113+
114+
def _read_alert(self):
115+
alert = None
116+
try:
117+
alert = self._wait_alert()
118+
# collapse new lines chars
119+
return ' '.join(alert.text.splitlines())
120+
except WebDriverException:
121+
raise RuntimeError('There were no alerts')
122+
123+
def _handle_alert(self, confirm=True):
124+
try:
125+
alert = self._wait_alert()
126+
if not confirm:
127+
alert.dismiss()
128+
return False
129+
else:
130+
alert.accept()
131+
return True
132+
except WebDriverException:
133+
raise RuntimeError('There were no alerts')
134+
135+
def _wait_alert(self):
136+
return WebDriverWait(self._current_browser(), 1).until(
137+
EC.alert_is_present())

src/Selenium2Library/keywords/_browsermanagement.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import absolute_import
12
import os
23
import robot
34
from robot.errors import DataError
45
from selenium import webdriver
56
from Selenium2Library import webdrivermonkeypatches
67
from Selenium2Library.utils import BrowserCache
78
from Selenium2Library.locators import WindowManager
8-
from keywordgroup import KeywordGroup
9+
from .keywordgroup import KeywordGroup
910
from selenium.common.exceptions import NoSuchWindowException
1011

1112
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

src/Selenium2Library/keywords/_cookie.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from keywordgroup import KeywordGroup
1+
from __future__ import absolute_import
2+
from .keywordgroup import KeywordGroup
23

34
class _CookieKeywords(KeywordGroup):
45

src/Selenium2Library/keywords/_element.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from __future__ import absolute_import
12
from selenium.webdriver.common.keys import Keys
23
from selenium.webdriver.common.action_chains import ActionChains
34
from selenium.webdriver.remote.webelement import WebElement
45
from Selenium2Library import utils
56
from Selenium2Library.locators import ElementFinder
67
from Selenium2Library.locators import CustomLocator
7-
from keywordgroup import KeywordGroup
8+
from .keywordgroup import KeywordGroup
89

910
try:
1011
basestring # attempt to evaluate basestring

src/Selenium2Library/keywords/_formelement.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import absolute_import
12
import os
2-
from keywordgroup import KeywordGroup
3+
from .keywordgroup import KeywordGroup
34
from selenium.common.exceptions import WebDriverException
45

56
class _FormElementKeywords(KeywordGroup):

src/Selenium2Library/keywords/_javascript.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import absolute_import
12
import os
2-
from keywordgroup import KeywordGroup
3+
from .keywordgroup import KeywordGroup
34

45

56
class _JavaScriptKeywords(KeywordGroup):

src/Selenium2Library/keywords/_logging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from __future__ import absolute_import
12
import os
23
import sys
34
from robot.api import logger
4-
from keywordgroup import KeywordGroup
5+
from .keywordgroup import KeywordGroup
56
from robot.libraries.BuiltIn import BuiltIn
67

78
try:

src/Selenium2Library/keywords/_runonfailure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import absolute_import
12
from robot.libraries import BuiltIn
2-
from keywordgroup import KeywordGroup
3+
from .keywordgroup import KeywordGroup
34

45
BUILTIN = BuiltIn.BuiltIn()
56

0 commit comments

Comments
 (0)