Best Python code snippet using toolium_python
base_case.py
Source:base_case.py
...23 @classmethod24 def tearDownClass(cls):25 """ Quite the browser """26 driver.quit()27 def wait_until_element_clickable(self, locator):28 element = None29 if locator[0] == 'xpath':30 element = wait.until(EC.element_to_be_clickable((By.XPATH, locator[1])))31 elif locator[0] == 'id':32 element = wait.until(EC.element_to_be_clickable((By.ID, locator[1])))33 elif locator[0] == 'name':34 element = wait.until(EC.element_to_be_clickable((By.NAME, locator[1])))35 elif locator[0] == 'CSS Selector':36 element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, locator[1])))37 return element38 def wait_for_element_visibility(self, locator):39 element = None40 if locator[0] == 'xpath':41 element = wait.until(EC.visibility_of_element_located((By.XPATH, locator[1])))42 elif locator[0] == 'id':43 element = wait.until(EC.visibility_of_element_located((By.ID, locator[1])))44 elif locator[0] == 'name':45 element = wait.until(EC.visibility_of_element_located((By.NAME, locator[1])))46 elif locator[0] == 'CSS Selector':47 element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, locator[1])))48 return element49 def Click(self, locator):50 """ Click the specifies element """51 element = self.wait_until_element_clickable(locator)52 element.click()53 def Clear(self, locator):54 """ Click the specifies element """55 element = self.wait_until_element_clickable(locator)56 element.clear()57 def Send(self, locator, txt):58 """ Send the text to the specifies element/field """59 element = self.wait_until_element_clickable(locator)60 element.click()61 element.clear()62 element.send_keys(txt)63 def FilloutFilled(self, locator, txt):64 """ Send the text to the specifies element/field """65 element = self.wait_until_element_clickable(locator)66 element.click()67 element.clear()68 element.send_keys(txt)69 def Select(self, locator, txt):70 """ Send the text to the dropdown field - this will select the specifies item"""71 element = self.wait_until_element_clickable(locator)72 element.send_keys(txt)73 def Open(self, url):74 """ Navigates the current browser window to the specified page. """75 driver.get(url)76 delay = 3 # seconds77 try:78 WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.TAG_NAME, 'h1')))79 except TimeoutError:80 print("Loading took too much time!")81 def Navigate(self, locator):82 """ Navigates the current browser window to the page using the specified menu item. """83 element = self.wait_until_element_clickable(locator)84 element.click()85 delay = 3 # seconds86 try:87 WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.TAG_NAME, 'h1')))88 except TimeoutError:89 print("Loading took too much time!")90 def get_page_source(self):91 wait.until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="myTable_x"]/table/tbody/tr[1]')))92 p_source = driver.page_source...
TFN_Library.py
Source:TFN_Library.py
...13 )14 def visit_url(self, url):15 self.driver.get(url)16 def verify_duplicate_message(self, label):17 message = self.wait_until_element_clickable(label).text18 assert message == 'Duplicate Check: The record already exists.'19 def verify_mandatory_message(self, label):20 message = self.wait_until_element_clickable(label).text21 assert message == 'You might have unsaved changes, are you sure you want to leave?'22 def verify_pop_up_message(self, label):23 message = self.wait_until_element_clickable(label).text24 assert message == "Write the number of TFNs to add and press [ENTER]"25 def send_keyboard_keys(self, label, keys):26 self.driver.execute_script("arguments[0].scrollIntoView();", self.wait_until_element_located(label))27 time.sleep(1)28 self.driver.execute_script("arguments[0].setAttribute('style', 'border:2px solid red; background:pink')",29 self.wait_until_element_located(label))30 time.sleep(1)31 self.wait_until_element_clickable(label).send_keys(keys)32 def send_keyboard_edit_keys(self, label, keys):33 time.sleep(5)34 self.wait_until_element_located(label).clear()35 self.wait_until_element_clickable(label).send_keys(keys)36 def get_text(self, label):37 return self.wait_until_element_located(label).text38 def click_event(self, label):39 self.is_loading_completed()40 self.wait_until_element_clickable(label).click()41 self.is_loading_completed()42 def double_click_using_action_chains(self, label):43 self.wait_until_element_clickable(label)44 action = ActionChains(self.driver)45 action.move_to_element(self.wait_until_element_located(label))46 action.double_click().perform()47 self.is_loading_completed()48 def single_click_using_action_chains(self, label):49 self.wait_until_element_clickable(label)50 action = ActionChains(self.driver)51 action.move_to_element(self.wait_until_element_located(label))52 action.click().perform()53 self.is_loading_completed()54 def auto_search_cross_button(self, label):55 self.wait_until_element_clickable(label)56 self.wait_until_element_located(label).click()57 def auto_search_result_verify(self, label, label1, test):58 self.is_loading_completed()59 self.wait_until_element_clickable(label)60 verify = self.wait_until_element_located(label1).text61 assert str(test).lower() in str(verify).lower()62 def auto_search_no_result(self, label, label1):63 self.wait_until_element_clickable(label)64 verify = self.wait_until_element_located(label1).text65 assert verify == 'No Results Found'66 def file_upload(self, label, filepath):67 self.driver.find_element_by_xpath(label[1]).send_keys(filepath)68 @staticmethod69 def get_random_alpha_numeric_string(size):70 # initializing size of string71 n = size72 # using random.choices()73 # generating random strings74 res = ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase +75 string.digits, k=n))...
base_page.py
Source:base_page.py
...3class BasePage:4 def __init__(self, driver):5 self._driver = driver6 self._wait = WebDriverWait(self._driver, 10)7 def wait_until_element_clickable(self, locator):8 return WebDriverWait(self._driver, 10).until(EC.element_to_be_clickable(locator))9 def wait_until_alert_clickable(self, alert):10 return WebDriverWait(self._driver, 10).until(EC.element_to_be_clickable(alert))11 def wait_until_window_clickable(self, window):12 return WebDriverWait(self._driver, 10).until(EC.element_to_be_clickable(window))13 def click(self, locator):14 element = self.wait_until_element_clickable(locator)15 element.click()16 def select(self, locator):17 element = self.wait_until_element_clickable(locator)18 element.click()19 def switch_to_alert(self, alert):20 alert = self.wait_until_alert_clickable(alert)21 alert.click()22 def get_text(self, element):23 return element.text24 def send_keys(self, locator, value, is_clear=False):25 element = self.wait_until_element_clickable(locator)26 if is_clear:27 element.clear()28 element.send_keys(value)29 def switch_to_window(self, window_after):30 window_after = self._driver.window_handles[1]31 self._driver.switch_to.window(window_after)32 @property33 def title(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!!