How to use wait_for_element_present method in Robotframework-anywherelibrary

Best Python code snippet using robotframework-anywherelibrary

treehole_page.py

Source:treehole_page.py Github

copy

Full Screen

...11 __bad_content_locator = (By.XPATH, '//a[@class="view_bad"]')12 def __init__(self, driver, parse=True):13 driver.get('http://i.jandan.net/treehole')14 self.url = driver.current_url15 self.current_page_number = int(retain_number(wait_for_element_present(16 driver, self.__current_page_locator).text))17 if parse:18 self.open_bad_content(driver)19 self.post_list = self.parse_post_list(driver)20 print(driver.page_source)21 def parse_post_list(self, driver):22 print("Parsing post list...")23 post_list = []24 post_elements = wait_for_elements_present(driver, self.__post_locator, 'Obtaining posts...')25 for post_element in post_elements:26 post = self.Post(post_element, driver)27 post_list.append(post)28 print(post)29 # self.write_to_json(post_list)30 return post_list31 def go_to_next_page(self, driver, parse=True):32 scroll_to_and_click_button(driver, self.__next_page_locator)33 return TreeholePage(driver, parse)34 def go_to_previous_page(self, driver, parse=True):35 scroll_to_and_click_button(driver, self.__previous_page_locator)36 return TreeholePage(driver, parse)37 def open_bad_content(self, driver):38 try:39 bad_content_elements = wait_for_elements_present(driver, self.__bad_content_locator, timeout=3)40 for bad_content_element in bad_content_elements:41 scroll_to_element(driver, bad_content_element)42 bad_content_element.click()43 except TimeoutException:44 print("No bad content in this page.")45 def __eq__(self, other):46 if isinstance(other, TreeholePage):47 return self.url == other.url48 return False49 def __str__(self):50 return str(self.__dict__)51 def __repr__(self):52 return str(self.__dict__)53 def to_json(self):54 return self.__dict__55 class Post:56 __user_locator = (By.XPATH, './b')57 __time_locator = (By.XPATH, './span[@class="time"]')58 __id_locator = (By.XPATH, './span[@class="righttext"]/a')59 __text_locator = (By.XPATH, './div[@class="commenttext"]/p')60 __oo_locator = (By.XPATH,61 './div[@class="jandan-vote"]//a[@class="comment-like like"]/following-sibling::span')62 __xx_locator = (By.XPATH,63 './div[@class="jandan-vote"]//a[@class="comment-unlike unlike"]/following-sibling::span')64 __comment_count_locator = (By.XPATH, './/a[@class="tucao-btn"]')65 __open_comment_locator = (By.XPATH, './div[@class="jandan-vote"]/a[@class="tucao-btn"]')66 __hot_comment_locator = (By.XPATH, './/div[@class="tucao-hot"]/div[@class="tucao-row"]')67 __comment_locator = (By.XPATH, './/div[@class="tucao-list"]/div[@class="tucao-row"]')68 def __init__(self, post_element, driver):69 self.post_user, self.post_time, self.post_id, self.post_oo, self.post_xx, self.post_text, self.comment_count, self.hot_comment_list, self.comment_list = self.parse_post(70 post_element, driver)71 def parse_post(self, post_element, driver):72 print("Parsing post...")73 post_user = wait_for_element_present(post_element, self.__user_locator).text74 post_time = wait_for_element_present(post_element, self.__time_locator).text.strip()[2:]75 post_id = wait_for_element_present(post_element, self.__id_locator).text76 post_oo = wait_for_element_present(post_element, self.__oo_locator).text77 post_xx = wait_for_element_present(post_element, self.__xx_locator).text78 post_text = ''79 post_text_elements = wait_for_elements_present(post_element, self.__text_locator)80 for post_text_element in post_text_elements:81 post_text += '\n' + post_text_element.text82 comment_list = []83 hot_comment_list = []84 comment_count = self.parse_comment_count(post_element)85 if comment_count != '0':86 self.open_comment_section(post_element, driver)87 print("Parsing comments...")88 comment_elements = wait_for_elements_present(post_element, self.__comment_locator)89 for comment_element in comment_elements:90 comment = self.Comment(comment_element, post_id)91 comment_list.append(comment)92 # list(set(comment_list))93 try:94 print("Parsing hot comments...")95 hot_comment_elements = wait_for_elements_present(post_element, self.__hot_comment_locator,96 timeout=1)97 for hot_comment_element in hot_comment_elements:98 hot_comment = self.Comment(hot_comment_element, post_id, is_hot_comment=True)99 hot_comment_list.append(hot_comment)100 # list(set(hot_comment_list))101 except TimeoutException:102 pass103 return post_user, post_time, post_id, post_oo, post_xx, post_text, comment_count, hot_comment_list, comment_list104 def parse_comment_count(self, post_element):105 comment_count_string = wait_for_element_present(post_element, self.__comment_count_locator).text106 return retain_number(comment_count_string)107 def open_comment_section(self, post_element, driver):108 print("Opening comment section...")109 element = wait_for_element_present(post_element, self.__open_comment_locator)110 scroll_to_element(driver, element)111 element.click()112 # scroll_to_and_click_button(post_element, self.__open_comment_locator)113 def __eq__(self, other):114 if isinstance(other, TreeholePage.Post):115 return self.post_id == other.post_id116 return False117 def __str__(self):118 return str(self.__dict__)119 def __repr__(self):120 return str(self.__dict__)121 def to_json(self):122 return self.__dict__123 class Comment:124 __user_locator = (By.XPATH, './/div[@class="tucao-author"]/span')125 __id_locator = (By.XPATH, './/span[@class="tucao-id"]')126 __text_locator = (By.XPATH, './/div[@class="tucao-content"]')127 __oo_locator = (By.XPATH, './/span[@class="tucao-oo"]')128 __xx_locator = (By.XPATH, './/span[@class="tucao-xx"]')129 def __init__(self, comment_element, post_id, is_hot_comment=False, ):130 self.comment_user, self.comment_id, self.comment_oo, self.comment_xx, self.comment_text = self.parse_comment(131 comment_element)132 self.is_hot_comment = is_hot_comment133 self.post_id = post_id134 def parse_comment(self, comment_element):135 comment_user = wait_for_element_present(comment_element, self.__user_locator).text136 comment_id = wait_for_element_present(comment_element, self.__id_locator).text[1:]137 comment_text = ''138 comment_text_elements = wait_for_elements_present(comment_element, self.__text_locator)139 for comment_text_element in comment_text_elements:140 comment_text += '\n' + comment_text_element.text141 comment_oo = wait_for_element_present(comment_element, self.__oo_locator).text142 comment_xx = wait_for_element_present(comment_element, self.__xx_locator).text143 return comment_user, comment_id, comment_oo, comment_xx, comment_text144 def __eq__(self, other):145 if isinstance(other, TreeholePage.Post.Comment):146 return self.comment_id == other.comment_id147 return False148 def __str__(self):149 return str(self.__dict__)150 def __repr__(self):151 return str(self.__dict__)152 def to_json(self):...

Full Screen

Full Screen

normal_scenarios.py

Source:normal_scenarios.py Github

copy

Full Screen

1from selenium.webdriver.common.by import By2import commons3def scenario_short(user):4 driver = commons.login(user)5 user.wait_for_element_present(By.ID, "start")6 driver.find_element_by_id("logout").click()7 user.log("logout clicked")8def scenario_full(user):9 driver = commons.login(user)10 user.wait_for_element_present(By.ID, "start")11 driver.find_element_by_id("start").click()12 commons.fill_repo_info(driver, user, user.repo)13 user.log("spawn clicked")14 user.wait_for_element_present(By.LINK_TEXT, "Control Panel")15 driver.find_element_by_link_text("Control Panel").click()16 user.wait_for_element_present(By.ID, "stop")17 driver.find_element_by_id("stop").click()18 user.log("stop clicked")19 user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")20 driver.find_element_by_id("logout").click()21 user.log("logout clicked")22def scenario_no_jupyter(user):23 driver = commons.login(user)24 user.wait_for_element_present(By.ID, "start")25 driver.find_element_by_id("start").click()26 commons.fill_repo_info(driver, user, 'docker:busybox')27 user.log("spawn clicked")28 user.wait_for_element_present(By.ID, "resist")29 user.log("correct, no jupyter in container")30 driver.find_element_by_id("resist").click()31 commons.fill_repo_info(driver, user, user.repo)32 user.log("spawn clicked (second try)")33 user.wait_for_element_present(By.LINK_TEXT, "Control Panel")34 driver.find_element_by_link_text("Control Panel").click()35 user.wait_for_element_present(By.ID, "stop")36 driver.find_element_by_id("stop").click()37 user.log("stop clicked")38 user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")39 driver.find_element_by_id("logout").click()40 user.log("logout clicked")41def scenario_timeout(user):42 driver = commons.login(user)43 user.wait_for_element_present(By.ID, "start")44 driver.find_element_by_id("start").click()45 commons.fill_repo_info(driver, user, 'https://github.com/everware/test_long_creation')46 user.log("spawn clicked")47 user.wait_for_element_present(By.ID, "resist")48 user.log('correct, timeout happened')49 driver.find_element_by_id("resist").click()50 user.log("resist clicked")51def scenario_no_dockerfile(user):52 driver = commons.login(user)53 user.wait_for_element_present(By.ID, "start")54 driver.find_element_by_id("start").click()55 commons.fill_repo_info(driver, user, 'https://github.com/everware/runnable_examples')56 user.log("spawn clicked")57 user.wait_for_element_present(By.ID, "resist")58 user.log("correct, no dockerfile")59def scenario_default_dockerfile(user):60 driver = commons.login(user)61 user.wait_for_element_present(By.ID, "start")62 driver.find_element_by_id("start").click()63 commons.fill_repo_info(driver, user, 'https://github.com/everware/runnable_examples')64 user.log("spawn clicked")65 user.wait_for_element_present(By.LINK_TEXT, "Control Panel")66 driver.find_element_by_link_text("Control Panel").click()67 user.wait_for_element_present(By.ID, "stop")68 driver.find_element_by_id("stop").click()69 user.log("stop clicked")70 user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")71 driver.find_element_by_id("logout").click()72 user.log("logout clicked")73def scenario_default_private_repos(user):74 driver = commons.login(user, "a516f02935686c8e782" + "e958e6a627dc3a3b17baa") # seems, github deletes public tokens75 user.wait_for_element_present(By.ID, "start")76 driver.find_element_by_id("start").click()77 commons.fill_repo_info(driver, user, "https://github.com/yandexdataschool/everware_private_test")78 user.log("spawn clicked")79 user.wait_for_element_present(By.LINK_TEXT, "Control Panel")80 driver.find_element_by_link_text("Control Panel").click()81 user.wait_for_element_present(By.ID, "stop")82 driver.find_element_by_id("stop").click()83 user.log("stop clicked")84 user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")85 driver.find_element_by_id("logout").click()86 user.log("logout clicked")87def scenario_r_shiny(user):88 driver = commons.login(user)89 user.wait_for_element_present(By.ID, "start")90 driver.find_element_by_id("start").click()91 commons.fill_repo_info(driver, user, "https://github.com/everware/r-shiny-example")92 user.log("spawn clicked")93 user.wait_for_pattern_in_page("Iris\s+k-means\s+clustering")94def scenario_jupyter_only(user):95 driver = commons.login(user)96 user.wait_for_element_present(By.ID, "start")97 driver.find_element_by_id("start").click()98 commons.fill_repo_info(driver, user, "https://github.com/astiunov/qutip-lectures")99 user.log("spawn clicked")100 user.wait_for_element_present(By.LINK_TEXT, "Control Panel")...

Full Screen

Full Screen

base_page.py

Source:base_page.py Github

copy

Full Screen

...7 def __init__(self):8 self.driver = Driver().get_driver()9 self.locator_type = By.XPATH10 def find_element(self, locator, time_out_sec=10):11 return self.wait_for_element_present(locator, time_out_sec)12 def wait_for_element_present(self, locator, time_out_sec=10):13 element = WebDriverWait(self.driver, time_out_sec).until(14 EC.presence_of_element_located((self.locator_type, locator)))15 return element16 def click(self, locator):17 element = self.find_element(locator)18 element.click()19 def get_text(self, locator):20 element = self.find_element(locator)21 return element.text22 def is_element_present(self, locator):23 try:24 self.find_element(locator)25 return True26 except TimeoutException:27 return False28 def open_url(self, url):29 self.driver.get(url)30 def enter_text(self, locator, text):31 element = self.find_element(locator)32 element.send_keys(text)33 def scroll_to_element_view(self, locator):34 self.wait_for_element_present(locator)35 element = self.driver.find_element(self.locator_type, locator)36 self.driver.execute_script("arguments[0].scrollIntoView();", element)37 def click_with_java_script(self, locator):38 self.wait_for_element_present(locator)39 element = self.driver.find_element(self.locator_type, locator)...

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