Best Python code snippet using robotframework-appiumlibrary_python
test_hw_7.py
Source:test_hw_7.py
...13 wd = webdriver.Chrome(options=options)14 wd.implicitly_wait(2)15 request.addfinalizer(wd.quit)16 return wd17def _is_element_present(driver, *args):18 try:19 driver.find_element(*args)20 return True21 except NoSuchElementException:22 return False23def test_adminka(driver):24 """25 Test excecutes 3 steps on the admin menu:26 1. Enter admin panel http://localhost/litecart/admin27 2. Navigates to every page accessable from leftbar menu and sub-menu28 3. Check if header with <h1> exists on the page29 """30 wait = WebDriverWait(driver, 6)31 url = 'http://localhost/litecart/admin'32 driver.get(url)33 ### step 1 - login34 username = driver.find_element(By.NAME, 'username')35 password = driver.find_element(By.NAME, 'password')36 submit = driver.find_element(By.NAME, 'login')37 username.send_keys('admin')38 password.send_keys('admin')39 submit.click()40 # verify admin page loaded41 assert 'My Store' in driver.title42 ### step 2 - check every page43 # create list of Menu items44 all_links = driver.find_elements(By.CSS_SELECTOR, '#box-apps-menu li a')45 menu = [link.text for link in all_links]46 for item in menu:47 sel_menu = f"//span[@class='name' and text()='{item}']"48 button = driver.find_element_by_xpath(sel_menu)49 button.click()50 heading = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'h1')))51 #assert _is_element_present(heading) == True52 assert _is_element_present(driver, By.TAG_NAME, 'h1') == True53 print(f"Menu {driver.title} heading --> {heading.text}")54 # check if menu item contains sub-menu55 if _is_element_present(driver, By.CSS_SELECTOR, "li#app-.selected ul"):56 sub_menu = driver.find_elements_by_css_selector('li#app-.selected ul a')57 # list of all submenus items58 sub_menu = [link.text for link in sub_menu]59 for item in range(len(sub_menu)):60 el_sub_menus = driver.find_elements_by_css_selector('li#app-.selected ul a')61 el_sub_menus[item].click()62 heading = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'h1')))63 assert _is_element_present(driver, By.TAG_NAME, 'h1') == True...
product_page.py
Source:product_page.py
...9 def open(self, path):10 self._open_page(path)11 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие кнопки "Add to Cart"')12 def should_be_add_cart_button(self):13 assert self._is_element_present(*Locators.ADD_CART_BUTTON), 'element "Cart Button" is not present'14 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие ÑÐµÐ½Ñ Ñ ÑоваÑа')15 def should_be_product_price(self):16 assert self._is_element_present(*Locators.PRODUCT_PRICE), 'element "Product Price" is not present'17 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие Ð¿Ð¾Ð»Ñ Ð²Ð²Ð¾Ð´Ð° колиÑеÑÑва')18 def should_be_quantity_input(self):19 assert self._is_element_present(*Locators.QUANTITY_INPUT), 'element "Quantity Input" is not present'20 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие Ð½Ð°Ð¸Ð¼ÐµÐ½Ð¾Ð²Ð°Ð½Ð¸Ñ ÑоваÑа')21 def should_be_product_name(self):22 assert self._is_element_present(*Locators.PRODUCT_NAME), 'element "Product Name" is not present'23 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие вкладки "Description"')24 def should_be_description_tab(self):...
main_page.py
Source:main_page.py
...9 def open(self):10 self._open_page()11 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие Ð¿Ð¾Ð»Ñ Ð²Ð²Ð¾Ð´Ð° поиÑкового запÑоÑа')12 def should_be_search_input(self):13 assert self._is_element_present(*Locators.SEARCH_INPUT), 'element "Search Input" is not present'14 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие баннеÑа')15 def should_be_banner_section(self):16 assert self._is_element_present(*Locators.BANNER_SECTION), 'element "Banner Section" is not present'17 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие главного менÑ')18 def should_be_main_menu(self):19 assert self._is_element_present(*Locators.MAIN_MENU), 'element "Main Menu" is not present'20 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸Ñие малой коÑзинÑ')21 def should_be_small_basket(self):22 assert self._is_element_present(*Locators.SMALL_BASKET), 'element "Small Basket" is not present'23 @step('ÐÑовеÑиÑÑ Ð½Ð°Ð»Ð¸ÑÐ¸Ñ Ð»Ð¾Ð³Ð¾Ñипа')24 def should_be_logo(self):...
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!!