测试周刊006: playwrightv1.53的新功能
在一个已有开发节奏的团队中,作为第一位测试人员去推行新流程,绝非易事。
你会被开发质疑:是不是要拖慢上线进度?是不是要卡死流程,让整个开发团队都不爽?
这些成见不是你的错,但你必须面对它们。
pydoll 初体验
之前介绍过一款新的 ui 自动化测试工具—-pydoll。
今天抽空在 github 的 copilot 的帮助下试用了一下。
我用 pydoll 实现了一个测试任务列表的测试套件,包含 5 个测试用例。
具体用例如下
import asyncio
import os
import unittest
from pydoll.browser.chromium import Chrome
from pydoll.browser.options import ChromiumOptions
from pydoll.constants import Key
class TestTodoMVC(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self):
options = ChromiumOptions()
options.add_argument('--start-maximized')
options.add_argument('--disable-notifications')
self.browser = Chrome(options=options)
self.tab = await self.browser.start()
await self.tab.go_to('https://todomvc.com/examples/react/dist/')
async def asyncTearDown(self):
await self.browser.__aexit__(None, None, None)
async def test_add_todo(self):
new_todo = await self.tab.find(class_name='new-todo', timeout=5, raise_exc=True)
await new_todo.type_text("Install pydoll")
await asyncio.sleep(1)
await new_todo.press_keyboard_key(Key.ENTER)
todo_items = await self.tab.find(class_name = 'view', timeout=5, find_all=True, raise_exc=True)
found = False
texts = []
for item in todo_items:
text = await item.text
texts.append(text)
if "Install pydoll" in text:
found = True
break
self.assertTrue(found)
async def test_complete_todo(self):
await self.test_add_todo()
toggle = await self.tab.find(class_name="toggle", timeout=5, raise_exc=True)
await toggle.click()
completed = await self.tab.find(class_name='completed', timeout=5, raise_exc=True)
self.assertIsNotNone(completed)
async def test_delete_todo(self):
await self.test_add_todo()
todo_item = await self.tab.find(class_name='view', timeout=5, raise_exc=True)
await todo_item.click()
destroy_btn = await todo_item.find(class_name='destroy', timeout=5, raise_exc=True)
await destroy_btn.click()
todo_items = await self.tab.find(class_name='view', find_all=True)
found = False
for item in todo_items:
if "Install pydoll" in item.text:
found = True
break
self.assertFalse(found)
async def test_filter_todo(self):
await self.test_add_todo()
toggle = await self.tab.find(class_name="toggle", timeout=5, raise_exc=True)
await toggle.click()
active_filter = await self.tab.find(text="Active", timeout=5, raise_exc=True)
await active_filter.click()
await asyncio.sleep(1)
active_items = [item for item in await self.tab.find(class_name = 'view', find_all=True)]
self.assertEqual(len(active_items), 0)
completed_filter = await self.tab.find(text="Completed", timeout=5, raise_exc=True)
await completed_filter.click()
await asyncio.sleep(1)
completed_items = await self.tab.find(class_name = 'view', find_all=True)
found = False
for item in completed_items:
title = await item.text
if "Install pydoll" in title:
found = True
break
self.assertTrue(found)
async def test_screenshot(self):
await self.test_add_todo()
screenshot_path = os.path.join(os.getcwd(), 'pydoll_repo.png')
await self.tab.take_screenshot(path=screenshot_path)
self.assertTrue(os.path.exists(screenshot_path))
if __name__ == "__main__":
unittest.main()
上面的代码实现了