Best Python code snippet using robotframework-pageobjects_python
keywords.py
Source:keywords.py
...3bi = BuiltIn()4sl = BuiltIn().get_library_instance("SeleniumLibrary")5def goto_login_form():6 sl.click_link('css=div.telef > a')7 sl.location_should_be('http://obod.com.ua/login.html')8 sl.element_should_contain('css=#content > span',9 'РегиÑÑÑаÑиÑ/ÐÑ
од в 1 клик')10 sl.element_should_contain('css=form > div > div > p',11 'ÐойÑи в ÐиÑнÑй ÐабинеÑ')12def next_and_check_log_on_invalid():13 sl.click_element('css=div.right > form > div > button')14 sl.location_should_be('http://obod.com.ua/login.html')15 sl.element_should_contain('css=#container > div.warning',16 'ÐепÑавилÑно Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ñ Ð¿Ð¾Ð»Ñ E-Mail и/или паÑолÑ!')17def goto_registration_form():18 sl.click_link('css=div.telef > a')19 sl.location_should_be('http://obod.com.ua/login.html')20 sl.element_should_contain('css=#content > span',21 'РегиÑÑÑаÑиÑ/ÐÑ
од в 1 клик')22 sl.element_should_contain('css=p:nth-child(1) > b',23 'РегиÑÑÑаÑиÑ')24 sl.click_element('css=div.left > div > a')25 sl.location_should_be('http://obod.com.ua/index.php?route=account/simpleregister')26 sl.element_should_contain('css=#content > h1',27 'ÐÑÑÑÑÐ°Ñ ÑегиÑÑÑаÑиÑ')28def next_and_check_reg_on_invalid():29 sl.click_element('css=#simpleregister > div > div > a > span')30 sl.location_should_be('http://obod.com.ua/index.php?route=account/simpleregister')31 sl.element_should_contain('css=#content > h1',32 'ÐÑÑÑÑÐ°Ñ ÑегиÑÑÑаÑиÑ')33 sl.element_should_contain('css=tr:nth-child(1) > td.simplecheckout-customer-right > span',34 'ÐÑибка в адÑеÑе ÑлекÑÑонной поÑÑÑ')35 sl.element_should_contain('css=tr:nth-child(2) > td.simplecheckout-customer-right > span',36 'РпаÑоле должно бÑÑÑ Ð¾Ñ 4 до 20 Ñимволов!')37 sl.element_should_contain('css=tr:nth-child(3) > td.simplecheckout-customer-right > span',38 'ÐÐ¼Ñ Ð´Ð¾Ð»Ð¶Ð½Ð¾ бÑÑÑ Ð¾Ñ 1 до 30 Ñимволов')39 sl.element_should_contain('css=tr:nth-child(4) > td.simplecheckout-customer-right > span',40 'ТелеÑон должен бÑÑÑ Ð² ÑоÑмаÑе +38(0xx)xxx-xx-xx')41def valid_login_and_check(email, password):42 sl.input_text('css=input[type=text]:nth-child(3)', email)43 sl.input_password('css= input[type=password]:nth-child(5)', password)44 sl.click_element('css=form >div > button')45 sl.location_should_be('http://obod.com.ua/index.php?route=account/tmdaccount')46 sl.element_should_contain('css=div.column3 > span.zag3', 'Ðой ÐккаÑнÑ')47def enter_password_only(valid_login_password):48 sl.input_password('css= input[type=password]:nth-child(5)',49 valid_login_password)50def enter_email_only(valid_login_email):51 sl.input_password('css=input[type=text]:nth-child(3)',52 valid_login_email)53def enter_valid_email_and_invalid_password(valid_login_email,54 invalid_login_password):55 sl.input_text('css=input[type=text]:nth-child(3)',56 valid_login_email)57 sl.input_password('css= input[type=password]:nth-child(5)',58 invalid_login_password)59def enter_invalid_email_and_valid_password(invalid_login_email,60 valid_login_password):61 sl.input_text('css=input[type=text]:nth-child(3)',62 invalid_login_email)63 sl.input_password('css= input[type=password]:nth-child(5)',64 valid_login_password)65def replacement_email_and_password(valid_login_email,66 valid_login_password):67 sl.input_text('css=input[type=text]:nth-child(3)',68 valid_login_password)69 sl.input_password('css= input[type=password]:nth-child(5)',70 valid_login_email)71def login_with_system_code_on_email(valid_login_password):72 sl.input_text('css=input[type=text]:nth-child(3)',73 '<script>alert</script>')74 sl.input_password('css= input[type=password]:nth-child(5)',75 valid_login_password)76def check_if_login_fields_are_saved(valid_login_email,77 valid_login_password):78 sl.input_text('css=input[type=text]:nth-child(3)',79 valid_login_email)80 sl.input_password('css=input[type=password]:nth-child(5)',81 valid_login_password)82 sl.go_back()83 sl.location_should_be('http://obod.com.ua/velomagazin-hmelnickiy.html')84 sl.element_should_contain('css=#content > h1',85 'Ðеломагазин ХмелÑниÑкий')86 sl.click_link('css=div.telef > a')87 sl.location_should_be('http://obod.com.ua/login.html')88 sl.element_should_contain('css=#content > span',89 'РегиÑÑÑаÑиÑ/ÐÑ
од в 1 клик')90 sl.element_should_contain('css=form > div > div > p',91 'ÐойÑи в ÐиÑнÑй ÐабинеÑ')92def registration_new_user(reg_valid_password,93 reg_valid_name,94 reg_valid_tel):95 reg_email_random_and_valid = 'test-obod' + str(random.randint(100, 999)) + '@mailintator.com'96 sl.input_text('css=#registration_main_email',97 reg_email_random_and_valid)98 sl.input_password('css= input[type=password]',99 reg_valid_password)100 sl.input_text('css=#registration_main_firstname',101 reg_valid_name)102 sl.press_keys('css=#registration_main_telephone',103 reg_valid_tel)104 sl.click_element('css=#simpleregister > div > div > a > span')105 sl.location_should_be('http://obod.com.ua/index.php?route=account/tmdaccount')106 sl.element_should_contain('css=div.column3 > span.zag3',107 'Ðой ÐккаÑнÑ')108def registration_user_with_only_spaces_in_field():109 sl.input_text('css=#registration_main_email',110 ' ')111 sl.input_password('css= input[type=password]',112 ' ')113 sl.input_text('css=#registration_main_firstname',114 ' ')115 sl.press_keys('css=#registration_main_telephone', ' ')116def registration_user_with_spaces_and_valid_data_in_field(reg_valid_password,117 reg_valid_name,118 reg_valid_tel):119 spcs_reg_email_random_and_valid = ' test-obod' + str(random.randint(100, 999)) + '@mailintator.com '120 spcs_password = ' ' + reg_valid_password + ' '121 spcs_name = ' ' + reg_valid_name + ' '122 spcs_telephone = ' ' + reg_valid_tel + ' '123 sl.input_text('css=#registration_main_email',124 spcs_reg_email_random_and_valid)125 sl.input_text('css= input[type=password]',126 spcs_password)127 sl.input_text('css=#registration_main_firstname',128 spcs_name)129 sl.press_keys('css=#registration_main_telephone',130 spcs_telephone)131 sl.click_element('css=#simpleregister > div > div > a > span')132 sl.location_should_be('http://obod.com.ua/index.php?route=account/tmdaccount')133 sl.element_should_contain('css=div.column3 > span.zag3',134 'Ðой ÐккаÑнÑ')135def check_if_registration_fields_are_saved(reg_valid_password,136 reg_valid_name,137 reg_valid_tel):138 reg_email_random_and_valid = 'test-obod' + str(random.randint(100, 999)) + '@mailintator.com'139 sl.input_text('css=#registration_main_email',140 reg_email_random_and_valid)141 sl.input_text('css= input[type=password]',142 reg_valid_password)143 sl.input_text('css=#registration_main_firstname',144 reg_valid_name)145 sl.press_keys('css=#registration_main_telephone',146 reg_valid_tel)147 sl.go_back()148 sl.element_should_contain('css=#content > span',149 'РегиÑÑÑаÑиÑ/ÐÑ
од в 1 клик')150 sl.location_should_be('http://obod.com.ua/login.html')151 sl.element_should_contain('css=p:nth-child(1) > b',152 'РегиÑÑÑаÑиÑ')153 sl.click_link('css=div.left > div > a')154 sl.location_should_be('http://obod.com.ua/index.php?route=account/simpleregister')155 sl.element_should_contain('css=#content > h1', 'ÐÑÑÑÑÐ°Ñ ÑегиÑÑÑаÑиÑ')156def go_to_shop_bicycle_parts_page():157 sl.click_element('css=li.mega-menu-mixed.main-menu-item-3 > a > span')158 sl.location_should_be('http://obod.com.ua/zapchasti')159 sl.element_should_contain('css=#content > h1',160 'ÐелозапÑаÑÑи, ÐапÑаÑÑи на ÐелоÑипед')161def go_to_shop_accessories_page():162 sl.click_element('css=li.mega-menu-mixed.main-menu-item-4 > a')163 sl.wait_until_location_is_not('http://obod.com.ua/velomagazin-hmelnickiy.html')164 sl.location_should_be('http://obod.com.ua/aksessuary')165 sl.element_should_contain('css=#content > h1',166 'ÐкÑеÑÑÑаÑÑ Ð´Ð»Ñ ÐелоÑипеда')167def buy_first_place_on_shop():168 sl.click_element('css=div:nth-child(1) > div > div.product-details > div.cart > a')169def go_to_cart_page_with_product():170 sl.wait_until_element_is_enabled('css=body > div.ui-pnotify', '7')171 sl.click_element('css=body > div.ui-pnotify > div > div.ui-pnotify-text > div > a')172def add_product_like_first():173 sl.click_element('css=td.quantity > img:nth-child(3)')174 sl.textfield_value_should_be('css=td.quantity > input[type=text]', '2')175def check_on_two_position_in_cart():176 sl.element_should_be_visible('css=#simplecheckout_cart > table > tbody > tr:nth-child(1)')177 sl.element_should_be_visible('css=#simplecheckout_cart > table > tbody > tr:nth-child(2)')178def delete_first_place_in_cart():...
CommonSteps.py
Source:CommonSteps.py
...49def step_impl(context, seconds):50 sleep(float(seconds))51@when("Client profile has loaded")52def step_impl(context):53 context.driver.location_should_be(PROFILE_URL)54 context.driver.find_by_id('firstName')55@step('Element with ID "{html_id}" should have value "{expected_value}"')56def step_impl(context, html_id, expected_value):57 actual_value = context.driver.find_by_id(html_id).get_attribute('value')58 assert_that(actual_value, equal_to(expected_value))59@step('Element with name "{html_name}" should have value "{expected_value}"')60def step_impl(context, html_name, expected_value):61 actual_value = context.driver.find_by_name(html_name).get_attribute('value')62 assert_that(actual_value, equal_to(expected_value))63@then("User is on Edit Appointment page")64def step_impl(context):65 context.driver.location_should_be(EDIT_APPOINTMENT_URL)66@then('Edit appointment dialog shows message "{expected_message}"')67def step_impl(context, expected_message):68 context.driver.find_by_name('edit-appointment-dialog')69 actual_message = context.driver.find_by_name('edit-appointment-dialog-msg').text70 assert_that(actual_message, equal_to(expected_message))71@when('User sets text for element with ID "{html_id}" to "{text}"')72def step_impl(context, html_id, text):73 context.driver.set_text_of_el_with_id(html_id, text)74@when('User sets text for element with name "{html_name}" to "{text}"')75def step_impl(context, html_name, text):76 context.driver.set_text_of_el_with_name(html_name, text)77@step(78 'Staff member enters user registration data "{first_name}" "{surname}" "{username}" "{email}" "{address1}" '79 '"{address2}" "{city}" "{province}" "{postal_code}"')80def step_impl(context, first_name, surname, username, email, address1, address2, city, province, postal_code):81 # Confirm on user registration page82 context.driver.location_should_be(REGISTER_URL)83 # Fill in form84 context.driver.set_text_of_el_with_name('first-name', first_name)85 context.driver.set_text_of_el_with_name('surname', surname)86 context.driver.set_text_of_el_with_name('username', username)87 context.driver.set_text_of_el_with_name('email', email)88 context.driver.set_text_of_el_with_name('address', address1)89 context.driver.set_text_of_el_with_name('address2', address2)90 context.driver.set_text_of_el_with_name('city', city)91 context.driver.set_text_of_el_with_name('postal-code', postal_code)92 # Make selection on province dropdown93 province_el = context.driver.find_by_name('province')94 context.driver.set_dropdown_selection(province_el, province)95 # Submit form96 context.driver.find_by_name('register-btn').click()97@step("Staff member is on User Registration page")98def step_impl(context):99 context.driver.open(REGISTER_URL)100 context.driver.location_should_be(REGISTER_URL)101@step("Login fields have loaded")102def step_impl(context):103 context.driver.location_should_be(LOGIN_URL)...
driver_assertion.py
Source:driver_assertion.py
1from logigear.core import browserManagementKeywords2class DriverAssertion():3 4 def location_should_be(self, url, message=None):5 browserManagementKeywords.location_should_be(url, message)6 7 def location_should_contain(self, expected, message=None):8 browserManagementKeywords.location_should_contain(expected, message)9 10 def title_should_be(self, title, message=None):11 browserManagementKeywords.title_should_be(title, message)12 ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!