Skip to content

Instantly share code, notes, and snippets.

@jrbenny35
Created April 12, 2018 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbenny35/676ea5f424ed31467d7d6167f0d8aafe to your computer and use it in GitHub Desktop.
Save jrbenny35/676ea5f424ed31467d7d6167f0d8aafe to your computer and use it in GitHub Desktop.
base_url = 'http://olympia-frontend.test:3000'
selenium = <selenium.webdriver.firefox.webdriver.WebDriver (session="d68d056f-5d99-4a78-a4f8-52829235d4ce")>
user = {'display_name': 'Super Created 19f572f3', 'email': 'qahsfgdzcyuw@restmail.net', 'fxa_id': None, 'groups': [], ...}
@pytest.mark.withoutresponses
def test_logout(base_url, selenium, user):
"""User can logout"""
page = Home(selenium, base_url).open()
page.login(user['email'], user['password'])
> page.logout()
base_url = 'http://olympia-frontend.test:3000'
page = <pages.desktop.home.Home object at 0x7fee844fc110>
selenium = <selenium.webdriver.firefox.webdriver.WebDriver (session="d68d056f-5d99-4a78-a4f8-52829235d4ce")>
user = {'display_name': 'Super Created 19f572f3', 'email': 'qahsfgdzcyuw@restmail.net', 'fxa_id': None, 'groups': [], ...}
tests/ui/test_login.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pages.desktop.home.Home object at 0x7fee844fc110>
def logout(self):
> self.header.click_logout()
self = <pages.desktop.home.Home object at 0x7fee844fc110>
tests/ui/pages/desktop/base.py:38:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pages.desktop.base.Header object at 0x7fee8c52b3d0>
def click_logout(self):
user = self.find_element(*self._user_locator)
logout = self.find_element(*self._logout_locator)
action = ActionChains(self.selenium)
action.move_to_element(user)
action.move_to_element(logout)
action.click()
> action.perform()
action = <selenium.webdriver.common.action_chains.ActionChains object at 0x7fee844eecd0>
logout = <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="d68d056f-5d99-4a78-a4f8-52829235d4ce", element="07add827-15ee-4bc1-9d88-e107fc344888")>
self = <pages.desktop.base.Header object at 0x7fee8c52b3d0>
user = <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="d68d056f-5d99-4a78-a4f8-52829235d4ce", element="e582e43e-f998-423e-b9b6-3e1612b8e914")>
tests/ui/pages/desktop/base.py:85:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.common.action_chains.ActionChains object at 0x7fee844eecd0>
def perform(self):
"""
Performs all stored actions.
"""
if self._driver.w3c:
> self.w3c_actions.perform()
self = <selenium.webdriver.common.action_chains.ActionChains object at 0x7fee844eecd0>
.tox/ui-tests/local/lib/python2.7/site-packages/selenium/webdriver/common/action_chains.py:80:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.common.actions.action_builder.ActionBuilder object at 0x7fee844fca90>
def perform(self):
enc = {"actions": []}
for device in self.devices:
encoded = device.encode()
if encoded['actions']:
enc["actions"].append(encoded)
> self.driver.execute(Command.W3C_ACTIONS, enc)
device = <selenium.webdriver.common.actions.key_input.KeyInput object at 0x7fee844fcd90>
enc = {'actions': [{'actions': [{'duration': 250, 'origin': {'element-6066-11e4-a52e-4f735466cecf': 'e582e43e-f998-423e-b9b6..., {'duration': 0, 'type': 'pause'}], 'id': 'key', 'type': 'key'}], 'sessionId': 'd68d056f-5d99-4a78-a4f8-52829235d4ce'}
encoded = {'actions': [{'duration': 0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}], 'id': 'key', 'type': 'key'}
self = <selenium.webdriver.common.actions.action_builder.ActionBuilder object at 0x7fee844fca90>
.tox/ui-tests/local/lib/python2.7/site-packages/selenium/webdriver/common/actions/action_builder.py:76:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.firefox.webdriver.WebDriver (session="d68d056f-5d99-4a78-a4f8-52829235d4ce")>
driver_command = 'actions'
params = {'actions': [{'actions': [{'duration': 250, 'origin': {'element-6066-11e4-a52e-4f735466cecf': 'e582e43e-f998-423e-b9b6...0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}], 'id': 'key', 'type': 'key'}]}
def execute(self, driver_command, params=None):
"""
Sends a command to be executed by a command.CommandExecutor.
:Args:
- driver_command: The name of the command to execute as a string.
- params: A dictionary of named parameters to send with the command.
:Returns:
The command's JSON response loaded into a dictionary object.
"""
if self.session_id is not None:
if not params:
params = {'sessionId': self.session_id}
elif 'sessionId' not in params:
params['sessionId'] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
> self.error_handler.check_response(response)
driver_command = 'actions'
params = {'actions': [{'actions': [{'duration': 250, 'origin': {'element-6066-11e4-a52e-4f735466cecf': 'e582e43e-f998-423e-b9b6...0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}, {'duration': 0, 'type': 'pause'}], 'id': 'key', 'type': 'key'}]}
response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"TypeError: rect is undefined","stacktrace":"ele...</req<@chrome://marionette/content/listener.js:493:14\ndispatch/<@chrome://marionette/content/listener.js:486:15\n"}}'}
self = <selenium.webdriver.firefox.webdriver.WebDriver (session="d68d056f-5d99-4a78-a4f8-52829235d4ce")>
.tox/ui-tests/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py:312:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7fee844fcb90>
response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"TypeError: rect is undefined","stacktrace":"ele...</req<@chrome://marionette/content/listener.js:493:14\ndispatch/<@chrome://marionette/content/listener.js:486:15\n"}}'}
def check_response(self, response):
"""
Checks that a JSON response from the WebDriver does not have an error.
:Args:
- response - The JSON response from the WebDriver server as a dictionary
object.
:Raises: If the response contains an error message.
"""
status = response.get('status', None)
if status is None or status == ErrorCode.SUCCESS:
return
value = None
message = response.get("message", "")
screen = response.get("screen", "")
stacktrace = None
if isinstance(status, int):
value_json = response.get('value', None)
if value_json and isinstance(value_json, basestring):
import json
try:
value = json.loads(value_json)
if len(value.keys()) == 1:
value = value['value']
status = value.get('error', None)
if status is None:
status = value["status"]
message = value["value"]
if not isinstance(message, basestring):
value = message
message = message.get('message')
else:
message = value.get('message', None)
except ValueError:
pass
exception_class = ErrorInResponseException
if status in ErrorCode.NO_SUCH_ELEMENT:
exception_class = NoSuchElementException
elif status in ErrorCode.NO_SUCH_FRAME:
exception_class = NoSuchFrameException
elif status in ErrorCode.NO_SUCH_WINDOW:
exception_class = NoSuchWindowException
elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
exception_class = StaleElementReferenceException
elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
exception_class = ElementNotVisibleException
elif status in ErrorCode.INVALID_ELEMENT_STATE:
exception_class = InvalidElementStateException
elif status in ErrorCode.INVALID_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
exception_class = InvalidSelectorException
elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
exception_class = ElementNotSelectableException
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
exception_class = ElementNotInteractableException
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
exception_class = InvalidCookieDomainException
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
exception_class = UnableToSetCookieException
elif status in ErrorCode.TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.SCRIPT_TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.UNKNOWN_ERROR:
exception_class = WebDriverException
elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
exception_class = UnexpectedAlertPresentException
elif status in ErrorCode.NO_ALERT_OPEN:
exception_class = NoAlertPresentException
elif status in ErrorCode.IME_NOT_AVAILABLE:
exception_class = ImeNotAvailableException
elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
exception_class = ImeActivationFailedException
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
exception_class = MoveTargetOutOfBoundsException
elif status in ErrorCode.JAVASCRIPT_ERROR:
exception_class = JavascriptException
elif status in ErrorCode.SESSION_NOT_CREATED:
exception_class = SessionNotCreatedException
elif status in ErrorCode.INVALID_ARGUMENT:
exception_class = InvalidArgumentException
elif status in ErrorCode.NO_SUCH_COOKIE:
exception_class = NoSuchCookieException
elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
exception_class = ScreenshotException
elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
exception_class = ElementClickInterceptedException
elif status in ErrorCode.INSECURE_CERTIFICATE:
exception_class = InsecureCertificateException
elif status in ErrorCode.INVALID_COORDINATES:
exception_class = InvalidCoordinatesException
elif status in ErrorCode.INVALID_SESSION_ID:
exception_class = InvalidSessionIdException
elif status in ErrorCode.UNKNOWN_METHOD:
exception_class = UnknownMethodException
else:
exception_class = WebDriverException
if value == '' or value is None:
value = response['value']
if isinstance(value, basestring):
if exception_class == ErrorInResponseException:
raise exception_class(response, value)
raise exception_class(value)
if message == "" and 'message' in value:
message = value['message']
screen = None
if 'screen' in value:
screen = value['screen']
stacktrace = None
if 'stackTrace' in value and value['stackTrace']:
stacktrace = []
try:
for frame in value['stackTrace']:
line = self._value_or_default(frame, 'lineNumber', '')
file = self._value_or_default(frame, 'fileName', '<anonymous>')
if line:
file = "%s:%s" % (file, line)
meth = self._value_or_default(frame, 'methodName', '<anonymous>')
if 'className' in frame:
meth = "%s.%s" % (frame['className'], meth)
msg = " at %s (%s)"
msg = msg % (meth, file)
stacktrace.append(msg)
except TypeError:
pass
if exception_class == ErrorInResponseException:
raise exception_class(response, message)
elif exception_class == UnexpectedAlertPresentException:
alert_text = None
if 'data' in value:
alert_text = value['data'].get('text')
elif 'alert' in value:
alert_text = value['alert'].get('text')
raise exception_class(message, screen, stacktrace, alert_text)
> raise exception_class(message, screen, stacktrace)
E WebDriverException: Message: TypeError: rect is undefined
exception_class = <class 'selenium.common.exceptions.WebDriverException'>
json = <module 'json' from '/usr/lib/python2.7/json/__init__.pyc'>
message = 'TypeError: rect is undefined'
response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"TypeError: rect is undefined","stacktrace":"ele...</req<@chrome://marionette/content/listener.js:493:14\ndispatch/<@chrome://marionette/content/listener.js:486:15\n"}}'}
screen = None
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7fee844fcb90>
stacktrace = None
status = 'unknown error'
value = {'error': 'unknown error', 'message': 'TypeError: rect is undefined', 'stacktrace': 'element.getInViewCentrePoint@chro...atch/</req<@chrome://marionette/content/listener.js:493:14
dispatch/<@chrome://marionette/content/listener.js:486:15
'}
value_json = '{"value":{"error":"unknown error","message":"TypeError: rect is undefined","stacktrace":"element.getInViewCentrePoint.../</req<@chrome://marionette/content/listener.js:493:14\ndispatch/<@chrome://marionette/content/listener.js:486:15\n"}}'
.tox/ui-tests/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException
------------------------------- pytest-selenium --------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment