霍格沃兹测试学院 ceshiren.com
autonumber
actor 测试工程师 as tester
participant 系统 as sys
tester -> sys: 测试工程师在系统页面做点击输入等操作
sys -> sys: 系统运行产生响应
sys -> tester: 测试工程师拿到实际结果与预期结果对比
autonumber
actor 测试工程师 as tester
participant Python as python
participant Selenium as web
participant 被测系统 as sys
tester -> python: 使用Python编写自动化测试脚本
python -> web: 调用selenium执行自动化测试脚本
web -> sys: 模拟点击、输入等操作,并获取自动化运行的响应结果
sys -> python: Python拿到系统的响应结果,并与提前设定好的预期结果进行对比

Selenium is a suite of tools to automate web browsers across many platforms. runs in many browsers and operating systems can be controlled by many programming languages and testing frameworks
把 chromedriver 所在路径添加至 path 内

配置完成之后一定要重启Pycharm 或者 Cmd(命令行)
where chromedriver



# 举例,不要生搬硬套
export PATH=$PATH:/Applications/Google\ Chrome.app/Contents/MacOS
from selenium.webdriver.chrome.options import Options
option = Options()
option.debugger_address = "localhost:9222"
self._driver = webdriver.Chrome(options=option)
self._driver.get("https://work.weixin.qq.com/wework_admin/frame")
扫码登录等无法自动化登录的场景
driver.get_cookies()driver.add_cookie(cookie)@startmindmap
* 思路
** 1. 打开浏览器,扫码登录
** 2. 登录之后(重点!!!),通过get_cookies获取cookie
** 3. 检查本地文件是否已经获取成功
** 4. 再次打开浏览器,直接进入主页
** 5. 可以跳过扫码步骤
@endmindmap
def test_cookie():
driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get("https://work.weixin.qq.com/wework_admin/loginpage_wx?")
cookies = [{'domain': '.work.weixin.qq.com', 'httpOnly': False,}]
for cookie in cookies:
driver.add_cookie(cookie)
driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
driver.find_element_by_id("menu_contacts").click()
time.sleep(5)
driver.quit()
source .zshrc或source .bash_profile