def test_js_errors(driver): '''Tests assert{,_no}_js_errors().''' # console.log() is not considered an error. with util.assert_no_js_errors(driver): driver.browser.execute_script('console.log("foo");') with util.assert_js_errors(driver, expected_messages=('bar', )): driver.browser.execute_script('console.error("bar");') with util.assert_no_js_errors(driver): # Within an asset_js_error() context manager, messages should not be # bubbled up. with util.assert_js_errors(driver, expected_messages=('baz', )): driver.browser.execute_script('console.error("baz");')
def test_create_group_with_identities_and_restrictions(driver): '''Tests creation of a group with identities.''' group_title = 'unittest_group_%s' % driver.generate_id() description = 'some text for group description' with driver.login_admin(): navbar = driver.wait.until( EC.visibility_of_element_located( (By.CSS_SELECTOR, '.navbar-nav:first-child'))) navbar.find_element_by_css_selector( 'li.nav-problems a.dropdown-toggle').click() problems_dropdown = driver.wait.until( EC.visibility_of( navbar.find_element_by_css_selector( 'li.nav-problems .dropdown-menu'))) # Problems menu for present_href in [ '/problem/collection/', '/submissions/', '/problem/new/' ]: assert problems_dropdown.find_elements_by_css_selector( 'a[href="%s"]' % present_href), ('%s item is not present!' % present_href) # Contests menu assert navbar.find_elements_by_css_selector('li.nav-contests a') group_alias = util.create_group(driver, group_title, description) identity, *_ = util.add_identities_group(driver, group_alias) with driver.login(identity.username, identity.password, is_main_user_identity=False): navbar = driver.wait.until( EC.visibility_of_element_located( (By.CSS_SELECTOR, '.navbar-nav:first-child'))) # Problems menu navbar.find_element_by_css_selector( 'li.nav-problems a.dropdown-toggle').click() problems_dropdown = driver.wait.until( EC.visibility_of( navbar.find_element_by_css_selector( 'li.nav-problems .dropdown-menu'))) for present_href in ['/problem/collection/', '/submissions/']: assert problems_dropdown.find_elements_by_css_selector( 'a[href="%s"]' % present_href), ('%s item is not present!' % present_href) for absent_href in ['/problem/new/']: assert not problems_dropdown.find_elements_by_css_selector( 'a[href="%s"]' % absent_href), ('%s item is visible!' % absent_href) navbar.find_element_by_css_selector( 'li.nav-contests a.dropdown-toggle').click() contests_dropdown = driver.wait.until( EC.visibility_of( navbar.find_element_by_css_selector( 'li.nav-contests .dropdown-menu'))) for present_href in ['/arena/']: assert contests_dropdown.find_elements_by_css_selector( 'a[href="%s"]' % present_href), ('%s item is not present!' % present_href) for absent_href in ['/contest/new/', '/scoreboardmerge/']: assert not contests_dropdown.find_elements_by_css_selector( 'a[href="%s"]' % absent_href), ('%s item is visible!' % absent_href) # Courses list driver.wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, 'a[data-nav-courses]'))).click() with driver.page_transition(): driver.wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, 'a[data-nav-courses-all]'))).click() assert not driver.browser.find_elements_by_css_selector( 'a[href="/course/new/"]') inaccessible_paths = ['/problem/new/', '/contest/new/', '/course/new/'] for inaccessible_path in inaccessible_paths: # Not using assert_js_errors() since this only produces JS errors # with chromedriver, not with saucelabs/Travis. with util.assert_no_js_errors( driver, path_whitelist=(inaccessible_path, )): with driver.page_transition(): driver.browser.get(driver.url(inaccessible_path)) assert_page_not_found_is_shown(driver, inaccessible_path)