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 create_problem(driver, problem_alias): '''Create a problem.''' with driver.login_admin(): driver.wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, 'a[data-nav-problems]'))).click() with driver.page_transition(): driver.wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, 'a[data-nav-problems-create]'))).click() with util.assert_js_errors( driver, expected_messages=('/api/problem/details/', )): driver.wait.until( EC.visibility_of_element_located( (By.XPATH, '//input[@name = "alias"]'))).send_keys(problem_alias) driver.wait.until( EC.visibility_of_element_located( (By.XPATH, '//input[@name = "title"]'))).send_keys(problem_alias) input_limit = driver.wait.until( EC.visibility_of_element_located( (By.XPATH, '//input[@name = "input_limit"]'))) input_limit.clear() input_limit.send_keys('1024') # Alias should be set automatically driver.browser.find_element_by_name('source').send_keys('test') # Make the problem public driver.browser.find_element_by_xpath( '//input[@type = "radio" and @name = "visibility" and @value = ' '"true"]').click() contents_element = driver.browser.find_element_by_name( 'problem_contents') contents_element.send_keys( os.path.join(util.OMEGAUP_ROOT, 'frontend/tests/resources/triangulos.zip')) with driver.page_transition(wait_for_ajax=False): contents_element.submit() assert (('/problem/%s/edit/' % problem_alias) in driver.browser.current_url), driver.browser.current_url