代码拉取完成,页面将自动刷新
# -*- 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。