E2E Test Utils¶
-
class
semesterly.test_utils.
SeleniumTestCase
(*args, **kwargs)[source]¶ This test case extends the Django StaticLiveServerTestCase. It creates a selenium ChromeDriver instance on setUp of each test. It navigates to the live url for the static live server. It also provides utilities and assertions for navigating and testing presence of elements or behavior.
-
img_dir
¶ str – Directory to save screenshots on failure.
-
driver
¶ WebDriver – Chrome WebDriver instance.
-
timeout
¶ int – Socket default timeout.
-
add_course
(course_idx, n_slots, n_master_slots, by_section='', code=None)[source]¶ Adds a course via search results and asserts the corresponding number of slots are found
Parameters: - course_idx (int) – index into the search results corresponding the to course to add
- n_slots (int) – the number of slots expected after add
- n_master_slots (int) – the number of master slots expected after add
- by_section (str, optional) – if provided adds the specific section of the course
- code (str, optional) – the course code to add, validates presence if provided
-
add_course_from_course_modal
(n_slots, n_master_slots)[source]¶ Adds a course via the course modal action. Requires that the course modal be open.
-
allow_conflicts_add
(n_slots)[source]¶ Allows conflicts via the conflict alert action, then validates that the course was added
-
assert_friend_image_found
(friend)[source]¶ Asserts that the provided friend’s image is found on the page
-
assert_friend_in_modal
(friend)[source]¶ Asserts that the provided friend’s image is found on the modal
-
assert_invisibility
(locator, root=None)[source]¶ Asserts the invisibility of the provided element
Parameters: - locator – A tuple of (By.*, ‘indentifier’)
- root (bool, optional) – The root element to search from, root of DOM if None
-
assert_n_elements_found
(locator, n_elements, root=None)[source]¶ Asserts that n_elements are found by the provided locator
-
assert_ptt_const_across_refresh
()[source]¶ Refreshes the browser and asserts that the tuple version of the personal timetable is equivalent to pre-refresh
-
assert_ptt_equals
(ptt)[source]¶ Asserts equivalency between the provided ptt tuple and the current ptt
-
assert_slot_presence
(n_slots, n_master_slots)[source]¶ Assert n_slots and n_master_slots are on the page
-
change_term
(term, clear_alert=False)[source]¶ Changes the term to the provided term by matching the string to the string found in the semester dropdown on Semester.ly
-
complete_user_settings_basics
(major, class_year)[source]¶ Completes major/class year/TOS agreement via the welcome modal
Parameters:
-
create_friend
(first_name, last_name, **kwargs)[source]¶ Creates a friend of the primary (first) user
-
create_personal_timetable_obj
(friend, courses, semester)[source]¶ Creates a personal timetable object belonging to the provided user with the given courses and semester
-
description
(*args, **kwds)[source]¶ A context manager which wraps a group of code and adds details to any exceptions thrown by the enclosed lines. Upon such an exception, the context manager will also take a screenshot of the current state of self.driver, writing a PNG to self.img_dir, labeled by the provided description and a timetstamp.
-
execute_action_expect_alert
(action, alert_text_contains='')[source]¶ Executes the provided action, asserts that an alert appears and validates that the alert text contains the provided string (when provided)
-
find
(locator, get_all=False, root=None, clickable=False, hidden=False)[source]¶ Locates element in the DOM and returns it when found.
Parameters: - locator – A tuple of (By.*, ‘indentifier’)
- get_all (bool, optional) – If true, will return list of matching elements
- root (bool, optional) – The root element to search from, root of DOM if None
- clickable (bool, optional) – If true, waits for clickability of element
- hidden (bool, optional) – If true, will allow for hidden elements
Returns: The WebElement object returned by self.driver (Selenium)
-
follow_and_validate_url
(url, validate)[source]¶ Opens a new window, switches to it, gets the url and validates it using the provided validating function.
Parameters: - url (str) – the url to follow and validate
- validate (func) – the function which validates the new page
Click the share link on the slot and follow it then validate the course modal
-
get_test_url
(school, path='')[source]¶ Get’s the live server testing url for a given school.
Parameters: Returns: the testing url
-
login_via_fb
(email, password)[source]¶ Login user via fb by clicking continue with Facebook in the signup modal, entering the user’s credentials into Facebook, then returns to Semester.ly
Parameters:
-
login_via_google
(email, password, **kwargs)[source]¶ Mocks the login of a user via Google by clicking continue with Facebook in the signup modal. Then manually creates and logins a user. All kwargs are passed to the user model on creation (e.g. name and email).
Parameters:
-
open_and_query_adv_search
(query, n_results=None)[source]¶ Open’s the advanced search modal and types in the provided query, asserting that n_results are then returned
-
open_course_modal_from_search
(course_idx)[source]¶ Opens course modal from search by search result index
-
remove_course
(course_idx, from_slot=False, n_slots_expected=None)[source]¶ Removes a course from the user’s timetable, asserts master slot is removed.
Parameters:
-
remove_course_from_course_modal
(n_slots_expected=None)[source]¶ Removes course via the action within the course’s course modal. Requires that the course modal be open.
-
save_user_settings
()[source]¶ Saves user setttings by clicking the button, asserts that the modal is then invisible
-
select_nth_adv_search_result
(index, semester)[source]¶ Selects the nth advanced search result with a click. Validates the course modal body displayed in the search reuslts
Clicks the share button via the top bar and validates it. Validation is done by following the url and checking the timetable using the validate_timetable function
-
take_alert_action
()[source]¶ Takes the action provided by the alert by clicking the button on when visible
-
-
semesterly.test_utils.
force_login
(user, driver, base_url)[source]¶ Forces the login of the provided user setting all cookies. Function will refresh the provided drivfer and the user will be logged in to that session.
-
class
semesterly.test_utils.
function_returns_true
(func)[source]¶ An expectation for checking if the provided function returns true
-
class
semesterly.test_utils.
n_elements_to_be_found
(locator, n_)[source]¶ An expectation for checking if the n elements are found locator, text
-
class
semesterly.test_utils.
text_to_be_present_in_element_attribute
(locator, text_, attribute_)[source]¶ An expectation for checking if the given text is present in the element’s locator, text