Skip to content

Commit

Permalink
Update tests using selenium
Browse files Browse the repository at this point in the history
ASIM-5273
  • Loading branch information
prusse-martin committed Nov 9, 2023
1 parent 5cbe5a3 commit fe65f20
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 96 deletions.
61 changes: 28 additions & 33 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By


def pytest_configure(config):
Expand Down Expand Up @@ -216,14 +217,7 @@ def get_exception_message(self, e):
:return: Error messaged extracted from an `WebDriverException`,
raised when errors happen during tests using Selenium.
"""
if self.selenium.name == 'phantomjs':
# PhantomJS driver for whatever reason encodes error message
# in JSON...
import json

return json.loads(e.value.msg)["errorMessage"]
else:
return e.value.msg
return e.value.msg


@pytest.fixture
Expand Down Expand Up @@ -335,7 +329,7 @@ def get_container(self):
:rtype: selenium.webdriver.remote.webelement.WebElement
:return: DIV element containing graph drawing widget.
"""
return self.selenium.find_element_by_id('graphContainer')
return self.selenium.find_element(By.ID, 'graphContainer')

def get_container_size(self):
"""
Expand Down Expand Up @@ -398,8 +392,8 @@ def get(v, attr):
)
color = color.lower()

edge = self.selenium.find_elements_by_css_selector(
'path[stroke="{}"][d~="M"][d~="{}"][d~="{}"]'.format(color, h_right, v_center)
edge = self.selenium.find_elements(
By.CSS_SELECTOR, f'path[stroke="{color}"][d~="M"][d~="{h_right}"][d~="{v_center}"]'
)
assert len(edge) <= 1
return edge[0] if len(edge) == 1 else None
Expand All @@ -415,14 +409,14 @@ def get_label_element(self, cell):
# vertices aren't child to cell drawing node in SVG of mxGraph, they
# actually share a same parent node which contains both cell drawing
# and text at a same level.
common = cell.find_element_by_xpath('../..')
common = cell.find_element(By.XPATH, '../..')
if self.selenium.execute_script('return graphEditor.graph.isHtmlLabel()'):
# If HTML labels are enabled, label is a bit more complicated...
g = common.find_element_by_css_selector('g[style]>g[transform]')
label = g.find_element_by_tag_name('div')
label = label.find_element_by_tag_name('div')
g = common.find_element(By.CSS_SELECTOR, 'g[style]>g[transform]')
label = g.find_element(By.TAG_NAME, 'div')
label = label.find_element(By.TAG_NAME, 'div')
else:
label = common.find_element_by_css_selector('g>g>text')
label = common.find_element(By.CSS_SELECTOR, 'g>g>text')
return label

def get_edge_position(self, edge):
Expand Down Expand Up @@ -511,8 +505,8 @@ def get_table_title(self, table):
:rtype: str
:return: Table title.
"""
title = table.find_element_by_css_selector('table.table-cell-title')
return title.find_element_by_tag_name('tr').text
title = table.find_element(By.CSS_SELECTOR, 'table.table-cell-title')
return title.find_element(By.TAG_NAME, 'tr').text

def get_table_contents(self, table):
"""
Expand All @@ -521,8 +515,8 @@ def get_table_contents(self, table):
:rtype: str
:return: Table contents.
"""
contents = table.find_element_by_css_selector('table.table-cell-contents')
return [i.text for i in contents.find_elements_by_tag_name('td')]
contents = table.find_element(By.CSS_SELECTOR, 'table.table-cell-contents')
return [i.text for i in contents.find_elements(By.TAG_NAME, 'td')]

def select_vertex(self, vertex):
"""
Expand All @@ -537,9 +531,10 @@ 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.
actions.move_to_element_with_offset(
vertex, int(vertex.get_attribute('width')) - 5, int(vertex.get_attribute('height')) - 5
)
x_offset = int(vertex.get_attribute('width')) // 2
y_offset = int(vertex.get_attribute('height')) // 2
assert (x_offset > 0) and (y_offset > 0)
actions.move_to_element_with_offset(vertex, x_offset, y_offset)
actions.click()
actions.perform()

Expand Down Expand Up @@ -658,7 +653,7 @@ def get_vertices(self):
"return graphEditor.graph.getStylesheet().getDefaultVertexStyle()[mxConstants.STYLE_FILLCOLOR]" # noqa
)
color = color.lower()
vertices = self.selenium.find_elements_by_css_selector('g>g>rect[fill="{}"]'.format(color))
vertices = self.selenium.find_elements(By.CSS_SELECTOR, f'g>g>rect[fill="{color}"]')
return vertices

def remove_cells(self, *cell_ids):
Expand Down Expand Up @@ -733,7 +728,7 @@ def get_vertex(self):
# <g> tags);
# * A <text> tag with its label in SVG (which is a grandchild of two
# consecutive <g> tags)
rect = self.selenium.find_elements_by_css_selector('g>g>rect[fill="{}"]'.format(color))
rect = self.selenium.find_elements(By.CSS_SELECTOR, f'g>g>rect[fill="{color}"]')
assert len(rect) <= 1
return rect[0] if rect else None

Expand All @@ -751,8 +746,8 @@ def __init__(self, selenium, host):
)

def get_port(self):
port_elements = self.selenium.find_elements_by_css_selector(
f'g>g>ellipse[fill="{self.port_color}"]'
port_elements = self.selenium.find_elements(
By.CSS_SELECTOR, f'g>g>ellipse[fill="{self.port_color}"]'
)
assert len(port_elements) <= 1
return port_elements[0] if port_elements else None
Expand Down Expand Up @@ -780,7 +775,7 @@ def get_vertex(self):
# <g> tags);
# * A <text> tag with its label in SVG (which is a grandchild of two
# consecutive <g> tags)
rect = self.selenium.find_elements_by_css_selector('g>g>rect[fill="{}"]'.format(color))
rect = self.selenium.find_elements(By.CSS_SELECTOR, f'g>g>rect[fill="{color}"]')
assert len(rect) <= 1
return rect[0] if rect else None

Expand Down Expand Up @@ -860,7 +855,7 @@ def __init__(self, selenium, host):
def get_decorations(self):
style = 'purple'
selector = 'g>g>rect[fill="{}"]'.format(self.host.styles[style]['fill_color'])
decoration = self.selenium.find_elements_by_css_selector(selector)
decoration = self.selenium.find_elements(By.CSS_SELECTOR, selector)
return decoration


Expand Down Expand Up @@ -891,8 +886,8 @@ def __init__(self, selenium, host):
]

def get_tables(self):
titles = self.selenium.find_elements_by_css_selector('div>table.table-cell-title')
return [web_el.find_element_by_xpath('../..') for web_el in titles]
titles = self.selenium.find_elements(By.CSS_SELECTOR, 'div>table.table-cell-title')
return [web_el.find_element(By.XPATH, '../..') for web_el in titles]


class Graph1Table(BaseGraphCase):
Expand Down Expand Up @@ -922,8 +917,8 @@ def __init__(self, selenium, host):
]

def get_tables(self):
titles = self.selenium.find_elements_by_css_selector('div>table.table-cell-title')
return [web_el.find_element_by_xpath('../..') for web_el in titles]
titles = self.selenium.find_elements(By.CSS_SELECTOR, 'div>table.table-cell-title')
return [web_el.find_element(By.XPATH, '../..') for web_el in titles]


def _wait_graph_page_ready(host, selenium):
Expand Down
Loading

0 comments on commit fe65f20

Please sign in to comment.