How to use find_by_name method in lisa

Best Python code snippet using lisa_python

form_elements.py

Source:form_elements.py Github

copy

Full Screen

...5import time6class FormElementsTest(object):7 def test_fill(self):8 self.browser.fill('query', 'new query')9 value = self.browser.find_by_name('query').value10 self.assertEqual('new query', value)11 def test_fill_element(self):12 self.browser.find_by_name('q').fill('new query')13 time.sleep(1)14 value = self.browser.find_by_name('q').value15 self.assertEqual('new query', value)16 def test_submiting_a_form_and_verifying_page_content(self):17 self.browser.fill('query', 'my name')18 self.browser.find_by_name('send').click()19 self.assertIn('My name is: Master Splinter', self.browser.html)20 def test_can_choose_a_radio_button(self):21 "should provide a way to choose a radio button"22 self.assertFalse(self.browser.find_by_id("gender-m").checked)23 self.browser.choose("gender", "M")24 self.assertTrue(self.browser.find_by_id("gender-m").checked)25 def test_can_find_textarea_by_tag(self):26 "should provide a way to find a textarea by tag_name"27 tag = self.browser.find_by_tag("textarea").first28 self.assertEqual('', tag.value)29 def test_can_find_input_without_type(self):30 "should recognize an input element that doesn't have a `type` attribute"31 tag = self.browser.find_by_css('[name="typeless"]').first32 self.assertEqual('default value', tag.value)33 def test_can_find_button(self):34 "should recognize a button"35 tag = self.browser.find_by_css('.just-a-button').first36 self.assertTrue(hasattr(tag, 'click'))37 def test_can_find_option_by_value(self):38 "should provide a way to find select option by value"39 self.assertEqual("Rio de Janeiro", self.browser.find_option_by_value("rj").text)40 def test_can_get_value_attribute_for_a_option(self):41 "should option have a value attribute"42 self.assertEqual("rj", self.browser.find_option_by_value("rj")["value"])43 def test_can_find_option_by_text(self):44 "should provide a way to find select option by text"45 self.assertEqual("rj", self.browser.find_option_by_text("Rio de Janeiro").value)46 def test_can_select_a_option(self):47 "should provide a way to select a option"48 self.assertFalse(self.browser.find_option_by_value("rj").selected)49 self.browser.select("uf", "rj")50 self.assertTrue(self.browser.find_option_by_value("rj").selected)51 def test_can_select_an_option_in_an_optgroup(self):52 "should provide a way to select an option that is in an optgroup"53 self.assertEqual(self.browser.find_by_name("food").value, "apples")54 self.browser.select("food", "grapes")55 self.assertEqual(self.browser.find_by_name("food").value, "grapes")56 def test_can_select_a_option_via_element(self):57 "should provide a way to select a option via element"58 self.assertFalse(self.browser.find_option_by_value("rj").selected)59 self.browser.find_by_name("uf").select("rj")60 self.assertTrue(self.browser.find_option_by_value("rj").selected)61 def test_can_check_a_checkbox(self):62 "should provide a way to check a radio checkbox"63 self.assertFalse(self.browser.find_by_name("some-check").checked)64 self.browser.check("some-check")65 self.assertTrue(self.browser.find_by_name("some-check").checked)66 def test_check_keeps_checked_if_called_multiple_times(self):67 "should keep a checkbox checked if check() is called multiple times"68 self.assertFalse(self.browser.find_by_name("some-check").checked)69 self.browser.check("some-check")70 self.browser.check("some-check")71 self.assertTrue(self.browser.find_by_name("some-check").checked)72 def test_can_uncheck_a_checkbox(self):73 "should provide a way to uncheck a radio checkbox"74 self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)75 self.browser.uncheck("checked-checkbox")76 self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)77 def test_uncheck_should_keep_unchecked_if_called_multiple_times(self):78 "should keep a checkbox unchecked if uncheck() is called multiple times"79 self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)80 self.browser.uncheck("checked-checkbox")81 self.browser.uncheck("checked-checkbox")82 self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)83 def test_can_fill_text_field_in_form(self):84 "should provide a away to change field value"85 self.browser.fill_form({'query': 'new query'})86 value = self.browser.find_by_name('query').value87 self.assertEqual('new query', value)88 def test_can_fill_password_field_in_form(self):89 "should provide a way to change password value"90 new_password = 'new password'91 self.browser.fill_form({'password': new_password})92 value = self.browser.find_by_name('password').value93 self.assertEqual(new_password, value)94 def test_can_fill_more_than_one_field_in_form(self):95 "should provide a away to change field value"96 self.browser.fill('query', 'my name')97 self.assertFalse(self.browser.find_by_id("gender-m").checked)98 self.assertFalse(self.browser.find_option_by_value("rj").selected)99 self.assertFalse(self.browser.find_by_name("some-check").checked)100 self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)101 self.browser.fill_form({102 'query': 'another new query',103 'description': 'Just another description value in the textarea',104 'gender': 'M',105 'uf': 'rj',106 'some-check': True,107 'checked-checkbox': False108 })109 query_value = self.browser.find_by_name('query').value110 self.assertEqual('another new query', query_value)111 desc_value = self.browser.find_by_name('description').value112 self.assertEqual('Just another description value in the textarea', desc_value)113 self.assertTrue(self.browser.find_by_id("gender-m").checked)114 self.assertTrue(self.browser.find_option_by_value("rj").selected)115 self.assertTrue(self.browser.find_by_name("some-check").checked)116 self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)117 def test_can_fill_tel_text_field(self):118 "should provide a way to change a tel field value"119 new_telephone = '555-0042'120 self.browser.fill_form({'telephone': new_telephone})121 value = self.browser.find_by_name('telephone').value122 self.assertEqual(new_telephone, value)123 def test_can_fill_unknown_text_field(self):124 "should provide a way to change a unknown text field type that isn't specifically defined"125 new_search_keyword = 'foobar'126 self.browser.fill_form({'search_keyword': new_search_keyword})127 value = self.browser.find_by_name('search_keyword').value128 self.assertEqual(new_search_keyword, value)129 def test_can_clear_text_field_content(self):130 self.browser.fill('query', 'random query')131 value = self.browser.find_by_name('query').value132 self.assertEqual('random query', value)133 self.browser.find_by_name('query').clear()134 value = self.browser.find_by_name('query').value135 self.assertFalse(value)136 def test_can_clear_password_field_content(self):137 self.browser.fill('password', '1nF4m310')138 value = self.browser.find_by_name('password').value139 self.assertEqual('1nF4m310', value)140 self.browser.find_by_name('password').clear()141 value = self.browser.find_by_name('password').value142 self.assertFalse(value)143 def test_can_clear_tel_field_content(self):144 self.browser.fill('telephone', '5553743980')145 value = self.browser.find_by_name('telephone').value146 self.assertEqual('5553743980', value)147 self.browser.find_by_name('telephone').clear()148 value = self.browser.find_by_name('telephone').value...

Full Screen

Full Screen

signup.py

Source:signup.py Github

copy

Full Screen

...5@step('I fill in the registration form$')6def i_fill_in_the_registration_form(step):7 def fill_in_reg_form():8 register_form = world.css_find('form#register_form')9 register_form.find_by_name('email').fill('robot+studio@edx.org')10 register_form.find_by_name('password').fill('test')11 register_form.find_by_name('username').fill('robot-studio')12 register_form.find_by_name('name').fill('Robot Studio')13 register_form.find_by_name('terms_of_service').click()14 world.retry_on_exception(fill_in_reg_form)15@step('I press the Create My Account button on the registration form$')16def i_press_the_button_on_the_registration_form(step):17 submit_css = 'form#register_form button#submit'18 world.css_click(submit_css)19@step('I should see an email verification prompt')20def i_should_see_an_email_verification_prompt(step):21 world.css_has_text('h1.page-header', u'Studio Home')22 world.css_has_text('div.msg h3.title', u'We need to verify your email address')23@step(u'I fill in and submit the signin form$')24def i_fill_in_the_signin_form(step):25 def fill_login_form():26 login_form = world.browser.find_by_css('form#login_form')27 login_form.find_by_name('email').fill('robot+studio@edx.org')28 login_form.find_by_name('password').fill('test')29 login_form.find_by_name('submit').click()30 world.retry_on_exception(fill_login_form)31@step(u'I should( not)? see a login error message$')32def i_should_see_a_login_error(step, should_not_see):33 if should_not_see:34 # the login error may be absent or invisible. Check absence first,35 # because css_visible will throw an exception if the element is not present36 if world.is_css_present('div#login_error'):37 assert_false(world.css_visible('div#login_error'))38 else:39 assert_true(world.css_visible('div#login_error'))40@step(u'I fill in and submit the signin form incorrectly$')41def i_goof_in_the_signin_form(step):42 def fill_login_form():43 login_form = world.browser.find_by_css('form#login_form')44 login_form.find_by_name('email').fill('robot+studio@edx.org')45 login_form.find_by_name('password').fill('oops')46 login_form.find_by_name('submit').click()47 world.retry_on_exception(fill_login_form)48@step(u'I edit the password field$')49def i_edit_the_password_field(step):50 password_css = 'form#login_form input#password'51 world.css_fill(password_css, 'test')52@step(u'I submit the signin form$')53def i_submit_the_signin_form(step):54 submit_css = 'form#login_form button#submit'...

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