Пример #1
0
def open_url(url, value):
    driver = get_driver()
    driver.open(url)
    for _ in range(1200):
        if driver.execute_script('return document.readyState === "complete" && performance.timing.loadEventEnd > 0'):
            break
        sleep(0.1)
Пример #2
0
def take_full_screenshot(save_path):
    driver = get_driver()

    # initiate value
    save_path = save_path + '.png' if save_path[-4::] != '.png' else save_path
    img_li = []  # to store image fragment
    offset = 0  # where to start

    # js to get height
    height = driver.driver.execute_script('return Math.max('
                                          'document.documentElement.clientHeight, window.innerHeight);')

    # js to get the maximum scroll height
    # Ref--> https://stackoverflow.com/questions/17688595/finding-the-maximum-scroll-position-of-a-page
    max_window_height = driver.driver.execute_script('return Math.max('
                                                     'document.body.scrollHeight, '
                                                     'document.body.offsetHeight, '
                                                     'document.documentElement.clientHeight, '
                                                     'document.documentElement.scrollHeight, '
                                                     'document.documentElement.offsetHeight);')

    # looping from top to bottom, append to img list
    # Ref--> https://gist.github.com/fabtho/13e4a2e7cfbfde671b8fa81bbe9359fb
    while offset < max_window_height:
        # Scroll to height
        driver.driver.execute_script(f'window.scrollTo(0, {offset});')
        img = Image.open(BytesIO((driver.driver.get_screenshot_as_png())))
        img_li.append(img)
        offset += height

    # Stitch image into one
    # Set up the full screen frame
    img_frame_height = sum([img_frag.size[1] for img_frag in img_li])
    img_frame = Image.new('RGB', (img_li[0].size[0], img_frame_height))
    offset = 0
    for img_frag in img_li:
        img_frame.paste(img_frag, (0, offset))
        offset += img_frag.size[1]
    img_frame.save(save_path)
    return save_path
Пример #3
0
def get_dom_size():
    return get_driver().driver.execute_script("return document.getElementsByTagName('*').length")
Пример #4
0
def get_dom():
    return get_driver().driver.page_source
Пример #5
0
def get_performance_entities():
    return get_driver().driver.execute_script("return performance.getEntriesByType('resource')")
Пример #6
0
def get_performance_timing():
    return get_driver().execute_script("return performance.timing")
Пример #7
0
def wait_for_visibility(locator):
    get_driver().element(locator).wait_until(be.visible)
Пример #8
0
def assert_text(locator, text):
    css_or_xpath = get_locator_strategy(locator)
    get_driver().element(css_or_xpath).should_have(have.exact_text(text))
Пример #9
0
def type(locator, text):
    css_or_xpath = get_locator_strategy(locator)
    get_driver().element(css_or_xpath).set_value(text)
Пример #10
0
def double_click(locator, value):
    css_or_xpath = get_locator_strategy(locator)
    get_driver().element(css_or_xpath).double_click()
Пример #11
0
def setWindowSize(size, value):
    s = size.split("x")
    get_driver().driver.set_window_size(s[0], s[1])
Пример #12
0
def runScript(locator, text):
    get_driver().execute_script(locator)
Пример #13
0
def mouseOver(locator, text):
    css_or_xpath = get_locator_strategy(locator)
    get_driver().element(css_or_xpath).hover()
Пример #14
0
def close():
    get_driver().quit()
Пример #15
0
def get_current_url():
    return get_driver().driver.current_url
Пример #16
0
def sendKeys(locator, text):
    css_or_xpath = get_locator_strategy(locator)
    get_driver().element(css_or_xpath).send_keys(process_text(text))
Пример #17
0
def get_current_session_id():
    return get_driver().driver.session_id
Пример #18
0
def take_screenshot():
    return get_driver().take_screenshot("tmp", "screen.png")