diff --git a/pywebio/platform/tornado.py b/pywebio/platform/tornado.py index a12cdb8e..8e82ad85 100644 --- a/pywebio/platform/tornado.py +++ b/pywebio/platform/tornado.py @@ -276,7 +276,7 @@ def start_server(applications: Union[Callable[[], None], List[Callable[[], None] page.MAX_PAYLOAD_SIZE = max_payload_size = parse_file_size(max_payload_size) - # covered `os.environ.get()` func with `bool()` to pervent type check error + # covered `os.environ.get()` func with `bool()` to prevent type check error debug = Session.debug = bool(os.environ.get('PYWEBIO_DEBUG', debug)) # Since some cloud server may close idle connections (such as heroku), diff --git a/requirements.txt b/requirements.txt index 4bc7da57..a24b29cd 100755 --- a/requirements.txt +++ b/requirements.txt @@ -16,8 +16,8 @@ plotly Pillow # test requirements -selenium==3.* -percy-python-selenium==0.1.3 +selenium +percy-selenium coverage # doc building requirements diff --git a/test/.percy.yml b/test/.percy.yml index bdeff16b..063b355b 100644 --- a/test/.percy.yml +++ b/test/.percy.yml @@ -1,3 +1,6 @@ -version: 1 +version: 2 snapshot: - widths: [1000] \ No newline at end of file + widths: + - 1000 +discovery: + disable-cache: true diff --git a/test/Readme.md b/test/Readme.md index db42d1d4..04c3f784 100644 --- a/test/Readme.md +++ b/test/Readme.md @@ -10,11 +10,11 @@ ### 运行测试用例 ```bash -pip3 install -e ".[dev]" -npm install -D @percy/agent +pip3 install -r ../requirements.txt +npm install --save-dev @percy/cli export PERCY_TOKEN=[projects-token] -npx percy exec -- python3 1.basic_output.py auto +npx percy exec -- python3 1.basic.py auto ``` diff --git a/test/template.py b/test/template.py index 96186b3d..6cff5f08 100644 --- a/test/template.py +++ b/test/template.py @@ -7,9 +7,10 @@ from functools import partial from os import path -from percy import percySnapshot +from percy import percy_snapshot from selenium.webdriver import Chrome from selenium.webdriver.support.ui import Select +from selenium.webdriver.common.by import By from pywebio.input import * from pywebio.output import * @@ -19,7 +20,7 @@ def get_visible_form(browser): - forms = browser.find_elements_by_css_selector('#input-cards > div') + forms = browser.find_elements(By.CSS_SELECTOR, '#input-cards > div') for f in forms: if f.is_displayed(): return f @@ -347,25 +348,26 @@ def test_output(browser: Chrome, enable_percy=False, action_delay=0.5): time.sleep(action_delay * 2) # 等待输出完毕 # get focus - browser.find_element_by_tag_name('body').click() + browser.find_element(By.TAG_NAME, 'body').click() time.sleep(action_delay * 2) browser.execute_script('$("html, body").scrollTop( $(document).height()+100);') time.sleep(action_delay) - enable_percy and percySnapshot(browser, name='begin output') + if enable_percy: + percy_snapshot(browser, name='begin output') - tab_btns = browser.find_elements_by_css_selector('#pywebio-scope-table_cell_buttons button') + tab_btns = browser.find_elements(By.CSS_SELECTOR, '#pywebio-scope-table_cell_buttons button') for btn in tab_btns: time.sleep(action_delay) browser.execute_script("arguments[0].click();", btn) - btns = browser.find_elements_by_css_selector('#pywebio-scope-put_buttons button') + btns = browser.find_elements(By.CSS_SELECTOR, '#pywebio-scope-put_buttons button') for btn in btns: time.sleep(action_delay) browser.execute_script("arguments[0].click();", btn) # 滚动窗口 - btns = browser.find_elements_by_css_selector('#pywebio-scope-scroll_basis_btns button') + btns = browser.find_elements(By.CSS_SELECTOR, '#pywebio-scope-scroll_basis_btns button') for btn in btns: time.sleep(action_delay * 2) browser.execute_script("arguments[0].click();", btn) @@ -373,14 +375,16 @@ def test_output(browser: Chrome, enable_percy=False, action_delay=0.5): time.sleep(action_delay * 2) browser.execute_script('$("html, body").scrollTop( $(document).height()+100);') time.sleep(action_delay) - enable_percy and percySnapshot(browser, name='basic output') + if enable_percy: + percy_snapshot(browser, name='basic output') # popup - btn = browser.find_element_by_css_selector('#pywebio-scope-popup_btn button') + btn = browser.find_element(By.CSS_SELECTOR, '#pywebio-scope-popup_btn button') browser.execute_script("arguments[0].click();", btn) time.sleep(action_delay * 2) - enable_percy and percySnapshot(browser, name='popup') + if enable_percy: + percy_snapshot(browser, name='popup') browser.execute_script("$('.modal').modal('hide');") @@ -603,128 +607,132 @@ def test_input(browser: Chrome, enable_percy=False, action_delay=0.5): template.background_input() # 或者 await template.coro_background_input() / flask_coro_background_input """ - browser.find_element_by_css_selector('#input-container input').send_keys("22") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("22") + browser.find_element(By.TAG_NAME, 'form').submit() time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container input').send_keys("secret") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("secret") + browser.find_element(By.TAG_NAME, 'form').submit() time.sleep(action_delay) - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.TAG_NAME, 'form').submit() # checkbox time.sleep(action_delay) - browser.execute_script("arguments[0].click();", browser.find_element_by_css_selector('#input-container input')) - browser.find_element_by_tag_name('form').submit() + browser.execute_script("arguments[0].click();", browser.find_element(By.CSS_SELECTOR, '#input-container input')) + browser.find_element(By.TAG_NAME, 'form').submit() # Text Area time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container textarea').send_keys(" ".join(str(i) for i in range(20))) - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container textarea').send_keys(" ".join(str(i) for i in range(20))) + browser.find_element(By.TAG_NAME, 'form').submit() # file time.sleep(action_delay) img_path = path.join(here_dir, 'assets', 'img.png') - browser.find_element_by_css_selector('#input-container input').send_keys(img_path) - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys(img_path) + browser.find_element(By.TAG_NAME, 'form').submit() # text time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container input').send_keys("text") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("text") + browser.find_element(By.TAG_NAME, 'form').submit() # 表单取消 time.sleep(action_delay) - browser.execute_script("arguments[0].click();", browser.find_element_by_css_selector('.pywebio_cancel_btn')) + browser.execute_script("arguments[0].click();", browser.find_element(By.CSS_SELECTOR, '.pywebio_cancel_btn')) # valid func, age in [10, 60] time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container input').send_keys("1") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("1") + browser.find_element(By.TAG_NAME, 'form').submit() time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container input').clear() - browser.find_element_by_css_selector('#input-container input').send_keys("90") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').clear() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("90") + browser.find_element(By.TAG_NAME, 'form').submit() time.sleep(action_delay) - browser.find_element_by_css_selector('#input-container input').clear() - browser.find_element_by_css_selector('#input-container input').send_keys("23") - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.CSS_SELECTOR, '#input-container input').clear() + browser.find_element(By.CSS_SELECTOR, '#input-container input').send_keys("23") + browser.find_element(By.TAG_NAME, 'form').submit() # code time.sleep(action_delay) - # 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() + # 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(action_delay) - browser.find_element_by_name('name').send_keys("name") + browser.find_element(By.NAME, 'name').send_keys("name") time.sleep(action_delay * 2) - browser.find_element_by_name('age').send_keys("90") - browser.find_element_by_tag_name('form').submit() + 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(action_delay) - enable_percy and percySnapshot(browser, name='input group invalid') + if enable_percy: + percy_snapshot(browser, name='input group invalid') time.sleep(action_delay) - browser.find_element_by_name('age').clear() - browser.find_element_by_name('age').send_keys("23") - browser.find_element_by_tag_name('form').submit() + 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(action_delay) - browser.execute_script("arguments[0].click();", browser.find_element_by_css_selector('form button[type="button"]')) + browser.execute_script("arguments[0].click();", browser.find_element(By.CSS_SELECTOR, 'form button[type="button"]')) time.sleep(action_delay) # input action time.sleep(action_delay) - browser.execute_script("arguments[0].click();", browser.find_element_by_css_selector('form button[type="button"]')) + browser.execute_script("arguments[0].click();", browser.find_element(By.CSS_SELECTOR, 'form button[type="button"]')) time.sleep(action_delay) - browser.find_element_by_tag_name('form').submit() + browser.find_element(By.TAG_NAME, 'form').submit() # Input group time.sleep(action_delay) browser.execute_script('$("html, body").scrollTop( $(document).height()+100);') time.sleep(action_delay) - enable_percy and percySnapshot(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) + if enable_percy: + percy_snapshot(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.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(action_delay * 2) browser.execute_script('$("html, body").scrollTop( $(document).height()+100);') time.sleep(action_delay) - enable_percy and percySnapshot(browser, name='input group all invalid') + if enable_percy: + percy_snapshot(browser, name='input group all invalid') - browser.find_element_by_name('password').clear() - browser.find_element_by_name('password').send_keys("123") + browser.find_element(By.NAME, 'password').clear() + browser.find_element(By.NAME, 'password').send_keys("123") browser.execute_script("$('form button[type=\"submit\"]').eq(1).click()") time.sleep(action_delay * 2) browser.execute_script('$("html, body").scrollTop( $(document).height()+100);') time.sleep(action_delay * 2) - enable_percy and percySnapshot(browser, name='input group all submit') + if enable_percy: + percy_snapshot(browser, name='input group all submit') - browser.find_element_by_css_selector('form').submit() + browser.find_element(By.CSS_SELECTOR, 'form').submit() # background time.sleep(action_delay * 6) - get_visible_form(browser).find_element_by_css_selector('#input-container input').send_keys("background") - get_visible_form(browser).find_element_by_tag_name('form').submit() + get_visible_form(browser).find_element(By.CSS_SELECTOR, '#input-container input').send_keys("background") + get_visible_form(browser).find_element(By.TAG_NAME, 'form').submit() # front time.sleep(action_delay * 2) - get_visible_form(browser).find_element_by_css_selector('#input-container input').send_keys("front") - get_visible_form(browser).find_element_by_tag_name('form').submit() + get_visible_form(browser).find_element(By.CSS_SELECTOR, '#input-container input').send_keys("front") + get_visible_form(browser).find_element(By.TAG_NAME, 'form').submit() def set_defer_call(): @@ -754,7 +762,7 @@ def save_output(browser: Chrome, filename=None, process_func=None): :param process_func: 自定义数据处理函数 :return: 处理前后的html文本 """ - raw_html = browser.find_element_by_id('markdown-body').get_attribute('innerHTML') + raw_html = browser.find_element(By.ID, 'markdown-body').get_attribute('innerHTML') html = re.sub(r'"pywebio-scope-.*?"', '', raw_html) html = re.sub(r'id="pywebio-.*?"', '', html) html = re.sub(r"\('pywebio-.*?'\)", '', html) diff --git a/test/util.py b/test/util.py index 9f63ba5c..8ed172bf 100644 --- a/test/util.py +++ b/test/util.py @@ -55,7 +55,7 @@ def run_test(server_func, test_func, address='http://localhost:8080?_pywebio_deb browser = None try: - browser = webdriver.Chrome(chrome_options=chrome_options) + browser = webdriver.Chrome(options=chrome_options) browser.set_window_size(1000, 900) port_str = urlparse(address).netloc.split(':', 1)[-1] or '80' asyncio.run(wait_host_port('localhost', int(port_str)))