Skip to content

Commit

Permalink
Replace deprecated method calls with newer versions
Browse files Browse the repository at this point in the history
These are supported in Selenium 3 but become mandatory in Selenium 4.

Helpful translation table:
SeleniumHQ/selenium#10712 (comment)
  • Loading branch information
evansd committed Dec 5, 2022
1 parent 4b13483 commit 3341481
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
9 changes: 5 additions & 4 deletions openprescribing/frontend/tests/functional/test_charts.py
Expand Up @@ -11,6 +11,7 @@
import unittest

from .selenium_base import SeleniumTestCase
from selenium.webdriver.common.by import By


class MapTest(SeleniumTestCase):
Expand All @@ -29,8 +30,8 @@ def test_map_slider(self):
# In the default month (Sept) there is one "maximum" value
self.assertEqual(
len(
self.browser.find_elements_by_xpath(
"//*[@fill='#67001f' and name()='path']"
self.browser.find_elements(
By.XPATH, "//*[@fill='#67001f' and name()='path']"
)
),
1,
Expand All @@ -53,8 +54,8 @@ def test_map_slider(self):
# Check the values for Gravesend have changed as expected
self.assertEqual(
len(
self.browser.find_elements_by_xpath(
"//*[@fill='#67001f' and name()='path']"
self.browser.find_elements(
By.XPATH, "//*[@fill='#67001f' and name()='path']"
)
),
2,
Expand Down
11 changes: 6 additions & 5 deletions openprescribing/frontend/tests/functional/test_general.py
Expand Up @@ -5,6 +5,7 @@
from mock import patch
from mock import PropertyMock
from .selenium_base import SeleniumTestCase
from selenium.webdriver.common.by import By


class GeneralFrontendTest(SeleniumTestCase):
Expand Down Expand Up @@ -105,7 +106,7 @@ def test_ccg_measures_sorting(self):
)

# Now click to sort by potential savings
self.browser.find_element_by_xpath("//button[@data-orderby='savings']").click()
self.browser.find_element(By.XPATH, "//button[@data-orderby='savings']").click()

# hack: not sure of the correct way to await the element
# being visible.
Expand Down Expand Up @@ -133,14 +134,14 @@ def test_ccg_measures_explore_link(self):
measure = self.find_by_xpath("//div[@id='measure_keppra']")
self.assertIn(
"/measure/keppra",
measure.find_element_by_partial_link_text(
"Compare all Sub-ICB Locations"
measure.find_element(
By.PARTIAL_LINK_TEXT, "Compare all Sub-ICB Locations"
).get_attribute("href"),
)
self.assertIn(
"/sicbl/02Q/keppra",
measure.find_element_by_partial_link_text(
"Split the measure"
measure.find_element(
By.PARTIAL_LINK_TEXT, "Split the measure"
).get_attribute("href"),
)

Expand Down
27 changes: 14 additions & 13 deletions openprescribing/frontend/tests/functional/test_measures.py
Expand Up @@ -16,6 +16,7 @@
from django.core.management import call_command
import requests
from .selenium_base import SeleniumTestCase
from selenium.webdriver.common.by import By

from frontend.models import RegionalTeam, STP, PCT, PCN, Practice, Measure, MeasureValue
from matrixstore.tests.decorators import copy_fixtures_to_matrixstore
Expand Down Expand Up @@ -60,16 +61,16 @@ def _get(self, path):
self.browser.get(url)

def _verify_link(self, base_element, css_selector, exp_text, exp_path):
element = base_element.find_element_by_css_selector(css_selector)
a_element = element.find_element_by_tag_name("a")
element = base_element.find_element(By.CSS_SELECTOR, css_selector)
a_element = element.find_element(By.TAG_NAME, "a")
self.assertEqual(a_element.text, exp_text)
href = _normalize_url(a_element.get_attribute("href"))
expected_href = _normalize_url(self.live_server_url + exp_path)
self.assertEqual(href, expected_href)

def _verify_num_elements(self, base_element, css_selector, exp_num):
self.assertEqual(
len(base_element.find_elements_by_css_selector(css_selector)), exp_num
len(base_element.find_elements(By.CSS_SELECTOR, css_selector)), exp_num
)

def _find_measure_panel(self, id_):
Expand Down Expand Up @@ -1382,13 +1383,13 @@ def test_explanation_for_practice(self):
ccg = p1.ccg
self._get("/sicbl/{}/core_0/".format(ccg.code))
panel_element = self._find_measure_panel("practice_{}".format(p1.code))
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(p1_exp_text, perf_element.text)

# practice_home_page
self._get("/practice/{}/".format(p1.code))
panel_element = self._find_measure_panel("top-measure-container")
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(p1_exp_text, perf_element.text)

def test_explanation_for_pcn(self):
Expand Down Expand Up @@ -1449,13 +1450,13 @@ def test_explanation_for_pcn(self):
# measure_for_all_pcns
self._get("/measure/core_0/pcn/")
panel_element = self._find_measure_panel("pcn_{}".format(p1.code))
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(p1_exp_text, perf_element.text)

# pcn_home_page
self._get("/pcn/{}/".format(p1.code))
panel_element = self._find_measure_panel("top-measure-container")
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(p1_exp_text, perf_element.text)

def test_explanation_for_ccg(self):
Expand Down Expand Up @@ -1516,13 +1517,13 @@ def test_explanation_for_ccg(self):
# measure_for_all_ccgs
self._get("/measure/core_0/")
panel_element = self._find_measure_panel("ccg_{}".format(c1.code))
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(c1_exp_text, perf_element.text)

# ccg_home_page
self._get("/sicbl/{}/".format(c1.code))
panel_element = self._find_measure_panel("top-measure-container")
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(c1_exp_text, perf_element.text)

def test_explanation_for_stp(self):
Expand Down Expand Up @@ -1583,13 +1584,13 @@ def test_explanation_for_stp(self):
# measure_for_all_stps
self._get("/measure/core_0/icb/")
panel_element = self._find_measure_panel("stp_{}".format(s1.code))
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(s1_exp_text, perf_element.text)

# stp_home_page
self._get("/icb/{}/".format(s1.code))
panel_element = self._find_measure_panel("top-measure-container")
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(s1_exp_text, perf_element.text)

def test_explanation_for_regional_team(self):
Expand Down Expand Up @@ -1643,13 +1644,13 @@ def test_explanation_for_regional_team(self):
# measure_for_all_regional_teams
self._get("/measure/core_0/regional-team/")
panel_element = self._find_measure_panel("regional_team_{}".format(r1.code))
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(r1_exp_text, perf_element.text)

# regional_team_home_page
self._get("/regional-team/{}/".format(r1.code))
panel_element = self._find_measure_panel("top-measure-container")
perf_element = panel_element.find_element_by_class_name("explanation")
perf_element = panel_element.find_element(By.CLASS_NAME, "explanation")
self.assertIn(r1_exp_text, perf_element.text)

def test_performance_summary_for_measure_for_all_pcns(self):
Expand Down

0 comments on commit 3341481

Please sign in to comment.