1 Star 0 Fork 0

ChanGOGOGO/callplus_ui_auto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
conftest.py 3.92 KB
一键复制 编辑 原始数据 按行查看 历史
yaocheng1101 提交于 2024-08-15 18:24 . 智能呼叫系统UI自动化
# -*- coding: utf-8 -*-
# This code written by ChanGOGOGO
"""
"""
import time
import pytest
from utils import helpers
from playwright.sync_api import sync_playwright
from callplus_auto.operate.operate import Login, HomePageOperate, DialogDesign, CalloutTask
def pytest_addoption(parser):
# 从pytest运行命令的--env参数中获取到配置文件名
parser.addoption("--env", action="store", default="dev", help="配置文件名")
@pytest.fixture(scope="session")
def env_config(request):
"""根据pytest运行命令中--env参数的传值读取对应的配置文件信息"""
env = request.config.getoption("--env")
config_name = f"{env}.yaml"
env_config = helpers.read_yaml(config_name)
return env_config
@pytest.fixture(scope="session")
def public_config():
"""读取公共配置文件信息"""
config = helpers.read_yaml('public.yaml')
return config
@pytest.fixture(scope="session")
def playwright_fixture():
p = sync_playwright().start()
yield p
p.stop()
@pytest.fixture(scope="session")
def browser_fixture(public_config, playwright_fixture):
headless = public_config.get('headless')
browser = playwright_fixture.chromium.launch(headless=headless, channel='msedge', args=['--start-maximized'])
yield browser
browser.close()
@pytest.fixture(scope="session")
def context_fixture(browser_fixture):
context = browser_fixture.new_context(no_viewport=True) # 配合no_viewport为True才能实现浏览器最大化
yield context
context.close()
@pytest.fixture(scope="session")
def page_fixture(context_fixture):
page = context_fixture.new_page()
yield page
page.close()
@pytest.fixture(scope="session")
def login(env_config, context_fixture, page_fixture):
"""登录callplus系统后选择业务"""
aiforce_url = env_config.get('aiforce_url')
page_fixture.goto(aiforce_url)
login = Login(page_fixture)
username = env_config.get('aiforce_id')
password = env_config.get('aiforce_password')
login.login(username, password)
business_name = env_config.get('business_name')
with context_fixture.expect_page() as new_page_info:
login.choose_business(business_name)
new_page = new_page_info.value
yield new_page
new_page.close()
@pytest.fixture(scope="session")
def home_page_operate(login):
"""主页相关操作"""
home_page_operate = HomePageOperate(login)
return home_page_operate
@pytest.fixture(scope="session")
def dialog_design(login):
"""对话设计相关操作"""
dialog_design = DialogDesign(login)
return dialog_design
@pytest.fixture(scope="session", autouse=True)
def switch_env(env_config, home_page_operate):
"""切换环境:2.0-老bot,3.0-对话平台"""
env_index = env_config.get('env_index')
home_page_operate.choose_env(env_index)
@pytest.fixture(scope="session", autouse=True)
def get_now_time():
now_time = time.strftime('%Y%m%d%H%M%S')
return now_time
@pytest.fixture(scope="session")
def goto_experiment_group_page(home_page_operate, dialog_design):
home_page_operate.click_left_menu('对话设计')
dialog_design.scene_tab_switch('实验组')
@pytest.fixture(scope="session")
def create_experiment_group(env_config, goto_experiment_group_page, dialog_design, get_now_time):
"""新建实验组"""
experiment_group_name = f'{get_now_time}-实验组'
dialog_design.create_experiment_group(experiment_group_name)
dialog_design.wait(500)
return experiment_group_name
@pytest.fixture(scope="session")
def create_child_scene(get_now_time, dialog_design, create_experiment_group):
"""新建实验组子场景"""
experiment_group_name = create_experiment_group
child_scene_name = f"{get_now_time}-子场景"
dialog_design.create_child_scene(experiment_group_name, child_scene_name)
return child_scene_name
@pytest.fixture(scope="session")
def callout_task(login):
callout_task = CalloutTask(login)
return callout_task
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/changogogo/callplus_ui_auto.git
git@gitee.com:changogogo/callplus_ui_auto.git
changogogo
callplus_ui_auto
callplus_ui_auto
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385