Exemplo n.º 1
0
    def test_has_a_backwards_compatible_function(self):
        mock_healthcheck()
        mock_snapshot()

        percySnapshot(browser=self.driver, name='Snapshot')

        self.assertEqual(httpretty.last_request().path, '/percy/snapshot')

        s1 = httpretty.latest_requests()[2].parsed_body
        self.assertEqual(s1['name'], 'Snapshot')
        self.assertEqual(s1['url'], 'http://localhost:8000/')
        self.assertEqual(s1['dom_snapshot'], '<html><head></head><body>Snapshot Me</body></html>')
Exemplo n.º 2
0
def test_output(browser: Chrome, enable_percy=False):
    """测试输出::

        run template.basic_output()
        template.background_output() # 或者 await template.coro_background_output()
        hold()

    """
    time.sleep(1)  # 等待输出完毕

    # get focus
    browser.find_element_by_tag_name('body').click()
    time.sleep(1)

    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(0.5)
    enable_percy and percySnapshot(browser=browser, name='begin output')

    tab_btns = browser.find_elements_by_css_selector(
        '#pywebio-scope-table_cell_buttons button')
    for btn in tab_btns:
        time.sleep(0.5)
        browser.execute_script("arguments[0].click();", btn)

    btns = browser.find_elements_by_css_selector(
        '#pywebio-scope-put_buttons button')
    for btn in btns:
        time.sleep(0.5)
        browser.execute_script("arguments[0].click();", btn)

    # 滚动窗口
    btns = browser.find_elements_by_css_selector(
        '#pywebio-scope-scroll_basis_btns button')
    for btn in btns:
        time.sleep(1)
        browser.execute_script("arguments[0].click();", btn)

    time.sleep(1)
    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(0.5)
    enable_percy and percySnapshot(browser=browser, name='basic output')

    # popup
    btn = browser.find_element_by_css_selector(
        '#pywebio-scope-popup_btn button')
    browser.execute_script("arguments[0].click();", btn)

    time.sleep(1)
    enable_percy and percySnapshot(browser=browser, name='popup')

    browser.execute_script("$('.modal').modal('hide');")
Exemplo n.º 3
0
def test(server_proc: subprocess.Popen, browser: Chrome):
    time.sleep(2)
    percySnapshot(browser=browser, name='misc output')

    coro_out = template.save_output(browser)[-1]

    # browser.get('http://localhost:8080/?app=thread')
    browser.execute_script(
        "arguments[0].click();",
        browser.find_element_by_css_selector('#pywebio-scope-go_app button'))
    time.sleep(2)

    thread_out = template.save_output(browser)[-1]

    assert "ToastClicked" in coro_out
    assert coro_out == thread_out

    browser.execute_script(
        "arguments[0].click();",
        browser.find_element_by_css_selector('#pywebio-scope-error button'))
    browser.execute_script("$('button[type=submit]').click();")
    time.sleep(2)
Exemplo n.º 4
0
def runTests(browser):
    browserName = browser.capabilities.get('browserName')
    browser.get('https://sdk-test.percy.dev')
    browser.implicitly_wait(10)
    browser.find_element_by_class_name("note")

    percySnapshot(browser=browser, name=browserName + ' Snapshots HTTPS, CSP, HSTS sites')

    percySnapshot(
        browser=browser,
        name=browserName + ' With options', widths=[666],
        minHeight=1500,
        percyCSS=".note { background-color: purple; }"
    )

    browser.get('https://sdk-test.percy.dev/redirects')
    browser.implicitly_wait(10)
    browser.find_element_by_class_name("note")

    percySnapshot(browser=browser, name=browserName + ' Snapshots redirected assets')

    browser.quit()
Exemplo n.º 5
0
 def test_contact_view(self):
     self.selenium.get(f'{self.live_server_url}/contact')
     self.selenium.implicitly_wait(1.5)
     percySnapshot(browser=self.selenium,
                   name='contact',
                   widths=PERCY_BS_WIDTHS)
Exemplo n.º 6
0
 def test_about_view(self):
     self.selenium.get(f'{self.live_server_url}/about')
     percySnapshot(browser=self.selenium,
                   name='about',
                   widths=PERCY_BS_WIDTHS)
Exemplo n.º 7
0
 def test_landing_view(self):
     self.selenium.get(self.live_server_url)
     percySnapshot(browser=self.selenium,
                   name='homepage',
                   widths=PERCY_BS_WIDTHS)
Exemplo n.º 8
0
def test_input(browser: Chrome, enable_percy=False):
    """测试输入::

        run template.basic_input()
        actions(['Continue'])
        template.background_input() # 或者 await template.coro_background_input() / flask_coro_background_input

    """
    browser.find_element_by_css_selector('input').send_keys("22")
    browser.find_element_by_tag_name('form').submit()

    time.sleep(0.5)
    browser.find_element_by_css_selector('input').send_keys("secret")
    browser.find_element_by_tag_name('form').submit()

    time.sleep(0.5)
    browser.find_element_by_tag_name('form').submit()

    # checkbox
    time.sleep(0.5)
    browser.execute_script("arguments[0].click();",
                           browser.find_element_by_css_selector('input'))
    browser.find_element_by_tag_name('form').submit()

    # Text Area
    time.sleep(0.5)
    browser.find_element_by_css_selector('textarea').send_keys(" ".join(
        str(i) for i in range(20)))
    browser.find_element_by_tag_name('form').submit()

    # file
    time.sleep(0.5)
    img_path = path.join(here_dir, 'assets', 'img.png')
    browser.find_element_by_css_selector('input').send_keys(img_path)
    browser.find_element_by_tag_name('form').submit()

    # text
    time.sleep(0.5)
    browser.find_element_by_css_selector('input').send_keys("text")
    browser.find_element_by_tag_name('form').submit()

    # 表单取消
    time.sleep(0.5)
    browser.execute_script(
        "arguments[0].click();",
        browser.find_element_by_css_selector('.pywebio_cancel_btn'))

    # valid func, age in [10, 60]
    time.sleep(0.5)
    browser.find_element_by_css_selector('input').send_keys("1")
    browser.find_element_by_tag_name('form').submit()
    time.sleep(0.5)
    browser.find_element_by_css_selector('input').clear()
    browser.find_element_by_css_selector('input').send_keys("90")
    browser.find_element_by_tag_name('form').submit()
    time.sleep(0.5)
    browser.find_element_by_css_selector('input').clear()
    browser.find_element_by_css_selector('input').send_keys("23")
    browser.find_element_by_tag_name('form').submit()

    # code
    time.sleep(0.5)
    # browser.find_element_by_css_selector('textarea').send_keys(" ".join(str(i) for i in range(20)))
    browser.find_element_by_tag_name('form').submit()

    # Cancelable from group
    time.sleep(0.5)
    browser.find_element_by_name('name').send_keys("name")
    time.sleep(1)
    browser.find_element_by_name('age').send_keys("90")
    browser.find_element_by_tag_name('form').submit()
    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(0.5)
    enable_percy and percySnapshot(browser=browser, name='input group invalid')

    time.sleep(0.5)
    browser.find_element_by_name('age').clear()
    browser.find_element_by_name('age').send_keys("23")
    browser.find_element_by_tag_name('form').submit()

    # callback actions
    time.sleep(0.5)
    browser.execute_script(
        "arguments[0].click();",
        browser.find_element_by_css_selector('form button[type="button"]'))
    time.sleep(0.4)

    # input action
    time.sleep(0.5)
    browser.execute_script(
        "arguments[0].click();",
        browser.find_element_by_css_selector('form button[type="button"]'))
    time.sleep(0.4)
    browser.find_element_by_tag_name('form').submit()

    # Input group
    time.sleep(0.5)
    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(0.5)
    enable_percy and percySnapshot(browser=browser, name='input group all')
    browser.find_element_by_name('text').send_keys("name")
    browser.find_element_by_name('number').send_keys("20")
    browser.find_element_by_name('float').send_keys("3.1415")
    browser.find_element_by_name('password').send_keys("password")
    browser.find_element_by_name('textarea').send_keys(" ".join(
        str(i) for i in range(20)))
    # browser.find_element_by_css_selector('[name="code"]').send_keys(" ".join(str(i) for i in range(10)))
    Select(browser.find_element_by_name('select-multiple')).select_by_index(0)
    # browser. find_element_by_css_selector('[name="select"]'). send_keys("name")
    # browser. find_element_by_css_selector('[name="checkbox-inline"]'). send_keys("name")
    # browser. find_element_by_css_selector('[name="checkbox"]'). send_keys("name")
    # browser. find_element_by_css_selector('[name="radio-inline"]'). send_keys("name")
    # browser. find_element_by_css_selector('[name="radio"]'). send_keys("name")
    browser.find_element_by_name('file_upload').send_keys(
        path.join(here_dir, 'assets', 'helloworld.txt'))

    browser.execute_script("$('form button').eq(1).click()")
    time.sleep(1)
    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(0.5)
    enable_percy and percySnapshot(browser=browser,
                                   name='input group all invalid')

    browser.find_element_by_name('password').clear()
    browser.find_element_by_name('password').send_keys("123")
    browser.execute_script("$('form button').eq(1).click()")
    time.sleep(1)
    browser.execute_script(
        '$("html, body").scrollTop( $(document).height()+100);')
    time.sleep(1)
    enable_percy and percySnapshot(browser=browser,
                                   name='input group all submit')

    browser.find_element_by_css_selector('form').submit()

    # background
    time.sleep(3)
    get_visible_form(browser).find_element_by_css_selector('input').send_keys(
        "background")
    get_visible_form(browser).find_element_by_tag_name('form').submit()
    # front
    time.sleep(0.5)
    get_visible_form(browser).find_element_by_css_selector('input').send_keys(
        "front")
    get_visible_form(browser).find_element_by_tag_name('form').submit()
Exemplo n.º 9
0
def test(server_proc: subprocess.Popen, browser: Chrome):
    time.sleep(6)
    percySnapshot(browser=browser, name='bokeh')
Exemplo n.º 10
0
 def test_protein_view(self):
     self.selenium.get(f'{self.live_server_url}/protein')
     percySnapshot(browser=self.selenium,
                   name='protein',
                   widths=PERCY_BS_WIDTHS)
Exemplo n.º 11
0
 def test_characterize_view(self):
     self.selenium.get(f'{self.live_server_url}/characterize')
     percySnapshot(browser=self.selenium,
                   name='characterize',
                   widths=PERCY_BS_WIDTHS)
Exemplo n.º 12
0
 def test_landing_view(self):
     self.selenium.get(self.live_server_url)
     self.selenium.execute_script('window.scrollTo(0, 100)')
     percySnapshot(browser=self.selenium,
                   name='homepage',
                   widths=PERCY_BS_WIDTHS)