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.
- driver¶
Chrome WebDriver instance.
- Type
WebDriver
- 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_custom_event_exists(*, name: str, day: Optional[str] = None, location: Optional[str] = None, color: Optional[str] = None, start_time: Optional[str] = None, end_time: Optional[str] = None, credits: Optional[float] = None)[source]¶
Asserts that a custom event with the provided fields exists in the current timetable.
- Parameters
name – Name of the event, can be substring of the actual name
day – Day of the week, one of “M”, “T”, “W”, “R”, “F”, “S”, “U”
location – Location of the event, can be substring of the actual name
color – Color of the event in hex (#F8F6F7), case insensitive
start_time – Start time of the event as a non zero-padded string (8:00)
end_time – End time of the event as a non zero-padded string (14:30)
credits – Number of credits of the event
- Raises
RuntimeError – If the event could not be found.
- 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
- compare_timetable(timetable_name: str)[source]¶
Activates the compare timetable mode with a timetable of the given name.
- Parameters
timetable_name – Name of the timetable to compare to, must already exist.
- Pre-condition:
The timetable dropdown is not clicked.
- complete_user_settings_basics(major, class_year)[source]¶
Completes major/class year/TOS agreement via the welcome modal
- create_custom_event(day: int, start_time: int, end_time: int, show_weekend: bool = True)[source]¶
Creates a custom event using drag and drop assuming custom event mode is off
- Parameters
day – 0-6, 0 is Monday
start_time – 0 is 8:00A.M, every 1 is 30 mins
end_time – 0 is 8:00A.M, every 1 is 30 mins
show_weekend – if weekends are shown
- 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
- create_ptt(name: str = '', finish_saving: bool = True)[source]¶
Create a personaltimetable with the provided name when provided
- Parameters
name – Name of the personal timetable
finish_saving – Whether to wait until the personal timetable is saved
- description(descr)[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.
- edit_custom_event(old_name: str, /, *, name: Optional[str] = None, day: Optional[str] = None, location: Optional[str] = None, color: Optional[str] = None, start_time: Optional[str] = None, end_time: Optional[str] = None, credits: Optional[float] = None)[source]¶
Edits the first custom event found with the provided name.
- Parameters
old_name – The name of the event to edit.
name – The new name to give the event.
day – The new day of the week, one of “M”, “T”, “W”, “R”, “F”, “S”, “U”.
location – The new location.
color – The new color as a hex code (#FF0000).
start_time – The new start time in military time (8:00).
end_time – The new end time in military time (13:00).
credits – The new number of credits.
- 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)
- exit_compare_timetable()[source]¶
Exits the compare timetable mode (pre: already in compare timetable mode)
- find(locator, get_all=False, root=None, clickable=False, hidden=False) → WebElement | list[WebElement][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)
- Throws:
RuntimeError: If element is not found or both get_all and clickable is True
- 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_custom_event_fields()[source]¶
Returns the fields of the currently selected custom event.
- Pre-condition:
Custom event modal is open.
- login_via_fb(email, password)[source]¶
Login user via fb by detecting the Continue with Facebook button in the signup modal, and then mocking user’s credentials
- login_via_google(email, password)[source]¶
Mocks the login of a user via Google by detecting the Continue with Google button in the signup modal, and then mocking the user’s credentials.
- 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.
- 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
- classmethod setUpClass()[source]¶
Hook method for setting up class fixture before running tests in the class.
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