Skip to content

Commit

Permalink
fix: Update Selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Oct 13, 2023
1 parent 87037ef commit a5f2581
Show file tree
Hide file tree
Showing 39 changed files with 775 additions and 626 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ codeforlife-portal = {path = ".", editable = true}
cfl-common = {path = "./cfl_common", editable = true}

[dev-packages]
django-selenium-clean = "==0.3.3"
django-selenium-clean = "==1.0.0"
django-test-migrations = "==1.2.0"
responses = "==0.18.0"
selenium = "==3.141.0"
selenium = "==4.9.0"
snapshottest = "==0.6.0"
pytest-django = "==4.5.2"
pytest = "==7.*"
Expand Down
847 changes: 472 additions & 375 deletions Pipfile.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions portal/tests/pageObjects/portal/base_page.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import absolute_import

from builtins import object
import time
from builtins import object

from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains

FADE_TIME = 0.5

Expand Down Expand Up @@ -74,27 +74,27 @@ def on_correct_page(self, pageName):
return self.element_exists_by_id(pageName)

def hover_over_resources_dropdown(self):
resources_dropdown = self.browser.find_element_by_id("teaching_resources_button")
resources_dropdown = self.browser.find_element(By.ID, "teaching_resources_button")
hover = ActionChains(self.browser).move_to_element(resources_dropdown)
hover.perform()

def go_to_rapid_router_resources_page(self):
self.hover_over_resources_dropdown()
self.browser.find_element_by_id("rapid_router_resources_button").click()
self.browser.find_element(By.ID, "rapid_router_resources_button").click()
from .resources_page import ResourcesPage

return ResourcesPage(self.browser)

def go_to_kurono_resources_page(self):
self.hover_over_resources_dropdown()
self.browser.find_element_by_id("kurono_resources_button").click()
self.browser.find_element(By.ID, "kurono_resources_button").click()
from .resources_page import ResourcesPage

return ResourcesPage(self.browser)

def go_to_kurono_teacher_dashboard_page(self):
self.browser.find_element_by_id("games_button").click()
self.browser.find_element_by_id("teacher_kurono_dashboard_button").click()
self.browser.find_element(By.ID, "games_button").click()
self.browser.find_element(By.ID, "teacher_kurono_dashboard_button").click()
from .kurono_teacher_dashboard_page import KuronoTeacherDashboardPage

return KuronoTeacherDashboardPage(self.browser)
Expand All @@ -112,19 +112,19 @@ def is_on_403_forbidden(self):
return self.on_correct_page("403_forbidden")

def was_form_invalid(self, formID, error):
errors = self.browser.find_element_by_id(formID).find_element_by_class_name("errorlist").text
errors = self.browser.find_element(By.ID, formID).find_element(By.CLASS_NAME, "errorlist").text
return error in errors

def is_dialog_showing(self):
time.sleep(FADE_TIME)
return self.browser.find_element_by_id("popup").is_displayed()
return self.browser.find_element(By.ID, "popup").is_displayed()

def confirm_dialog(self):
self.browser.find_element_by_id("confirm_button").click()
self.browser.find_element(By.ID, "confirm_button").click()
time.sleep(FADE_TIME)
return self

def cancel_dialog(self):
self.browser.find_element_by_id("cancel_button").click()
self.browser.find_element(By.ID, "cancel_button").click()
time.sleep(FADE_TIME)
return self
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

from selenium.webdriver.common.by import By

from . import home_page
from .base_page import BasePage

Expand All @@ -10,5 +12,5 @@ def __init__(self, browser):
assert self.on_correct_page("emailVerificationNeeded_page")

def return_to_home_page(self):
self.browser.find_element_by_id("home_button").click()
self.browser.find_element(By.ID, "home_button").click()
return home_page.HomePage(self.browser)
20 changes: 10 additions & 10 deletions portal/tests/pageObjects/portal/game_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ def _dismiss_initial_dialog(self):

def dismiss_dialog(self, button_id):
self.wait_for_element_to_be_clickable((By.ID, button_id))
self.browser.find_element_by_id(button_id).click()
self.browser.find_element(By.ID, button_id).click()
self.wait_for_element_to_be_invisible((By.ID, button_id))

def load_solution(self, workspace_id):
self.browser.find_element_by_id("load_tab").click()
self.browser.find_element(By.ID, "load_tab").click()
selector = "#loadWorkspaceTable tr[value='" + str(workspace_id) + "']"
self.wait_for_element_to_be_clickable((By.CSS_SELECTOR, selector))
self.browser.find_element_by_css_selector(selector).click()
self.browser.find_element_by_id("loadWorkspace").click()
self.browser.find_element(By.CSS_SELECTOR, selector).click()
self.browser.find_element(By.ID, "loadWorkspace").click()
time.sleep(1)
return self

def clear(self):
self.browser.find_element_by_id("clear_tab").click()
self.browser.find_element(By.ID, "clear_tab").click()
return self

def try_again(self):
self.dismiss_dialog("try_again_button")
return self

def step(self):
self.browser.find_element_by_id("step_tab").click()
self.browser.find_element(By.ID, "step_tab").click()
return self

def assert_is_green_light(self, traffic_light_index):
Expand All @@ -56,12 +56,12 @@ def assert_is_red_light(self, traffic_light_index):
self._assert_light_is_on(traffic_light_index, "red")

def _assert_light_is_on(self, traffic_light_index, colour):
image = self.browser.find_element_by_id("trafficLight_%s_%s" % (traffic_light_index, colour))
image = self.browser.find_element(By.ID, "trafficLight_%s_%s" % (traffic_light_index, colour))

assert_that(image.get_attribute("opacity"), equal_to("1"))

def run_program(self, wait_for_element_id="algorithmScore"):
self.browser.find_element_by_id("fast_tab").click()
self.browser.find_element(By.ID, "fast_tab").click()

try:
self.wait_for_element_to_be_clickable((By.ID, wait_for_element_id), 45)
Expand All @@ -84,12 +84,12 @@ def run_program_that_runs_out_of_instructions(self):

def _run_failing_program(self, text):
self.run_program("try_again_button")
error_message = self.browser.find_element_by_id("myModal-lead").text
error_message = self.browser.find_element(By.ID, "myModal-lead").text
assert_that(error_message, contains_string(text))
return self

def _assert_score(self, element_id, score):
route_score = self.browser.find_element_by_id(element_id).text
route_score = self.browser.find_element(By.ID, element_id).text
assert_that(route_score, equal_to(score))
return self

Expand Down
20 changes: 11 additions & 9 deletions portal/tests/pageObjects/portal/home_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .base_page import BasePage


Expand All @@ -9,36 +11,36 @@ def __init__(self, browser):
assert self.on_correct_page("home_page")

def go_to_teacher_login_page(self):
self.browser.find_element_by_id("login_dropdown").click()
self.browser.find_element_by_id("teacher_login_button").click()
self.browser.find_element(By.ID, "login_dropdown").click()
self.browser.find_element(By.ID, "teacher_login_button").click()

from portal.tests.pageObjects.portal.teacher_login_page import TeacherLoginPage

return TeacherLoginPage(self.browser)

def teacher_logout(self):
self.browser.find_element_by_id("logout_menu").click()
self.browser.find_element_by_id("logout_button").click()
self.browser.find_element(By.ID, "logout_menu").click()
self.browser.find_element(By.ID, "logout_button").click()
return HomePage(self.browser)

def go_to_independent_student_login_page(self):
self.browser.find_element_by_id("login_dropdown").click()
self.browser.find_element_by_id("independent_login_button").click()
self.browser.find_element(By.ID, "login_dropdown").click()
self.browser.find_element(By.ID, "independent_login_button").click()

from portal.tests.pageObjects.portal.independent_login_page import IndependentStudentLoginPage

return IndependentStudentLoginPage(self.browser)

def go_to_student_login_page(self):
self.browser.find_element_by_id("login_dropdown").click()
self.browser.find_element_by_id("student_login_button").click()
self.browser.find_element(By.ID, "login_dropdown").click()
self.browser.find_element(By.ID, "student_login_button").click()

from portal.tests.pageObjects.portal.student_login_class_code import StudentLoginClassCodePage

return StudentLoginClassCodePage(self.browser)

def go_to_signup_page(self):
self.browser.find_element_by_id("signup_button").click()
self.browser.find_element(By.ID, "signup_button").click()

import portal.tests.pageObjects.portal.signup_page as signup_page

Expand Down
12 changes: 7 additions & 5 deletions portal/tests/pageObjects/portal/independent_login_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By

from .base_page import BasePage
from .password_reset_page import PasswordResetPage
from .play import dashboard_page
Expand All @@ -19,14 +21,14 @@ def independent_student_login_failure(self, email, password):
return self

def _independent_student_login(self, email, password):
self.browser.find_element_by_id("id_username").send_keys(email)
self.browser.find_element_by_id("id_password").send_keys(password)
self.browser.find_element_by_name("independent_student_login").click()
self.browser.find_element(By.ID, "id_username").send_keys(email)
self.browser.find_element(By.ID, "id_password").send_keys(password)
self.browser.find_element(By.NAME, "independent_student_login").click()

def go_to_indep_forgotten_password_page(self):
self.browser.find_element_by_id("student_forgotten_password_button").click()
self.browser.find_element(By.ID, "student_forgotten_password_button").click()
return PasswordResetPage(self.browser)

def has_login_failed(self, form_id, error):
errors = self.browser.find_element_by_id(form_id).find_element_by_class_name("errorlist").text
errors = self.browser.find_element(By.ID, form_id).find_element(By.CLASS_NAME, "errorlist").text
return error in errors
16 changes: 9 additions & 7 deletions portal/tests/pageObjects/portal/kurono_teacher_dashboard_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .base_page import BasePage


Expand All @@ -12,14 +14,14 @@ def __init__(self, browser):
def create_game(self, class_id):
self._click_add_game_dropdown()

self.browser.find_element_by_id(f"class_{class_id}").click()
self.browser.find_element(By.ID, f"class_{class_id}").click()

return self

def change_game_worksheet(self, worksheet_id):
self._click_change_worksheet_dropdown()

self.browser.find_element_by_id(f"worksheet_{worksheet_id}").click()
self.browser.find_element(By.ID, f"worksheet_{worksheet_id}").click()

self.confirm_dialog()

Expand All @@ -28,20 +30,20 @@ def change_game_worksheet(self, worksheet_id):
def delete_games(self, game_ids):
# Tick checkboxes
for game_id in game_ids:
self.browser.find_element_by_xpath(f"//input[@name='game_ids' and @value='{game_id}']").click()
self.browser.find_element(By.XPATH, f"//input[@name='game_ids' and @value='{game_id}']").click()

# Click delete
self.browser.find_element_by_id("deleteGamesButton").click()
self.browser.find_element(By.ID, "deleteGamesButton").click()

self.confirm_dialog()

return self

def _click_change_worksheet_confirm_button(self):
self.browser.find_element_by_id("confirm_button").click()
self.browser.find_element(By.ID, "confirm_button").click()

def _click_add_game_dropdown(self):
self.browser.find_element_by_id("add_class_dropdown").click()
self.browser.find_element(By.ID, "add_class_dropdown").click()

def _click_change_worksheet_dropdown(self):
self.browser.find_element_by_id("worksheets_dropdown").click()
self.browser.find_element(By.ID, "worksheets_dropdown").click()
17 changes: 9 additions & 8 deletions portal/tests/pageObjects/portal/password_reset_form_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import absolute_import

from .base_page import BasePage

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from .base_page import BasePage


class PasswordResetPage(BasePage):
Expand All @@ -15,7 +16,7 @@ def teacher_reset_password(self, new_password):
self.clear_and_fill("new_password1", new_password)
self.clear_and_fill("new_password2", new_password)

self.browser.find_element_by_id("teacher_update_button").click()
self.browser.find_element(By.ID, "teacher_update_button").click()

self.wait_for_element_by_id("reset_password_done_page")

Expand All @@ -25,7 +26,7 @@ def student_reset_password(self, new_password):
self.clear_and_fill("new_password1", new_password)
self.clear_and_fill("new_password2", new_password)

self.browser.find_element_by_id("student_update_button").click()
self.browser.find_element(By.ID, "student_update_button").click()

self.wait_for_element_by_id("reset_password_done_page")

Expand All @@ -36,14 +37,14 @@ def reset_password_fail(self, new_password):
self.clear_and_fill("new_password2", new_password)

try:
update_button = self.browser.find_element_by_id("teacher_update_button")
update_button = self.browser.find_element(By.ID, "teacher_update_button")
except NoSuchElementException:
update_button = self.browser.find_element_by_id("student_update_button")
update_button = self.browser.find_element(By.ID, "student_update_button")

update_button.click()

return self

def clear_and_fill(self, field, value):
self.browser.find_element_by_id("id_" + field).clear()
self.browser.find_element_by_id("id_" + field).send_keys(value)
self.browser.find_element(By.ID, "id_" + field).clear()
self.browser.find_element(By.ID, "id_" + field).send_keys(value)
8 changes: 5 additions & 3 deletions portal/tests/pageObjects/portal/password_reset_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

from selenium.webdriver.common.by import By

from .base_page import BasePage
from .home_page import HomePage

Expand All @@ -11,13 +13,13 @@ def __init__(self, browser):
assert self.on_correct_page("reset_password_page")

def cancel(self):
self.browser.find_element_by_id("cancel_button").click()
self.browser.find_element(By.ID, "cancel_button").click()
return HomePage(self.browser)

def reset_email_submit(self, email):
self.browser.find_element_by_id("id_email").send_keys(email)
self.browser.find_element(By.ID, "id_email").send_keys(email)

self.wait_for_element_by_id("reset_button")

self.browser.find_element_by_id("reset_button").click()
self.browser.find_element(By.ID, "reset_button").click()
return self
Loading

0 comments on commit a5f2581

Please sign in to comment.