示例#1
0
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)
示例#2
0
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)
示例#3
0
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"
示例#4
0
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"
示例#5
0
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"
示例#6
0
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
示例#7
0
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)
示例#8
0
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
示例#9
0
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)
示例#10
0
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
示例#11
0
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)
示例#12
0
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()
示例#13
0
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
示例#14
0
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
示例#15
0
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)
示例#16
0
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')
示例#17
0
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)
示例#18
0
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)
示例#19
0
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()
示例#20
0
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