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.


Directory to save screenshots on failure.




Chrome WebDriver instance.




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

  • 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.


Allows conflicts via the conflict alert action, then validates that the course was added


Asserts that the provided friend’s image is found on the page


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

  • locator – A tuple of (By.*, ‘indentifier’)

  • root (bool, optional) – The root element to search from, root of DOM if None


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


Refreshes the browser and asserts that the tuple version of the personal timetable is equivalent to pre-refresh


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


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


Clears the tutorial modal for first time users


Clears the focus of the driver


Closes the course modal using the (x) button

complete_user_settings_basics(major, class_year)[source]

Completes major/class year/TOS agreement via the welcome modal

  • major (str) – Student’s major

  • class_year (str) – Student’s class year

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 a personaltimetable with the provided name when provided


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.


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)

find(locator, get_all=False, root=None, clickable=False, hidden=False)[source]

Locates element in the DOM and returns it when found.

  • 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


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.

  • 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


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.

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

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


the testing url


Initializes directory to which we store test failure screenshots


Locks the first course on the timetable

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

  • email (str) – User’s email

  • password (str) – User’s password

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).

  • 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


Opens the course modal from the nth slot


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.

  • 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


Removes course via the action within the course’s course modal. Requires that the course modal be open.


Saves the user’s current personal timetable and returs a tuple representation


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

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


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.


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


Switches to the personal timetable with matching name


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


Hook method for deconstructing the test fixture after testing it.


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 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