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

Clears the tutorial modal for first time users

click_off()[source]

Clears the focus of the driver

close_course_modal()[source]

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

Parameters
  • 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_ptt(name=None)[source]

Create a personaltimetable with the provided name when provided

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.

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)

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

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 clicking continue with Facebook in the signup modal, entering the user’s credentials into Facebook, then returns to Semester.ly

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

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

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

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

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