How to use opened_with_body method in Selene

Best Python code snippet using selene_python

error_messages_test.py

Source:error_messages_test.py Github

copy

Full Screen

...22 return [line.strip() if not re.match('\s*screenshot: .*?/\.selene/screenshots/\d+?/screen_\d+\.png\s*',line)23 else 'screenshot: //.selene/screenshots/*/screen_*.png'24 for line in str(ex.value.msg).strip().splitlines()]25def test_selement_search_fails_with_message_when_explicitly_waits_for_condition():26 GIVEN_PAGE.opened_with_body('''27 <label id='element'>Hello world!</label>28 ''')29 config.timeout = 0.130 with pytest.raises(TimeoutException) as ex:31 s('#element').should(have.exact_text('Hello wor'))32 assert exception_message(ex) == \33 ['failed while waiting 0.1 seconds',34 'to assert ExactText',35 "for first_by('css selector', '#element')",36 '',37 'reason: ConditionMismatchException: condition did not match',38 "expected: Hello wor",39 "actual: Hello world!",40 'screenshot: //.selene/screenshots/*/screen_*.png']41def test_selement_search_fails_with_message_when_implicitly_waits_for_condition():42 GIVEN_PAGE.opened_with_body('''43 <button id='hidden-button' style='display:none'>You can't click me, ha ha! :P</button>44 ''')45 config.timeout = 0.146 with pytest.raises(TimeoutException) as ex:47 s('#hidden-button').click()48 assert exception_message(ex) == \49 ['failed while waiting 0.1 seconds',50 'to assert Visible',51 "for first_by('css selector', '#hidden-button')",52 '',53 'reason: ConditionMismatchException: condition did not match',54 'screenshot: //.selene/screenshots/*/screen_*.png']55def test_inner_selement_search_fails_with_message_when_implicitly_waits_for_condition_mismatch_on_inner_element():56 GIVEN_PAGE.opened_with_body('''57 <div id='container'>58 <button id='hidden-button' style='display:none'>You can't click me, ha ha! :P</button>59 </div>60 ''')61 config.timeout = 0.162 with pytest.raises(TimeoutException) as ex:63 s('#container').element('#hidden-button').click()64 assert exception_message(ex) == \65 ['failed while waiting 0.1 seconds',66 'to assert Visible',67 "for first_by('css selector', '#container').find_by('css selector', '#hidden-button')",68 '',69 'reason: ConditionMismatchException: condition did not match',70 'screenshot: //.selene/screenshots/*/screen_*.png']71def test_inner_selement_search_fails_with_message_when_implicitly_waits_for_condition_mismatched_on_parent_element():72 GIVEN_PAGE.opened_with_body('''73 <div id='hidden-container' style='display:none'>74 <button id='button'>You still can't click me, ha ha! :P</button>75 </div>76 ''')77 config.timeout = 0.178 with pytest.raises(TimeoutException) as ex:79 s('#hidden-container').element('#button').click()80 assert exception_message(ex) == \81 ['failed while waiting 0.1 seconds',82 'to assert Visible',83 "for first_by('css selector', '#hidden-container').find_by('css selector', '#button')",84 '',85 'reason: TimeoutException:',86 'failed while waiting 0.1 seconds',87 'to assert Visible',88 "for first_by('css selector', '#hidden-container')",89 '',90 'reason: ConditionMismatchException: condition did not match',91 'screenshot: //.selene/screenshots/*/screen_*.png']92def test_inner_selement_search_fails_with_message_when_implicitly_waits_for_condition_failed_on_parent_element():93 GIVEN_PAGE.opened_with_body('''94 <div>95 <button id='button'>Try to click me</button>96 </div>97 ''')98 config.timeout = 0.199 with pytest.raises(TimeoutException) as ex:100 s('#not-existing').element('#button').click()101 assert exception_message(ex) == \102 ['failed while waiting 0.1 seconds',103 'to assert Visible',104 "for first_by('css selector', '#not-existing').find_by('css selector', '#button')",105 '',106 'reason: TimeoutException:',107 'failed while waiting 0.1 seconds',108 'to assert Visible',109 "for first_by('css selector', '#not-existing')",110 '',111 'reason: NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#not-existing"}',112 'screenshot: //.selene/screenshots/*/screen_*.png']113def test_indexed_selement_search_fails_with_message_when_implicitly_waits_for_condition_failed_on_collection():114 GIVEN_PAGE.opened_with_body('''115 <div>116 <button id='button'>Try to click me</button>117 </div>118 ''')119 config.timeout = 0.1120 with pytest.raises(TimeoutException) as ex:121 ss('button')[1].click()122 assert exception_message(ex) == \123 ['failed while waiting 0.1 seconds',124 'to assert Visible',125 "for all_by('css selector', 'button')[1]",126 '',127 'reason: TimeoutException:',128 'failed while waiting 0.1 seconds',129 'to assert SizeAtLeast',130 "for all_by('css selector', 'button')",131 '',132 'reason: ConditionMismatchException: condition did not match',133 'expected: >= 2',134 'actual: 1',135 'screenshot: //.selene/screenshots/*/screen_*.png']136# todo: uncomment when refactored conditions implementation137# def test_selement_search_fails_with_message_when_explicitly_waits_for_not_condition():138# GIVEN_PAGE.opened_with_body('''139# <label id='element'>Hello world!</label>140# ''')141# config.timeout = 0.1142#143# s('#element').should_not(have.exact_text('Hello world!'))144# with pytest.raises(TimeoutException) as ex:145# s('#element').should_not(have.exact_text('Hello world!'))146#147# assert exception_message(ex) == \148# ['failed while waiting 0.1 seconds',149# 'to assert not ExactText',150# "for first_by('css selector', '#element')",151# '',152# 'reason: ConditionMismatchException: condition did not match',...

Full Screen

Full Screen

selement_waiting_search_on_actions_like_click_test.py

Source:selement_waiting_search_on_actions_like_click_test.py Github

copy

Full Screen

...23def setup_function(fn):24 global original_timeout25def test_waits_for_visibility():26 GIVEN_PAGE\27 .opened_with_body(28 '''29 <a href="#second" style="display:none">go to Heading 2</a>30 <h2 id="second">Heading 2</h2>''')\31 .execute_script_with_timeout(32 'document.getElementsByTagName("a")[0].style = "display:block";',33 500)34 driver.element('a').click()35 assert ("second" in driver.current_url) is True36def test_waits_for_present_in_dom_and_visibility():37 GIVEN_PAGE.opened_with_body(38 '''39 <h2 id="second">Heading 2</h2>''')40 WHEN.load_body_with_timeout(41 '''42 <a href="#second">go to Heading 2</a>43 <h2 id="second">Heading 2</h2>''',44 500)45 driver.element('a').click()46 assert ("second" in driver.current_url) is True47def test_waits_first_for_present_in_dom_then_visibility():48 GIVEN_PAGE.opened_with_body(49 '''50 <h2 id="second">Heading 2</h2>''')51 WHEN.load_body_with_timeout(52 '''53 <a href="#second" style="display:none">go to Heading 2</a>54 <h2 id="second">Heading 2</h2>''',55 250)\56 .execute_script_with_timeout(57 'document.getElementsByTagName("a")[0].style = "display:block";',58 500)59 driver.element('a').click()60 assert ("second" in driver.current_url) is True61# todo: there should be each such test method for each "passing" test from above...62def test_fails_on_timeout_during_waiting_for_visibility():63 config.timeout = 0.2564 GIVEN_PAGE\65 .opened_with_body(66 '''67 <a href='#second' style='display:none'>go to Heading 2</a>68 <h2 id='second'>Heading 2</h2>''')\69 .execute_script_with_timeout(70 'document.getElementsByTagName("a")[0].style = "display:block";',71 500)72 with pytest.raises(TimeoutException):73 driver.element("a").click()...

Full Screen

Full Screen

indexed_selement_waiting_search_on_actions_like_click_test.py

Source:indexed_selement_waiting_search_on_actions_like_click_test.py Github

copy

Full Screen

...23def setup_function(fn):24 global original_timeout25def test_waits_for_visibility():26 GIVEN_PAGE\27 .opened_with_body(28 '''29 <a href="#second" style="display:none">go to Heading 2</a>30 <h2 id="second">Heading 2</h2>''')\31 .execute_script_with_timeout(32 'document.getElementsByTagName("a")[0].style = "display:block";',33 500)34 driver.all('a')[0].click()35 assert ("second" in driver.current_url) is True36def test_waits_for_present_in_dom_and_visibility():37 GIVEN_PAGE.opened_with_body(38 '''39 <h2 id="second">Heading 2</h2>''')40 WHEN.load_body_with_timeout(41 '''42 <a href="#second">go to Heading 2</a>43 <h2 id="second">Heading 2</h2>''',44 500)45 driver.all('a')[0].click()46 assert ("second" in driver.current_url) is True47def test_waits_first_for_present_in_dom_then_visibility():48 GIVEN_PAGE.opened_with_body(49 '''50 <h2 id="second">Heading 2</h2>''')51 WHEN.load_body_with_timeout(52 '''53 <a href="#second" style="display:none">go to Heading 2</a>54 <h2 id="second">Heading 2</h2>''',55 250)\56 .execute_script_with_timeout(57 'document.getElementsByTagName("a")[0].style = "display:block";',58 500)59 driver.all('a')[0].click()60 assert ("second" in driver.current_url) is True61# todo: there should be each such test method for each "passing" test from above...62def test_fails_on_timeout_during_waiting_for_visibility():63 config.timeout = 0.2564 GIVEN_PAGE\65 .opened_with_body(66 '''67 <a href='#second' style='display:none'>go to Heading 2</a>68 <h2 id='second'>Heading 2</h2>''')\69 .execute_script_with_timeout(70 'document.getElementsByTagName("a")[0].style = "display:block";',71 500)72 with pytest.raises(TimeoutException):73 driver.all('a')[0].click()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful