|
@@ -1,6 +1,5 @@
|
|
|
# TODO(dcramer): this heavily inspired by pytest-selenium, and it's possible
|
|
|
# we could simply inherit from the plugin at this point
|
|
|
-
|
|
|
import logging
|
|
|
import os
|
|
|
import sys
|
|
@@ -17,6 +16,7 @@ from selenium.common.exceptions import (
|
|
|
WebDriverException,
|
|
|
)
|
|
|
from selenium.webdriver.common.action_chains import ActionChains
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
from selenium.webdriver.support import expected_conditions
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
|
@@ -129,10 +129,10 @@ class Browser:
|
|
|
|
|
|
if xpath is not None:
|
|
|
self.wait_until(xpath=xpath)
|
|
|
- return self.driver.find_element_by_xpath(xpath)
|
|
|
+ return self.driver.find_element(by=By.XPATH, value=xpath)
|
|
|
else:
|
|
|
self.wait_until(selector)
|
|
|
- return self.driver.find_element_by_css_selector(selector)
|
|
|
+ return self.driver.find_element(by=By.CSS_SELECTOR, value=selector)
|
|
|
|
|
|
def elements(self, selector=None, xpath=None):
|
|
|
"""
|
|
@@ -141,17 +141,17 @@ class Browser:
|
|
|
|
|
|
if xpath is not None:
|
|
|
self.wait_until(xpath=xpath)
|
|
|
- return self.driver.find_elements_by_xpath(xpath)
|
|
|
+ return self.driver.find_elements(by=By.XPATH, value=xpath)
|
|
|
else:
|
|
|
self.wait_until(selector)
|
|
|
- return self.driver.find_elements_by_css_selector(selector)
|
|
|
+ return self.driver.find_elements(by=By.CSS_SELECTOR, value=selector)
|
|
|
|
|
|
def element_exists(self, selector):
|
|
|
"""
|
|
|
Check if an element exists on the page. This method will *not* wait for the element.
|
|
|
"""
|
|
|
try:
|
|
|
- self.driver.find_element_by_css_selector(selector)
|
|
|
+ self.driver.find_element(by=By.CSS_SELECTOR, value=selector)
|
|
|
except NoSuchElementException:
|
|
|
return False
|
|
|
return True
|
|
@@ -186,7 +186,7 @@ class Browser:
|
|
|
return self
|
|
|
|
|
|
def find_element_by_name(self, name):
|
|
|
- return self.driver.find_element_by_name(name)
|
|
|
+ return self.driver.find_element(by=By.NAME, value=name)
|
|
|
|
|
|
def move_to(self, selector=None):
|
|
|
"""
|
|
@@ -205,8 +205,6 @@ class Browser:
|
|
|
Waits until ``selector`` is visible and enabled to be clicked, or until ``timeout``
|
|
|
is hit, whichever happens first.
|
|
|
"""
|
|
|
- from selenium.webdriver.common.by import By
|
|
|
-
|
|
|
if selector:
|
|
|
condition = expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, selector))
|
|
|
else:
|
|
@@ -221,8 +219,6 @@ class Browser:
|
|
|
Waits until ``selector`` is found in the browser, or until ``timeout``
|
|
|
is hit, whichever happens first.
|
|
|
"""
|
|
|
- from selenium.webdriver.common.by import By
|
|
|
-
|
|
|
if selector:
|
|
|
condition = expected_conditions.presence_of_element_located((By.CSS_SELECTOR, selector))
|
|
|
elif xpath:
|
|
@@ -244,8 +240,6 @@ class Browser:
|
|
|
Waits until ``selector`` is NOT found in the browser, or until
|
|
|
``timeout`` is hit, whichever happens first.
|
|
|
"""
|
|
|
- from selenium.webdriver.common.by import By
|
|
|
-
|
|
|
if selector:
|
|
|
condition = expected_conditions.presence_of_element_located((By.CSS_SELECTOR, selector))
|
|
|
elif title:
|
|
@@ -328,7 +322,7 @@ class Browser:
|
|
|
with self.full_viewport():
|
|
|
screenshot_path = f"{snapshot_dir}/{filename}.png"
|
|
|
# This will make sure we resize viewport height to fit contents
|
|
|
- self.driver.find_element_by_tag_name("body").screenshot(screenshot_path)
|
|
|
+ self.driver.find_element(by=By.TAG_NAME, value="body").screenshot(screenshot_path)
|
|
|
|
|
|
if os.environ.get("SENTRY_SCREENSHOT"):
|
|
|
import click
|
|
@@ -340,7 +334,9 @@ class Browser:
|
|
|
)
|
|
|
if has_tooltips:
|
|
|
screenshot_path = f"{snapshot_dir}-tooltips/{filename}.png"
|
|
|
- self.driver.find_element_by_tag_name("body").screenshot(screenshot_path)
|
|
|
+ self.driver.find_element(by=By.TAG_NAME, value="body").screenshot(
|
|
|
+ screenshot_path
|
|
|
+ )
|
|
|
self.driver.execute_script(
|
|
|
"window.__closeAllTooltips && window.__closeAllTooltips()"
|
|
|
)
|
|
@@ -348,7 +344,7 @@ class Browser:
|
|
|
if not desktop_only:
|
|
|
with self.mobile_viewport():
|
|
|
screenshot_path = f"{snapshot_dir}-mobile/{filename}.png"
|
|
|
- self.driver.find_element_by_tag_name("body").screenshot(screenshot_path)
|
|
|
+ self.driver.find_element(by=By.TAG_NAME, value="body").screenshot(screenshot_path)
|
|
|
|
|
|
if os.environ.get("SENTRY_SCREENSHOT"):
|
|
|
import click
|