How to use _is_element_present method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

test_hw_7.py

Source:test_hw_7.py Github

copy

Full Screen

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

Full Screen

Full Screen

product_page.py

Source:product_page.py Github

copy

Full Screen

...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):...

Full Screen

Full Screen

main_page.py

Source:main_page.py Github

copy

Full Screen

...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):...

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 robotframework-appiumlibrary 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