def test_assert_element_checked(data): actions.navigate(data.env.url+'elements/') actions.assert_element_checked('#selected-checkbox') golem_steps.assert_last_step_message('Assert element #selected-checkbox is checked') with expected_exception(AssertionError, 'element #unselected-checkbox is not checked'): actions.assert_element_checked('#unselected-checkbox') # radio button actions.assert_element_checked('#exampleRadios1') with expected_exception(AssertionError, 'element #exampleRadios2 is not checked'): actions.assert_element_checked('#exampleRadios2')
def test(data): # append error when there are no steps with expected_exception(Exception, 'there is no last step to append error'): actions._append_error('error message', description='error description') # add a step and append an error to it actions._add_step('step message') actions._append_error('error message', description='error description') expected = {'message': 'error message', 'description': 'error description'} assert execution.steps[-1]['error'] == expected # append error when last step already contains an error with expected_exception(Exception, 'last step already contains an error'): actions._append_error('error message', description='error description')
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_title_contains('Elem') golem_steps.assert_last_step_message("Assert page title contains 'Elem'") with expected_exception(AssertionError, "expected title to contain 'incorrect'"): actions.assert_title_contains('incorrect')
def test_assert_response_status_code(data): actions.http_get(data.env.url) actions.assert_response_status_code(data.last_response, 200) golem_steps.assert_last_step_message('Assert response status code is 200') msg = 'expected response status code to be 201 but was 200' with expected_exception(AssertionError, msg): actions.assert_response_status_code(data.last_response, 201)
def test_assert_element_enabled(data): actions.navigate(data.env.url+'elements/') actions.assert_element_enabled('#input-one') golem_steps.assert_last_step_message('Assert element #input-one is enabled') actions.navigate(data.env.url+'disabled-elements/') with expected_exception(AssertionError, 'element #text is not enabled'): actions.assert_element_enabled('#text')
def test(data): actions.navigate(data.env.url + 'special-elements/') actions.assert_element_not_present('#does-not-exist') golem_steps.assert_last_step_message('Assert element is not present') with expected_exception(AssertionError, 'element #double-click-one is present'): actions.assert_element_not_present('#double-click-one')
def test(data): actions.navigate(data.env.url + 'elements/') browser = actions.get_browser() checkbox_not_checked = browser.find('#unselected-checkbox') checkbox_checked = browser.find('#selected-checkbox') radio_not_checked = browser.find('#exampleRadios2') # checkbox not checked actions.verify_element_not_checked(checkbox_not_checked) checkbox_not_checked.check() actions.verify_element_checked(checkbox_not_checked) # checkbox already checked actions.verify_element_checked(checkbox_checked) checkbox_checked.check() actions.verify_element_checked(checkbox_checked) # radio button not checked actions.verify_element_not_checked(radio_not_checked) radio_not_checked.check() actions.verify_element_checked(radio_not_checked) radio_checked = radio_not_checked # radio button already checked radio_checked.check() actions.verify_element_checked(radio_checked) # try to check an element not radio or checkbox msg = 'Element #button-one is not checkbox or radiobutton' with expected_exception(Exception, msg): browser.find('#button-one').check()
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_url_contains('elements') golem_steps.assert_last_step_message("Assert URL contains 'elements'") with expected_exception(AssertionError, "expected URL to contain 'incorrect'"): actions.assert_url_contains('incorrect')
def test_assert_element_has_attribute(data): actions.navigate(data.env.url+'elements/') actions.assert_element_has_attribute('#button-one', 'onclick') golem_steps.assert_last_step_message('Assert element #button-one has attribute onclick') msg = 'element #button-one does not have attribute not-this-one' with expected_exception(AssertionError, msg): actions.assert_element_has_attribute('#button-one', 'not-this-one')
def test(data): actions.navigate(data.env.url+'tabs/') actions.send_keys('#urlInput', '/elements/') actions.click("#goButton") actions.clear_element('#urlInput') actions.send_keys('#urlInput', '/alert/') actions.click("#goButton") actions.switch_to_window_by_index(0) first_title = actions.get_window_title() actions.switch_to_window_by_index(1) second_title = actions.get_window_title() actions.switch_to_window_by_index(2) third_title = actions.get_window_title() actions.switch_to_window_by_index(0) # close third window by title actions.get_browser().close_window_by_title(third_title) actions.verify_amount_of_windows(2) actions.verify_title(first_title) # close first window by title, from the first window actions.get_browser().close_window_by_title(first_title) # second window is now active actions.verify_amount_of_windows(1) actions.verify_title(second_title) # try to close a window that is not present msg = "a window with title 'Incorrect Title' was not found" with expected_exception(Exception, msg): actions.get_browser().close_window_by_title('Incorrect Title')
def test(data): actions.navigate(data.env.url+'dynamic-elements/?delay=3') actions.get_browser().wait_for_element_text_contains('#button-seven', 'New', 5) actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-seven text to contain 'New'" with expected_exception(Exception, msg): actions.get_browser().wait_for_element_text_contains('#button-seven', 'New', 3)
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_element_not_checked('#unselected-checkbox') golem_steps.assert_last_step_message( 'Assert element #unselected-checkbox is not checked') with expected_exception(AssertionError, 'element #selected-checkbox is checked'): actions.assert_element_not_checked('#selected-checkbox')
def test(data): url = data.env.url+'elements/' actions.navigate(url) actions.assert_url(url) golem_steps.assert_last_step_message("Assert URL is '{}'".format(url)) msg = "expected URL to be 'http://incorrect_url' but was '{}'".format(url) with expected_exception(AssertionError, msg): actions.assert_url('http://incorrect_url')
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_title('Web Playground - Elements') golem_steps.assert_last_step_message( "Assert page title is 'Web Playground - Elements'") msg = "expected title to be 'incorrect title' but was 'Web Playground - Elements'" with expected_exception(AssertionError, msg): actions.assert_title('incorrect title')
def test(data): actions.navigate(data.env.url + 'dynamic-elements/?delay=3') actions.get_browser().wait_for_element_present('#button-five', 5) actions.verify_element_present('#button-five') actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "timeout waiting for element #button-five to be present" with expected_exception(Exception, msg): actions.get_browser().wait_for_element_present('#button-five', 3)
def test(data): actions.navigate(data.env.url+'dynamic-elements/?delay=3') actions.wait_for_page_contains_text('<div id="button-five-container">', timeout=5) # wait times out waiting for text to be present in page actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for page to contain '<div id=\"button-five-container\">'" with expected_exception(Exception, msg): actions.wait_for_page_contains_text('<div id="button-five-container">', timeout=3)
def test(data): actions.navigate(data.env.url + 'special-elements/') actions.assert_page_not_contains_text('THIS TEXT IS NOT PRESENT') golem_steps.assert_last_step_message( "Assert 'THIS TEXT IS NOT PRESENT' is not present in the page") msg = "text 'Special Elements' was found in the page" with expected_exception(AssertionError, msg): actions.assert_page_not_contains_text('Special Elements')
def test_assert_cookie_present(data): actions.navigate(data.env.url) cookie = {'name': 'foo', 'value': 'bar'} actions.add_cookie(cookie) actions.assert_cookie_present('foo') assert golem_steps.get_last_step_message() == "Assert that cookie 'foo' exists" with expected_exception(AssertionError, "cookie 'not_exists' was not found"): actions.assert_cookie_present('not_exists')
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_element_text_is_not('#link1', 'incorrect text') golem_steps.assert_last_step_message( "Assert element #link1 text is not 'incorrect text'") msg = "expected element #link1 text to not be 'this is a link to index'" with expected_exception(AssertionError, msg): actions.assert_element_text_is_not('#link1', 'this is a link to index')
def test_assert_element_not_displayed(data): actions.navigate(data.env.url + 'special-elements/') actions.assert_element_not_displayed('#hidden-button') golem_steps.assert_last_step_message( 'Assert element #hidden-button is not displayed') with expected_exception(AssertionError, 'element #double-click-one is displayed'): actions.assert_element_not_displayed('#double-click-one')
def test(data): actions.navigate(data.env.url + 'alert/') with expected_exception(AssertionError, 'an alert was not present'): actions.assert_alert_present() actions.click('#alert-button') actions.assert_alert_present() assert golem_steps.get_last_step_message() == 'Assert an alert is present' actions.dismiss_alert()
def test(data): actions.navigate(data.env.url + 'elements/') actions.assert_element_text_not_contains('#link1', 'not-contained') golem_steps.assert_last_step_message( "Assert element #link1 does not contain text 'not-contained'") msg = "element #link1 text 'this is a link to index' contains text 'this is a link'" with expected_exception(AssertionError, msg): actions.assert_element_text_not_contains('#link1', 'this is a link')
def test_assert_element_has_not_focus(data): actions.navigate(data.env.url + 'elements/') actions.assert_element_has_not_focus('#input-one') golem_steps.assert_last_step_message( 'Assert element #input-one does not have focus') actions.focus_element('#input-one') with expected_exception(AssertionError, 'element #input-one has focus'): actions.assert_element_has_not_focus('#input-one')
def test(data): actions.navigate(data.env.url + 'dynamic-elements/?delay=3') actions.wait_for_element_enabled('#button-three', 10) actions.verify_element_enabled('#button-three') actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-three to be enabled" with expected_exception(Exception, msg): actions.get_browser().wait_for_element_enabled('#button-three', timeout=3)
def test(data): browser = actions.get_browser() browser.navigate(data.env.url + 'dynamic-elements/?delay=3') element = '#button-seven' browser.find(element).wait_text('New Text', timeout=10) actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-seven text to be 'New Text'" with expected_exception(Exception, msg): browser.find(element).wait_text('New Text', 3)
def test(data): actions.navigate(data.env.url + 'dynamic-elements/?delay=3') actions.get_browser().wait_for_element_text_is_not('#button-seven', 'Initial Text', 10) actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-seven text not to be 'Initial Text'" with expected_exception(Exception, msg): actions.get_browser().wait_for_element_text_is_not( '#button-seven', 'Initial Text', 3)
def test(data): actions.navigate(data.env.url+'dynamic-elements/?delay=3') actions.wait_for_element_text_not_contains('#button-seven', 'Initial', 5) msg = "Wait for element #button-seven to not contain text 'Initial'" golem_steps.assert_last_step_message(msg) actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-seven text to not contain 'Initial'" with expected_exception(TimeoutException, msg): actions.wait_for_element_text_not_contains('#button-seven', 'Initial', 3)
def test_assert_element_attribute_is_not(data): actions.navigate(data.env.url + 'elements/') actions.assert_element_attribute_is_not('#button-one', 'id', 'incorrect') expected = "Assert element #button-one attribute id value is not incorrect" golem_steps.assert_last_step_message(expected) msg = "expected element #button-one attribute id value to not be button-one" with expected_exception(AssertionError, msg): actions.assert_element_attribute_is_not('#button-one', 'id', 'button-one')
def test(data): actions.navigate(data.env.url + 'dynamic-elements/?delay=3') actions.wait_for_element_text('#button-seven', 'New Text', 10) golem_steps.assert_last_step_message( "Wait for element #button-seven text to be 'New Text'") actions.navigate(data.env.url + 'dynamic-elements/?delay=5') msg = "Timeout waiting for element #button-seven text to be 'New Text'" with expected_exception(TimeoutException, msg): actions.wait_for_element_text('#button-seven', 'New Text', 3)
def test(data): actions.navigate(data.env.url) actions.add_cookie({'name': 'foo', 'value': 'bar'}) actions.assert_cookie_value('foo', 'bar') assert golem_steps.get_last_step_message( ) == "Assert that cookie 'foo' value is 'bar'" msg = "expected cookie 'foo' value to be 'incorrect' but was 'bar'" with expected_exception(AssertionError, msg): actions.assert_cookie_value('foo', 'incorrect')