Skip to content

Commit

Permalink
Fix flake8 issues in Python client
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed Jun 20, 2016
1 parent 62ff9d3 commit a1b3b47
Show file tree
Hide file tree
Showing 107 changed files with 980 additions and 886 deletions.
2 changes: 1 addition & 1 deletion py/selenium/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# specific language governing permissions and limitations
# under the License.

from . import exceptions
from . import exceptions # noqa
52 changes: 37 additions & 15 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Exceptions that may happen in all the webdriver code.
"""


class WebDriverException(Exception):
"""
Base webdriver exception.
Expand All @@ -38,6 +39,7 @@ def __str__(self):
exception_msg += "Stacktrace:\n%s" % stacktrace
return exception_msg


class ErrorInResponseException(WebDriverException):
"""
Thrown when an error has occurred on the server side.
Expand All @@ -49,52 +51,58 @@ def __init__(self, response, msg):
WebDriverException.__init__(self, msg)
self.response = response


class InvalidSwitchToTargetException(WebDriverException):
"""
Thrown when frame or window target to be switched doesn't exist.
"""
pass


class NoSuchFrameException(InvalidSwitchToTargetException):
"""
Thrown when frame target to be switched doesn't exist.
"""
pass


class NoSuchWindowException(InvalidSwitchToTargetException):
"""
Thrown when window target to be switched doesn't exist.
To find the current set of active window handles, you can get a list
To find the current set of active window handles, you can get a list
of the active window handles in the following way::
print driver.window_handles
"""
pass


class NoSuchElementException(WebDriverException):
"""
Thrown when element could not be found.
If you encounter this exception, you may want to check the following:
* Check your selector used in your find_by...
* Element may not yet be on the screen at the time of the find operation,
(webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
(webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
for how to write a wait wrapper to wait for an element to appear.
"""
pass


class NoSuchAttributeException(WebDriverException):
"""
Thrown when the attribute of element could not be found.
You may want to check if the attribute exists in the particular browser you are
testing against. Some browsers may have different property names for the same
You may want to check if the attribute exists in the particular browser you are
testing against. Some browsers may have different property names for the same
property. (IE8's .innerText vs. Firefox .textContent)
"""
pass


class StaleElementReferenceException(WebDriverException):
"""
Thrown when a reference to an element is now "stale".
Expand All @@ -103,26 +111,28 @@ class StaleElementReferenceException(WebDriverException):
Possible causes of StaleElementReferenceException include, but not limited to:
* You are no longer on the same page, or the page may have refreshed since the element
* You are no longer on the same page, or the page may have refreshed since the element
was located.
* The element may have been removed and re-added to the screen, since it was located.
Such as an element being relocated.
This can happen typically with a javascript framework when values are updated and the
Such as an element being relocated.
This can happen typically with a javascript framework when values are updated and the
node is rebuilt.
* Element may have been inside an iframe or another context which was refreshed.
"""
pass

class InvalidElementStateException(WebDriverException):

class InvalidElementStateException(WebDriverException):
"""
"""
pass


class UnexpectedAlertPresentException(WebDriverException):
"""
Thrown when an unexpected alert is appeared.
Usually raised when when an expected modal is blocking webdriver form executing any
Usually raised when when an expected modal is blocking webdriver form executing any
more commands.
"""
def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None):
Expand All @@ -132,70 +142,80 @@ def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None):
def __str__(self):
return "Alert Text: %s\n%s" % (self.alert_text, super(UnexpectedAlertPresentException, self).__str__())


class NoAlertPresentException(WebDriverException):
"""
Thrown when switching to no presented alert.
This can be caused by calling an operation on the Alert() class when an alert is
This can be caused by calling an operation on the Alert() class when an alert is
not yet on the screen.
"""
pass


class ElementNotVisibleException(InvalidElementStateException):
"""
Thrown when an element is present on the DOM, but
Thrown when an element is present on the DOM, but
it is not visible, and so is not able to be interacted with.
Most commonly encountered when trying to click or read text
Most commonly encountered when trying to click or read text
of an element that is hidden from view.
"""
pass


class ElementNotSelectableException(InvalidElementStateException):
"""
Thrown when trying to select an unselectable element.
For example, selecting a 'script' element.
"""
pass


class InvalidCookieDomainException(WebDriverException):
"""
Thrown when attempting to add a cookie under a different domain
than the current URL.
"""
pass


class UnableToSetCookieException(WebDriverException):
"""
Thrown when a driver fails to set a cookie.
"""
pass


class RemoteDriverServerException(WebDriverException):
"""
"""
pass


class TimeoutException(WebDriverException):
"""
Thrown when a command does not complete in enough time.
"""
pass


class MoveTargetOutOfBoundsException(WebDriverException):
"""
Thrown when the target provided to the `ActionsChains` move()
Thrown when the target provided to the `ActionsChains` move()
method is invalid, i.e. out of document.
"""
pass


class UnexpectedTagNameException(WebDriverException):
"""
Thrown when a support class did not get an expected web element.
"""
pass


class InvalidSelectorException(NoSuchElementException):
"""
Thrown when the selector which is used to find an element does not return
Expand All @@ -206,13 +226,15 @@ class InvalidSelectorException(NoSuchElementException):
"""
pass


class ImeNotAvailableException(WebDriverException):
"""
Thrown when IME support is not available. This exception is thrown for every IME-related
method call if IME support is not available on the machine.
"""
pass


class ImeActivationFailedException(WebDriverException):
"""
Thrown when activating an IME engine has failed.
Expand Down
32 changes: 16 additions & 16 deletions py/selenium/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
# specific language governing permissions and limitations
# under the License.

from .firefox.webdriver import WebDriver as Firefox
from .firefox.firefox_profile import FirefoxProfile
from .chrome.webdriver import WebDriver as Chrome
from .chrome.options import Options as ChromeOptions
from .ie.webdriver import WebDriver as Ie
from .edge.webdriver import WebDriver as Edge
from .opera.webdriver import WebDriver as Opera
from .safari.webdriver import WebDriver as Safari
from .blackberry.webdriver import WebDriver as BlackBerry
from .phantomjs.webdriver import WebDriver as PhantomJS
from .android.webdriver import WebDriver as Android
from .remote.webdriver import WebDriver as Remote
from .common.desired_capabilities import DesiredCapabilities
from .common.action_chains import ActionChains
from .common.touch_actions import TouchActions
from .common.proxy import Proxy
from .firefox.webdriver import WebDriver as Firefox # noqa
from .firefox.firefox_profile import FirefoxProfile # noqa
from .chrome.webdriver import WebDriver as Chrome # noqa
from .chrome.options import Options as ChromeOptions # noqa
from .ie.webdriver import WebDriver as Ie # noqa
from .edge.webdriver import WebDriver as Edge # noqa
from .opera.webdriver import WebDriver as Opera # noqa
from .safari.webdriver import WebDriver as Safari # noqa
from .blackberry.webdriver import WebDriver as BlackBerry # noqa
from .phantomjs.webdriver import WebDriver as PhantomJS # noqa
from .android.webdriver import WebDriver as Android # noqa
from .remote.webdriver import WebDriver as Remote # noqa
from .common.desired_capabilities import DesiredCapabilities # noqa
from .common.action_chains import ActionChains # noqa
from .common.touch_actions import TouchActions # noqa
from .common.proxy import Proxy # noqa

__version__ = '2.53.0'
1 change: 0 additions & 1 deletion py/selenium/webdriver/android/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

6 changes: 3 additions & 3 deletions py/selenium/webdriver/android/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.

import base64
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


class WebDriver(RemoteWebDriver):
"""
Simple RemoteWebDriver wrapper to start connect to Selendroid's WebView app
Expand All @@ -36,7 +36,7 @@ def __init__(self, host="localhost", port=4444, desired_capabilities=DesiredCapa
- port - port that selendroid is running on
- desired_capabilities: Dictionary object with capabilities
"""
RemoteWebDriver.__init__(self,
RemoteWebDriver.__init__(
self,
command_executor="http://%s:%d/wd/hub" % (host, port),
desired_capabilities=desired_capabilities)

7 changes: 5 additions & 2 deletions py/selenium/webdriver/blackberry/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

import os
import platform
import time
import subprocess

from selenium.webdriver.remote.command import Command
try:
import http.client as http_client
except ImportError:
import httplib as http_client

from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/chrome/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

from selenium.webdriver.remote.remote_connection import RemoteConnection


class ChromeRemoteConnection(RemoteConnection):

def __init__(self, remote_server_addr, keep_alive=True):
RemoteConnection.__init__(self, remote_server_addr, keep_alive)
self._commands["launchApp"] = ('POST',
'/session/$sessionId/chromium/launch_app')
self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app')
4 changes: 3 additions & 1 deletion py/selenium/webdriver/chrome/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from selenium.webdriver.common import service


class Service(service.Service):
"""
Object that manages the starting and stopping of the ChromeDriver
Expand All @@ -34,7 +36,7 @@ def __init__(self, executable_path, port=0, service_args=None,

self.service_args = service_args or []
if log_path:
self.service_args.append('--log-path=%s' % log_path)
self.service_args.append('--log-path=%s' % log_path)

service.Service.__init__(self, executable_path, port=port, env=env,
start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")
Expand Down
14 changes: 8 additions & 6 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
# specific language governing permissions and limitations
# under the License.

import base64
from selenium.webdriver.remote.command import Command
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from selenium.common.exceptions import WebDriverException
from .remote_connection import ChromeRemoteConnection
from .service import Service
from .options import Options


class WebDriver(RemoteWebDriver):
"""
Controls the ChromeDriver and allows you to drive the browser.
Expand Down Expand Up @@ -56,12 +54,16 @@ def __init__(self, executable_path="chromedriver", port=0,
else:
desired_capabilities.update(chrome_options.to_capabilities())

self.service = Service(executable_path, port=port,
service_args=service_args, log_path=service_log_path)
self.service = Service(
executable_path,
port=port,
service_args=service_args,
log_path=service_log_path)
self.service.start()

try:
RemoteWebDriver.__init__(self,
RemoteWebDriver.__init__(
self,
command_executor=ChromeRemoteConnection(
remote_server_addr=self.service.service_url),
desired_capabilities=desired_capabilities)
Expand Down
Loading

0 comments on commit a1b3b47

Please sign in to comment.