def getURL(driver, url): try: driver.get(url) print success + "Navigated to "+ url + " after " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to load " + url + " after " + ("%s seconds" % (time.time() - start_time)) driver.save_screenshot('screens/getURL-fail.png') return (driver, url)
def getURL(driver, url): try: driver.get(url) print success + "Navigated to " + url + " after " + ( "%s seconds" % (time.time() - start_time)) except: print fail + "Unable to load " + url + " after " + ( "%s seconds" % (time.time() - start_time)) driver.save_screenshot('screens/getURL-fail.png') return (driver, url)
def refresh(driver): try: driver.refresh() time.sleep(1) print success + "Refreshed Browser at " + ("%s seconds" % (time.time() - start_time)) except: print fail +"Unable to Refresh"
def uploadFile(driver, direc, file): try: driver.find_element_by_css_selector('input[type="file"]').send_keys( os.getcwd() + direc + file) print success + "Sent " + str(file) + " to file upload at " + ( "%s seconds" % (time.time() - start_time)) except: print fail + "Unable to upload file"
def refresh(driver): try: driver.refresh() time.sleep(1) print success + "Refreshed Browser at " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to Refresh"
def waitForElementPresent(driver, css_selector, seconds): try: driver.find_element_by_css_selector(css_selector) driver.implicitly_wait(seconds) print success + "Element " + "<" + css_selector + ">" + " present after " + ( "%s seconds" % (time.time() - start_time)) except: print fail + "Unable to locate " + css_selector
def snapshot(driver, image_name): try: time.sleep(5) driver.implicitly_wait(20) driver.save_screenshot('./screens/' + image_name + '.png') print success + "Recorded screenshot " + "'" + image_name + '.png' + "'" + " after " + ( "%s seconds" % (time.time() - start_time)) except: print fail + "Unable to take a screenshot" return (time, driver, image_name)
def quit (driver): try: driver.quit() print "" print colored("Done, without errors.", "green") print "Finished test in " + ("%s seconds" % (time.time() - start_time)) except: print colored("Test Failed. See Errors in log.","red") return driver
def getAll(driver, selector): try: driver.find_element_by_css_selector(selector) driver.execute_script("document.querySelectorAll('" + selector + "')") print success + "Found all <" + selector + ">" + " at " + ("%s seconds" % (time.time() - start_time)) + " using js fallback" print str(selector) except: driver.execute_script("document.querySelectorAll('" + selector + "')") print fail + "Unable to find elements using js fallback" return (driver, selector)
def quit(driver): try: driver.quit() print "" print colored("Done, without errors.", "green") print "Finished test in " + ("%s seconds" % (time.time() - start_time)) except: print colored("Test Failed. See Errors in log.", "red") return driver
def getAll(driver, selector): try: driver.find_element_by_css_selector(selector) driver.execute_script("document.querySelectorAll('" + selector + "')") print success + "Found all <" + selector + ">" + " at " + ( "%s seconds" % (time.time() - start_time)) + " using js fallback" print str(selector) except: driver.execute_script("document.querySelectorAll('" + selector + "')") print fail + "Unable to find elements using js fallback" return (driver, selector)
def waitForElementPresent(driver, css_selector, seconds): try: driver.find_element_by_css_selector(css_selector) driver.implicitly_wait(seconds) print success + "Element " + "<" + css_selector + ">" + " present after " + ( "%s seconds" % (time.time() - start_time)) except: print fail + "Unable to locate " + css_selector driver.save_screenshot('screens/fails/unable-to-locate-' + css_selector + '-in-DOM.png') print fail + "Sent a screenshot to the fails folder in screen/fails" driver.quit()
def quit (driver): try: driver.quit() print "" print colored("Done, without errors.", "green") print "Finished test in " + ("%s seconds" % (time.time() - start_time)) except: print colored("Test Failed. See Errors in log.","red") print str(len(success)) + "assertions Passed" print str(len(fail)) + "assertions Failed" return driver
def quit(driver): try: driver.quit() print "" print colored("Done, without errors.", "green") print "Finished test in " + ("%s seconds" % (time.time() - start_time)) except: print colored("Test Failed. See Errors in log.", "red") print str(len(success)) + "assertions Passed" print str(len(fail)) + "assertions Failed" return driver
def clickRetry(driver, css_selector): try: driver.find_element_by_css_selector(css_selector).click() time.sleep(1) #pause 1 second driver.implicitly_wait(20) print success + "Clicked on <" + css_selector + ">" + " at " + ( "%s seconds" % (time.time() - start_time)) except: driver.find_element_by_css_selector(css_selector).click() print fail + "Unable to locate " + css_selector + " and took screenshot of failure" driver.save_screenshot('screens/clickretry-fail.png') driver.quit() return (driver, css_selector)
def uploadFile(driver,direc,file): try: driver.find_element_by_css_selector('input[type="file"]').send_keys(os.getcwd() + direc + file) print success + "Sent " + str(file) + " to file upload at " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to upload file" driver.save_screenshot('screens/fails/unable-to-upload')
def snapshot(driver, image_name): try: time.sleep(5) driver.implicitly_wait(20) driver.save_screenshot('./screens/' + image_name + '.png') print success + "Recorded screenshot " + "'" + image_name + '.png' + "'" + " after " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to take a screenshot" return (time, driver, image_name)
def clickRetry (driver, css_selector): try: driver.find_element_by_css_selector(css_selector).click() time.sleep(1) #pause 1 second driver.implicitly_wait(20) print success + "Clicked on <" + css_selector + ">" + " at " + ("%s seconds" % (time.time() - start_time)) except: driver.find_element_by_css_selector(css_selector).click() print fail + "Unable to locate " + css_selector + " and took screenshot of failure" driver.save_screenshot('screens/fails/unable-to-click-' + css_selector + '.png') driver.quit() return (driver, css_selector)
def waitForElementPresent(driver, css_selector,seconds): try: driver.find_element_by_css_selector(css_selector) driver.implicitly_wait(seconds) print success + "Element " + "<" + css_selector + ">" + " present after " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to locate " + css_selector driver.save_screenshot('screens/fails/unable-to-locate-' + css_selector + '-in-DOM.png') print fail + "Sent a screenshot to the fails folder in screen/fails" driver.quit()
def waitForElementPresent(driver, css_selector,seconds): try: driver.find_element_by_css_selector(css_selector) driver.implicitly_wait(seconds) print success + "Element " + "<" + css_selector + ">" + " present after " + ("%s seconds" % (time.time() - start_time)) except: print fail + "Unable to locate " + css_selector