Best Python code snippet using robotframework-pageobjects_python
tests.py
Source:tests.py
...15# test 216def test_search_item():17 site = page.MainPage(browser)18 site.enter_search_line('usb')19 site.click_search_button()20 assert site.is_search_results_found('usb')212223# test 324def test_search_item_count():25 site = page.MainPage(browser)26 site.enter_search_line('usb')27 site.click_search_button()28 assert site.is_search_results_count() > 0293031# test 432def test_add_item_to_cart():33 site = page.MainPage(browser)34 site.enter_search_line('usb')35 site.click_search_button()36 site.add_item_to_cart()37 sucsess_atention = pytest.driver.find_element_by_class_name('productInfo__texts__message').text38 assert sucsess_atention == 'Zbožà bylo pÅidáno do koÅ¡Ãku'3940# test 541def test_unlogin():42 site = page.MainPage(browser)43 site.login_fill_and_click('putinov.tb@gmail.com', 'skillfactory')44 site.unlogin()45 unlogin = pytest.driver.find_element_by_xpath('//*[@id="lblLogin"]').text46 assert unlogin == 'PÅihlásit'4748# test 649def test_item_card_name():50 site = page.MainPage(browser)51 site.enter_search_line('usb')52 site.click_search_button()53 site.enter_item_card()54 name = site.get_card_name()55 assert name != ''565758# test 759def test_item_card_foto():60 site = page.MainPage(browser)61 site.enter_search_line('usb')62 site.click_search_button()63 site.enter_item_card()64 foto = site.get_main_foto()65 assert foto.get_attribute('src') != ''666768# test 869def test_item_card_fotos():70 site = page.MainPage(browser)71 site.enter_search_line('usb')72 site.click_search_button()73 site.enter_item_card()74 fotos = site.get_fotos()75 for i in range(len(fotos)):76 assert fotos[i].get_attribute('src') != ''777879# test 980def test_item_card_description():81 site = page.MainPage(browser)82 site.enter_search_line('usb')83 site.click_search_button()84 site.enter_item_card()85 desc = site.get_main_info()86 assert desc != ''878889# test 1090def test_item_card_params():91 site = page.MainPage(browser)92 site.enter_search_line('usb')93 site.click_search_button()94 site.enter_item_card()95 param = site.get_params()96 assert param != ''979899# test 11100def test_item_card_cena():101 site = page.MainPage(browser)102 site.enter_search_line('usb')103 site.click_search_button()104 site.enter_item_card()105 cena = site.get_price()106 assert cena != ''107108109# test 12110def test_item_card_recenze():111 site = page.MainPage(browser)112 site.enter_search_line('usb')113 site.click_search_button()114 site.enter_item_card()115 recenz = site.get_recence()116 assert recenz != ''117118119# test 13120def test_item_card_poradna():121 site = page.MainPage(browser)122 site.enter_search_line('usb')123 site.click_search_button()124 site.enter_item_card()125 porad = site.get_poradna()126 assert porad != ''127128129# test 14130def test_item_card_score():131 site = page.MainPage(browser)132 site.enter_search_line('usb')133 site.click_search_button()134 site.enter_item_card()135 score = site.get_score_card().text136 assert score != ''137138139# test 15140def test_item_card_home():141 site = page.MainPage(browser)142 site.enter_search_line('usb')143 site.click_search_button()144 site.enter_item_card()145 info1 = site.get_main_info()146 site.get_poradna()147 site.go_home_card()148 info2 = site.get_main_info()149 assert info1 == info2150151152# test 16153def test_cart_items_price():154 site = page.MainPage(browser)155 site.enter_search_line('usb')156 site.click_search_button()157 site.add_item_to_cart()158 site.enter_cart()159 prices = site.get_single_prices_cart()160 for i in range(len(prices)):161 assert prices[i] != ''162163164# test 17165def test_enter_cart():166 site = page.MainPage(browser)167 site.enter_cart()168 text = pytest.driver.find_element_by_css_selector('div#blocke > div > span').text169 assert text == 'Jsem tak prázdný...'170171172173174# test 18175def test_cart_items_names():176 site = page.MainPage(browser)177 site.enter_search_line('usb')178 site.click_search_button()179 site.add_item_to_cart()180 site.enter_cart()181 names = site.get_single_prices_cart()182 for i in range(len(names)):183 assert names[i] != ''184185186# test 19187def test_cart_sum_price_correct():188 site = page.MainPage(browser)189 site.enter_search_line('usb')190 site.click_search_button()191 site.add_item_to_cart()192 site.enter_cart()193 summ = site.get_sum_price_cart().text194 summ = summ[:-3]195 summ = summ.split(' ')196 summ = summ[0] + summ[1]197 summ =int(summ)198 summ_check = site.get_single_prices_cart()199 for i in range(len(summ_check)):200 summ_check[i] = summ_check[:-3]201 summ_check_m = summ_check[i].split(' ')202 summ_check_m[i] = int(summ_check_m[0] + summ_check_m[1])203 while i in range(len(summ_check_m)):204 summ_check = summ_check_m[i] + summ_check_m[i+1]205 assert summ == summ_check206207208# test 20209def test_cart_exit():210 site = page.MainPage(browser)211 site.enter_search_line('usb')212 site.click_search_button()213 site.enter_item_card()214 before = site.get_card_name().text215 site.enter_cart()216 site.exit_cart()217 after = site.get_card_name().text218 assert before == after219220221222# test 21223def test_cart_delete_item():224 site = page.MainPage(browser)225 site.enter_search_line('usb')226 site.click_search_button()227 site.add_item_to_cart()228 site.enter_cart()229 site.cart_delete_item()230 text = pytest.driver.find_element_by_css_selector('div#blocke > div > span').text231 assert text == 'Jsem tak prázdný...'232233234# test 22235def test_cart_item_countup():236 site = page.MainPage(browser)237 site.enter_search_line('usb')238 site.click_search_button()239 site.add_item_to_cart()240 site.enter_cart()241 before = site.get_cart_item_count()242 site.cart_item_count_up()243 after = site.get_cart_item_count()244 assert before < after245246247# test 23248def test_cart_item_countdown():249 site = page.MainPage(browser)250 site.enter_search_line('usb')251 site.click_search_button()252 site.add_item_to_cart()253 site.enter_cart()254 before = site.get_cart_item_count()255 site.cart_item_count_down()256 after = site.get_cart_item_count()257 assert before > after258259260# test 24261def test_result_filter_max_price():262 site = page.MainPage(browser)263 site.enter_search_line('usb')264 site.click_search_button()265 site.go_to_serch_max_price().click()266 price1 = site.get_serch_prices()[1].text267 price2 = site.get_serch_prices()[2].text268 price1 = int(price1[:-2])269 price2 = int(price2[:-2])270 assert price1 >= price2271272273274275# test 25276def test_result_filter_min_price():277 site = page.MainPage(browser)278 site.enter_search_line('usb')279 site.click_search_button()280 site.go_to_serch_min_price().click()281 price1 = site.get_serch_prices()[1].text282 price2 = site.get_serch_prices()[2].text283 price1 = int(price1[:-2])284 price2 = int(price2[:-2])285 assert price1 <= price2286287288289# test 26290def test_result_filterside_price():291 site = page.MainPage(browser)292 site.enter_search_line('usb')293 site.click_search_button()294 price = site.get_search_sidebar_price()295 assert price != ''296297298# test 27299def test_result_filterside_available():300 site = page.MainPage(browser)301 site.enter_search_line('usb')302 site.click_search_button()303 available = site.get_search_sidebar_available()304 assert available != ''305306307308# test 28309def test_result_filterside_lable():310 site = page.MainPage(browser)311 site.enter_search_line('usb')312 site.click_search_button()313 lable = site.get_search_sidebar_lable()314 assert lable != ''315316317318# test 29319def test_result_filterside_stav():320 site = page.MainPage(browser)321 site.enter_search_line('usb')322 site.click_search_button()323 stav = site.get_search_sidebar_stav()324 assert stav != ''325326327328# test 30329def test_leftside_menu():330 site = page.MainPage(browser)331 menu = site.get_leftside_menu()332 assert menu != ''333334335336# test 31
...
test_result.py
Source:test_result.py
...10 search_page.open_page()11 # Act12 search_page \13 .fill_in_search_field(phrase) \14 .click_search_button()15 # Assert16 assert phrase in result_page.get_title()17 for title_link in result_page.get_all_links_values():18 assert phrase.lower() in title_link.lower()19@pytest.mark.flaky(reruns=3, reruns_delay=2)20def test_more_results_should_be_appeared_after_click_by_button_more_results(browser, screenshot):21 search_page = SearchPage(browser)22 result_page = ResultPage(browser)23 phrase = "Panda"24 # Arrange25 search_page \26 .open_page() \27 .fill_in_search_field(phrase) \28 .click_search_button()29 default_numbers_of_results = len(result_page.get_all_links_values())30 # Act31 result_page.click_more_results_button()32 increased_numbers_of_results = len(result_page.get_all_links_values())33 # Assert34 assert default_numbers_of_results < increased_numbers_of_results, "'More results' button should be appeared more " \35 "results "36@pytest.mark.flaky(reruns=3, reruns_delay=2)37def test_after_click_by_result_link_selected_page_should_be_opened(browser, screenshot):38 search_page = SearchPage(browser)39 result_page = ResultPage(browser)40 phrase = "Panda"41 # Arrange42 search_page \43 .open_page() \44 .fill_in_search_field(phrase) \45 .click_search_button()46 # Act47 link = result_page.get_random_link()48 result_page.click_by_result_link(link)49 # Assert50 link_text = link.text51 title_text = result_page.get_title()52 assert link_text in title_text, "New page should be opened"53@pytest.mark.flaky(reruns=3, reruns_delay=2)54def test_after_search_text_changing_new_phrase_should_be_searched(browser, screenshot):55 search_page = SearchPage(browser)56 result_page = ResultPage(browser)57 phrase = "Panda"58 new_phrase = "Python"59 # Arrange60 search_page \61 .open_page() \62 .fill_in_search_field(phrase) \63 .click_search_button()64 # Act65 result_page \66 .clear_search_input() \67 .fill_in_search_field_new_search_text(new_phrase) \68 .click_search_button()69 # Assert70 assert new_phrase in result_page.get_title(), "New phrase should be searched"71 for title_link in result_page.get_all_links_values():72 assert new_phrase.lower() in title_link.lower(), "Part of new phrase should be contained into title of links"73@pytest.mark.flaky(reruns=3, reruns_delay=2)74def test_image_results_should_be_appeared_after_switching_by_click_reference_images(browser, screenshot):75 search_page = SearchPage(browser)76 result_page = ResultPage(browser)77 phrase = "Panda"78 image_reference = "Images"79 img_attr = "img"80 # Arrange81 search_page \82 .open_page() \83 .fill_in_search_field(phrase) \84 .click_search_button()85 # Act86 result_page.click_to_switch_results_items_by(image_reference)87 # Assert88 list_of_images_attr_names = result_page.get_all_img_attr()89 assert result_page.is_item_bar_active(image_reference) is True, "Images reference should be active"90 for image_attr_name in list_of_images_attr_names:91 assert img_attr in image_attr_name, "Attribute img should be into each links according to image searching"92@pytest.mark.flaky(reruns=3, reruns_delay=2)93def test_video_results_should_be_appeared_after_switching_by_click_reference_videos(browser, screenshot):94 search_page = SearchPage(browser)95 result_page = ResultPage(browser)96 phrase = "Panda"97 videos_reference = "Videos"98 # Arrange99 search_page \100 .open_page() \101 .fill_in_search_field(phrase) \102 .click_search_button()103 # Act104 result_page.click_to_switch_results_items_by(videos_reference)105 # Assert106 assert result_page.is_item_bar_active(videos_reference) is True, "Videos reference should be active"107@pytest.mark.flaky(reruns=3, reruns_delay=2)108def test_news_results_should_be_appeared_after_switching_by_click_reference_news(browser, screenshot):109 search_page = SearchPage(browser)110 result_page = ResultPage(browser)111 phrase = "Panda"112 news_reference = "News"113 # Arrange114 search_page \115 .open_page() \116 .fill_in_search_field(phrase) \117 .click_search_button()118 # Act119 result_page.click_to_switch_results_items_by(news_reference)120 # Assert121 assert result_page.is_item_bar_active(news_reference) is True, "News reference should be active"122@pytest.mark.flaky(reruns=3, reruns_delay=2)123def test_after_click_by_all_regions_dropdown_with_regions_should_be_appeared(browser, screenshot):124 search_page = SearchPage(browser)125 result_page = ResultPage(browser)126 phrase = "Panda"127 region = "Australia"128 # Arrange129 search_page \130 .open_page() \131 .fill_in_search_field(phrase) \132 .click_search_button()133 # Act134 result_page \135 .click_by_all_regions() \136 .select_particular_region(region)137 # Assert138 assert result_page.is_region_selected(region) is True, f"Region: {region} should be selected"139 assert result_page.is_switcher_enabled() is True, "Switcher should be auto enabled, when region is selected"140@pytest.mark.flaky(reruns=3, reruns_delay=2)141def test_links_should_be_opened_in_new_tab_after_changing_settings_open_links_in_new_tab(browser, screenshot):142 search_page = SearchPage(browser)143 result_page = ResultPage(browser)144 phrase = "Panda"145 new_tab_switcher = "Open Links in a New Tab"146 # Arrange147 search_page \148 .open_page() \149 .fill_in_search_field(phrase) \150 .click_search_button()151 # Act152 result_page \153 .click_by_settings() \154 .click_by_switcher(new_tab_switcher)155 # Assert156 random_link = result_page.get_random_link()157 result_page.click_by_result_link(random_link)158 assert len(result_page.driver.window_handles) == 2, "Two tabs should be opened"159@pytest.mark.flaky(reruns=3, reruns_delay=2)160def test_scrolling_should_be_infinite_by_autoloading_results_after_changing_settings_infinite_scroll(browser,161 screenshot):162 search_page = SearchPage(browser)163 result_page = ResultPage(browser)164 phrase = "Panda"165 infinite_scroll_switcher = "Infinite Scroll"166 # Arrange167 search_page \168 .open_page() \169 .fill_in_search_field(phrase) \170 .click_search_button()171 amount_of_links_before_changes = len(result_page.get_all_links())172 # Act173 result_page \174 .click_by_settings() \175 .click_by_switcher(infinite_scroll_switcher)176 # Assert177 amount_of_links_after_changes = len(result_page.do_scrolling_down().get_all_links())...
test_search.py
Source:test_search.py
...4 ÐÑедваÑиÑелÑнÑе ÑÑловиÑ5 ÐодгоÑовиÑÑ Ð´Ð°Ð½Ð½Ñе Ð´Ð»Ñ Ð¿Ð¾Ð¸Ñка6 """7 app.open_main_page()8 app.main.click_search_button()9 app.main.click_prpr_ata()10 app.refresh_page()11 app.open_main_page()12 prod = app.main.get_prod1_title()13 assert prod != None14 def test_valid_item(self, app):15 """16 s01p17 1) пеÑеÑ
одим на ÑÑÑаниÑÑ Ð¼Ð°Ð³Ð°Ð·Ð¸Ð½Ð°18 2) вводим Ð½Ð°Ð¸Ð¼ÐµÐ½Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¸Ð¼ÐµÑÑегоÑÑ ÑоваÑа19 3) нажимаем ÐºÐ½Ð¾Ð¿ÐºÑ Search20 4) наÑ
одим на ÑÑÑаниÑе ÑезÑлÑÑаÑов поиÑка иÑкомÑй ÑоваÑ21 """22 app.open_main_page()23 prod = app.main.get_prod1_title()24 app.main.fill_bar_filler(prod)25 app.main.click_search_button()26 search_result_item = app.main.get_prod1_title()27 assert search_result_item == prod28 def test_invalid_item(self, app):29 """30 s02n31 ÐоиÑк неÑÑÑеÑÑвÑÑÑего Ð½Ð°Ð¸Ð¼ÐµÐ½Ð¾Ð²Ð°Ð½Ð¸Ñ ÑоваÑа32 1) пеÑеÑ
одим на ÑÑÑаниÑÑ Ð¼Ð°Ð³Ð°Ð·Ð¸Ð½Ð°33 2) вводим Ð½Ð°Ð¸Ð¼ÐµÐ½Ð¾Ð²Ð°Ð½Ð¸Ñ Ð½ÐµÑÑÑеÑÑвÑÑÑего ÑоваÑа34 3) нажимаем ÐºÐ½Ð¾Ð¿ÐºÑ Search35 4) наÑ
одим на ÑÑÑаниÑе ÑезÑлÑÑаÑов ÑекÑÑ36 Ñ ÑообÑением Nothing here, see github37 """38 app.open_main_page()39 title = app.main.get_invalid_prod_title()40 app.main.fill_bar_filler(title)41 app.main.click_search_button()42 error_message = app.main.get_negative_search_result()43 error_ref = app.main.error_ref()44 assert error_message == error_ref45 def test_empty_item(self, app):46 """47 s03n48 ÐоиÑк неÑÑÑеÑÑвÑÑÑего Ð½Ð°Ð¸Ð¼ÐµÐ½Ð¾Ð²Ð°Ð½Ð¸Ñ ÑоваÑа49 1) пеÑеÑ
одим на ÑÑÑаниÑÑ Ð¼Ð°Ð³Ð°Ð·Ð¸Ð½Ð°50 2) нажимаем ÐºÐ½Ð¾Ð¿ÐºÑ Search51 3) наÑ
одим на ÑÑÑаниÑе ÑезÑлÑÑаÑов ÑекÑÑ52 Ñ ÑообÑением Nothing here, see github53 """54 app.open_main_page()55 app.main.click_search_button()56 error_message = app.main.get_negative_search_result()57 error_ref = app.main.error_ref()...
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!!