class ExplicitWaitTypes(): def __init__(self, driver): self.driver = driver self.hw = HandyWrappers(driver) def waitForElement(self, locator, locatorType="id", timeout=10, pool_Frequency=0.5): element = None try: byType = self.hw.getByType(locatorType) print("Waiting for maximum :: " + str(timeout) + " :: seconds for element to be clickable") wait = WebDriverWait(self.driver, 10, poll_frequency=1, ignored_exceptions=[ NoSuchElementException, ElementNotVisibleException, ElementNotSelectableException ]) element = wait.until(EC.element_to_be_clickable((byType, ""))) print("Element appeared on the web page") except: print("Element not appeared on the web page") print_stack() return element
def waitForElement(self, locator, locatorType="id", timeout=10): element = None try: hw = HandyWrappers(self.driver) locatorType = hw.getByType(locatorType) print("Espera maxima de:: " + str(timeout) + ":: segundos para que el elemento sea usable") element = WebDriverWait( self.driver, timeout, poll_frequency=1, ignored_exceptions=[ NoSuchElementException ]).until(lambda driver: self.driver.find_element( locatorType, locator)) print("Elemento aparecio en la pagina web") except: print("Elemento aparecio no en la pagina web") return element
def Login(self, driver=None, user='', passwd="", element={}): self.takeS = 0 self.observations = 'without observations' self.results = '' self.valueL = '' self.locator = '' fieldnames = [ 'user', 'password', 'results', 'Number of screenshots', 'observations' ] driver.maximize_window() hw = HandyWrappers(driver) if len(element) < 0: self.locator = By.XPATH self.valueL = "//input[@type='text']" else: self.locator = hw.getByType(element['locator']) self.valueL = element['valueL'] driver.implicitly_wait(3) self.takescreenshot(driver, namescren='TestStartLogin', directory="ScreenshotsPruebaLogin/") self.takeS += 1 # --------------------------------------------------------------------------------------------------------------- A = driver.find_elements(self.locator, self.valueL) if len(A) > 1: for element in A: try: element.send_keys(user) except: pass elif len(A) == 1: A[0].send_keys(user) else: print("element " + self.valueL + " not found, process finished") self.results = "AuthenticationFail" self.observations = "element " + self.valueL + " not found, process finished" data = [{ 'user': user, 'password': passwd, 'results': self.results, 'Number of screenshots': self.takeS, 'observations': self.observations }] self.createCVS(fieldnames, data, name=self.results) return B = driver.find_elements(By.XPATH, "//input[@type='password']") if len(B) > 1: for element in B: try: element.send_keys(passwd) except: pass elif len(B) == 1: B[0].send_keys(passwd) else: print("element for put password not found, process finished") self.results = "AuthenticationFail" self.observations = "element for put password not found, process finished" data = [{ 'user': user, 'password': passwd, 'results': self.results, 'Number of screenshots': self.takeS, 'observations': self.observations }] self.createCVS(fieldnames, data, name=self.results) return self.takescreenshot(driver, namescren="FillFields", directory="ScreenshotsPruebaLogin/") self.takeS += 1 C = driver.find_elements(By.XPATH, "//*[@type='submit']") if len(C) > 1: for element in C: try: element.click() except: pass elif len(C) == 1: C[0].click() else: print("button to start session up not found, process finished") self.results = "AuthenticationFail" self.observations = "Button to start session not found, process finished" data = [{ 'user': user, 'password': passwd, 'results': self.results, 'Number of screenshots': self.takeS, 'observations': self.observations }] self.createCVS(fieldnames, data, name=self.results) return time.sleep(3) print("validating authentication") V1 = hw.elementPresenceCheck(locator=self.valueL, byType=self.locator) V2 = hw.elementPresenceCheck(locator="//input[@type='password']", byType=By.XPATH) V3 = hw.elementPresenceCheck(locator="//*[@type='password']", byType=By.XPATH) if V1 and V2 and V3: self.takescreenshot(driver, namescren="AuthenticationFail", directory="ScreenshotsPruebaLogin/") self.takeS += 1 self.results = "AuthenticationFail" else: self.takescreenshot(driver, namescren="AuthenticationSuccessful", directory="ScreenshotsPruebaLogin/") self.takeS += 1 self.results = "AuthenticationSuccessful" data = [{ 'user': user, 'password': passwd, 'results': self.results, 'Number of screenshots': self.takeS, 'observations': self.observations }] self.createCVS(fieldnames, data, name=self.results)