Skip to content

Commit

Permalink
Selenium has deprecated get_attribute
Browse files Browse the repository at this point in the history
Use `get_dom_attribute` instead.
  • Loading branch information
prusse-martin committed Nov 27, 2024
1 parent 96609cf commit f4411d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
36 changes: 18 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def get_vertex_position(self, vertex):
:rtype: tuple[float, float]
:return: Left/X and top/Y screen coordinates of vertex, respectively.
"""
return float(vertex.get_attribute("x")), float(vertex.get_attribute("y"))
return float(vertex.get_dom_attribute("x")), float(vertex.get_dom_attribute("y"))

def get_vertex_size(self, vertex):
"""
Expand All @@ -357,7 +357,7 @@ def get_vertex_size(self, vertex):
:rtype: tuple[int, int]
:return: Width and height in pixels of vertex, respectively.
"""
return int(vertex.get_attribute("width")), int(vertex.get_attribute("height"))
return int(vertex.get_dom_attribute("width")), int(vertex.get_dom_attribute("height"))

def get_edge(self, source, target):
"""
Expand All @@ -373,7 +373,7 @@ def get_edge(self, source, target):
# An edge is represented by a SVG path, it is created from
# right side of 'foo' vertex until it connects with 'bar'.
def get(v, attr):
return int(v.get_attribute(attr))
return int(v.get_dom_attribute(attr))

from selenium.common.exceptions import StaleElementReferenceException

Expand Down Expand Up @@ -430,7 +430,7 @@ def get_edge_position(self, edge):
"""
import re

edge_coords = re.search(r"M (\d+) (\d+)", edge.get_attribute("d"))
edge_coords = re.search(r"M (\d+) (\d+)", edge.get_dom_attribute("d"))
return int(edge_coords.group(1)), int(edge_coords.group(2))

def get_id(self, cell):
Expand Down Expand Up @@ -532,8 +532,8 @@ def select_vertex(self, vertex):
# because of element mismatch. This is an attempt to click in the
# bottom right part of vertex that *usually* doesn't seem to have
# anything over it.
x_offset = int(vertex.get_attribute("width")) // 2
y_offset = int(vertex.get_attribute("height")) // 2
x_offset = int(vertex.get_dom_attribute("width")) // 2
y_offset = int(vertex.get_dom_attribute("height")) // 2
assert (x_offset > 0) and (y_offset > 0)
actions.move_to_element_with_offset(vertex, x_offset, y_offset)
actions.click()
Expand Down Expand Up @@ -712,10 +712,10 @@ def __init__(self, selenium, host):
selenium.execute_script("api.insertVertex(10, 10, 25, 25, 'label', null)")

vertex = self.get_vertex()
assert vertex.get_attribute("x") == "10"
assert vertex.get_attribute("y") == "10"
assert vertex.get_attribute("width") == "25"
assert vertex.get_attribute("height") == "25"
assert vertex.get_dom_attribute("x") == "10"
assert vertex.get_dom_attribute("y") == "10"
assert vertex.get_dom_attribute("width") == "25"
assert vertex.get_dom_attribute("height") == "25"
assert self.get_label_element(vertex).text == "label"

def get_vertex(self):
Expand Down Expand Up @@ -762,10 +762,10 @@ def __init__(self, selenium, host):
selenium.execute_script("api.insertVertex(10, 10, 25, 25, 'yellow', 'yellow')")

vertex = self.get_vertex()
assert vertex.get_attribute("x") == "10"
assert vertex.get_attribute("y") == "10"
assert vertex.get_attribute("width") == "25"
assert vertex.get_attribute("height") == "25"
assert vertex.get_dom_attribute("x") == "10"
assert vertex.get_dom_attribute("y") == "10"
assert vertex.get_dom_attribute("width") == "25"
assert vertex.get_dom_attribute("height") == "25"
assert self.get_label_element(vertex).text == "yellow"

def get_vertex(self):
Expand Down Expand Up @@ -848,10 +848,10 @@ def __init__(self, selenium, host):
self.eval_js_function("api.insertDecoration", x, y, w, h, label, style)

decoration = self.get_decorations()[0]
assert int(decoration.get_attribute("x")) == x - (w // 2)
assert int(decoration.get_attribute("y")) == y - (h // 2)
assert int(decoration.get_attribute("width")) == w
assert int(decoration.get_attribute("height")) == h
assert int(decoration.get_dom_attribute("x")) == x - (w // 2)
assert int(decoration.get_dom_attribute("y")) == y - (h // 2)
assert int(decoration.get_dom_attribute("width")) == w
assert int(decoration.get_dom_attribute("height")) == h

def get_decorations(self):
style = "purple"
Expand Down
18 changes: 9 additions & 9 deletions tests/test_js_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_insert_vertex_with_style(graph_cases) -> None:
)
default = default.lower()

assert vertex.get_attribute("fill") != default
assert vertex.get_dom_attribute("fill") != default


@pytest.mark.parametrize(
Expand Down Expand Up @@ -304,8 +304,8 @@ def test_toggle_grid(selenium, host, grid, wait_graph_page_ready) -> None:
selenium.execute_script("api.toggleGrid()")

container = selenium.find_element(By.CSS_SELECTOR, "div.graph")
assert container.get_attribute("id") == "graphContainer"
assert container.get_attribute("class") == ("graph" if grid else "graph hide-bg")
assert container.get_dom_attribute("id") == "graphContainer"
assert container.get_dom_attribute("class") == ("graph" if grid else "graph hide-bg")


@pytest.mark.parametrize("snap", [True, False])
Expand Down Expand Up @@ -339,10 +339,10 @@ def expected(v):
result = math.ceil(result / 10.0) * 10
return result

assert int(vertex.get_attribute("width")) == w
assert int(vertex.get_attribute("height")) == h
assert int(vertex.get_attribute("x")) == expected(x)
assert int(vertex.get_attribute("y")) == expected(y)
assert int(vertex.get_dom_attribute("width")) == w
assert int(vertex.get_dom_attribute("height")) == h
assert int(vertex.get_dom_attribute("x")) == expected(x)
assert int(vertex.get_dom_attribute("y")) == expected(y)


def test_get_cell_id_at(graph_cases) -> None:
Expand Down Expand Up @@ -575,7 +575,7 @@ def test_table_with_image(graph_cases) -> None:
image_elements = graph.selenium.find_elements(By.CSS_SELECTOR, ".table-cell-contents img")
assert len(image_elements) == 1
image = image_elements[0]
assert image.get_attribute("src").endswith("some-image-path")
assert image.get_dom_attribute("src").endswith("some-image-path")


def test_update_table(graph_cases) -> None:
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_edge_with_style(port, mode, graph_cases_factory) -> None:
with server.host(port=port.get(), styles=styles) as host:
cases = graph_cases_factory(host)
graph = cases("2v_1e" if mode == "by_code" else "2v_1eDD")
assert graph.get_edge(*graph.get_vertices()).get_attribute("stroke") == "#000000"
assert graph.get_edge(*graph.get_vertices()).get_dom_attribute("stroke") == "#000000"


def test_get_label(graph_cases) -> None:
Expand Down

0 comments on commit f4411d7

Please sign in to comment.