Skip to content

Commit

Permalink
upgrade percy to fix test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
wang0618 committed Feb 16, 2024
1 parent 51ece4a commit df42253
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 103 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ jobs:
npm install
gulp
cp dist/pywebio.min.* ../pywebio/html/js
- name: Install Test JS deps
run: npm install -D @percy/agent
- name: Install package
run: pip3 install ".[all]"
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install env
run: echo "PERCY_TOKEN=${{ secrets.PERCY_TOKEN }}" >> $GITHUB_ENV
- run: npm install --save-dev @percy/cli
- name: Percy Test
uses: percy/exec[email protected]
with:
working-directory: ./test
command: "./run_all.sh"
run: npx percy exec -- bash ./run_all.sh
working-directory: ./test
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
- name: Upload test output
uses: actions/upload-artifact@v1
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion pywebio/platform/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ plotly
Pillow

# test requirements
selenium==3.*
percy-python-selenium==0.1.3
selenium
percy-selenium
coverage

# doc building requirements
Expand Down
7 changes: 5 additions & 2 deletions test/.percy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
version: 1
version: 2
snapshot:
widths: [1000]
widths:
- 1000
discovery:
disable-cache: true
4 changes: 2 additions & 2 deletions test/11.charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cutecharts.charts import Line
from cutecharts.charts import Pie
from cutecharts.charts import Radar
from percy import percySnapshot
from percy import percy_snapshot
from selenium.webdriver import Chrome

import pywebio
Expand Down Expand Up @@ -376,7 +376,7 @@ def target():

def test(server_proc: subprocess.Popen, browser: Chrome):
time.sleep(8)
percySnapshot(browser, name='bokeh')
percy_snapshot(browser, name='bokeh')


def start_test_server():
Expand Down
9 changes: 5 additions & 4 deletions test/13.misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import subprocess
from functools import partial

from percy import percySnapshot
from percy import percy_snapshot
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By

import pywebio
import template
Expand Down Expand Up @@ -208,7 +209,7 @@ def test(server_proc: subprocess.Popen, browser: Chrome):

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

thread_out = template.save_output(browser)[-1]
Expand All @@ -220,10 +221,10 @@ def test(server_proc: subprocess.Popen, browser: Chrome):
time.sleep(6)

browser.execute_script("arguments[0].click();",
browser.find_element_by_css_selector('#pywebio-scope-error button'))
browser.find_element(By.CSS_SELECTOR, '#pywebio-scope-error button'))
browser.execute_script("$('button[type=submit]').click();")
time.sleep(2)
percySnapshot(browser, name='misc')
percy_snapshot(browser, name='misc')


def start_test_server():
Expand Down
7 changes: 4 additions & 3 deletions test/16.path_deploy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import subprocess

from percy import percySnapshot
from percy import percy_snapshot
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By

import util
from pywebio.platform import path_deploy
Expand All @@ -14,10 +15,10 @@

def test(server_proc: subprocess.Popen, browser: Chrome):
time.sleep(10)
percySnapshot(browser, name='path_deploy_1')
percy_snapshot(browser, name='path_deploy_1')
browser.get('http://localhost:8080/')
time.sleep(2)
page_html = browser.find_element_by_tag_name('body').get_attribute('innerHTML')
page_html = browser.find_element(By.TAG_NAME, 'body').get_attribute('innerHTML')
print(page_html)
for f in ['bmi', 'bokeh_app', 'chat_room', 'input_usage', 'output_usage', 'set_env_demo']:
assert f in page_html, f'{f} not in page'
Expand Down
29 changes: 15 additions & 14 deletions test/18.pin_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import subprocess
import time

from percy import percySnapshot
from percy import percy_snapshot
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select

Expand Down Expand Up @@ -67,25 +68,25 @@ async def coro_target():


def test_one_page(browser: Chrome):
browser.find_element_by_css_selector('[name=input]').send_keys("1")
browser.find_element(By.CSS_SELECTOR, '[name=input]').send_keys("1")
time.sleep(0.5)
browser.find_element_by_css_selector('[name=textarea]').send_keys("2")
browser.find_element(By.CSS_SELECTOR, '[name=textarea]').send_keys("2")
time.sleep(0.5)
Select(browser.find_element_by_css_selector('[name=select]')).select_by_visible_text('B')
Select(browser.find_element(By.CSS_SELECTOR, '[name=select]')).select_by_visible_text('B')
time.sleep(0.5)
Select(browser.find_element_by_css_selector('[name=select_multiple]')).select_by_visible_text('A')
Select(browser.find_element(By.CSS_SELECTOR, '[name=select_multiple]')).select_by_visible_text('A')
time.sleep(0.5)
browser.find_element_by_css_selector('[name=checkbox]').click()
browser.find_element(By.CSS_SELECTOR, '[name=checkbox]').click()
time.sleep(0.5)
browser.find_element_by_css_selector('[name=checkbox_inline]').click()
browser.find_element(By.CSS_SELECTOR, '[name=checkbox_inline]').click()
time.sleep(0.5)
browser.find_element_by_css_selector('[name=radio]').click()
browser.find_element(By.CSS_SELECTOR, '[name=radio]').click()
time.sleep(0.5)
browser.find_element_by_css_selector('[name=radio_inline]').click()
browser.find_element(By.CSS_SELECTOR, '[name=radio_inline]').click()
time.sleep(0.5)
browser.find_element_by_css_selector('button[type=\"submit\"]').click()
browser.find_element(By.CSS_SELECTOR, 'button[type=\"submit\"]').click()
time.sleep(0.5)
codeMirror = browser.find_element_by_css_selector(".CodeMirror pre")
codeMirror = browser.find_element(By.CSS_SELECTOR, ".CodeMirror pre")
action_chains = ActionChains(browser)
action_chains.move_to_element(codeMirror).click(codeMirror).send_keys('3').perform()

Expand All @@ -95,14 +96,14 @@ def test(server_proc: subprocess.Popen, browser: Chrome):
time.sleep(2)
test_one_page(browser)
time.sleep(2)
percySnapshot(browser, name='pin')
assert PASSED_TEXT in browser.find_element_by_id('markdown-body').get_attribute('innerHTML')
percy_snapshot(browser, name='pin')
assert PASSED_TEXT in browser.find_element(By.ID, 'markdown-body').get_attribute('innerHTML')

browser.get('http://localhost:8080/?app=coro_target')
time.sleep(2)
test_one_page(browser)
time.sleep(1)
assert PASSED_TEXT in browser.find_element_by_id('markdown-body').get_attribute('innerHTML')
assert PASSED_TEXT in browser.find_element(By.ID, 'markdown-body').get_attribute('innerHTML')


def start_test_server():
Expand Down
6 changes: 3 additions & 3 deletions test/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Loading

0 comments on commit df42253

Please sign in to comment.