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

Directory to save screenshots on failure.

Type

str

driver

Chrome WebDriver instance.

Type

WebDriver

timeout

Socket default timeout.

Type

int

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_loader_completes()[source]

Asserts that the semester.ly page loader has completed

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_ptt_name(name)[source]

Changes personal timetable name to the provided title

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

clear_search_query()[source]

Clears the search box

clear_tutorial()[source]

Clears the tutorial modal for first time users

click_off()[source]

Clears the focus of the driver

Closes the advanced search modal

close_course_modal()[source]

Closes the course modal using the (x) button

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

Parameters
  • major (str) – Student’s major

  • class_year (str) – Student’s class year

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.

enter_search_query(query)[source]

Enters the provided query into the search box

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.

get_elements_as_text(locator)[source]

Gets elements using self.get and represents them as text

get_test_url(school, path='')[source]

Get’s the live server testing url for a given school.

Parameters
  • school (str) – the string for which to create the test url

  • path (str) – the appended path to file or page with trailing /

Returns

the testing url

get_timetable_name()[source]

Gets the personal timetable name

init_screenshot_dir()[source]

Initializes directory to which we store test failure screenshots

lock_course()[source]

Locks the first course on the timetable

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

Parameters
  • email (str) – User’s email

  • password (str) – User’s password

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.

Parameters
  • email (str) – User’s email

  • password (str) – User’s password

Open’s the advanced search modal and types in the provided query, asserting that n_results are then returned

Opens course modal from search by search result index

open_course_modal_from_slot(course_idx)[source]

Opens the course modal from the nth slot

ptt_to_tuple()[source]

Converts personal timetable to a tuple representation

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
  • course_idx (int) – the index of the course for which to remove

  • from_slot (bool, optional) – if provided, removes via slot rather than via a master_slot

  • n_slots_expected (int, optional) – if provided, asserts n slots found after removal

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

search_course(query, n_results)[source]

Searches a course and asserts n_results elements are found

Parameters
  • query (str) – the text to enter into search

  • n_results (int) – the number of results to look for. If 0, will look for no results

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

setUp()[source]

Hook method for setting up the test fixture before exercising it.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

share_timetable(courses)[source]

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

switch_to_ptt(name)[source]

Switches to the personal timetable with matching name

take_alert_action()[source]

Takes the action provided by the alert by clicking the button on when visible

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

validate_course_modal()[source]

Validates the course modal displays proper course data

validate_course_modal_body(course, modal, semester)[source]

Validates the course modal body displays credits, name, code, etc.

validate_timeable(courses)[source]

Validate timetable by checking that for each course provided, a slot exists with that course’s name and course code.

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

class semesterly.test_utils.text_to_be_present_in_nth_element(locator, text_, index_)[source]

An expectation for checking if the given text is present in the nth element’s locator, text

class semesterly.test_utils.url_matches_regex(pattern)[source]

Expected Condition which waits until the browser’s url matches the provided regex