web自动化7-pytest④实践测试用例-回归用例web自动化部分代码

文档说明:

  • 本文档包括web自动化目录结构
  • 代码元素定位 : 父级, 同级后面, 同级div, 包含, 不包含, 鼠标右键, 悬停, 句柄切换(浏览器切换,关闭), 不可见元素查找, 滑动到不可见元素出现, 悬停后点击, 页面有值判断, 页面数据量判断
  • web自动化: 前置, 后置事件
    结合上篇文章, 基本可以实现 web 自动化所有内容. 结合前几篇文章, 应用场景足够丰富!

目录结构:
在这里插入图片描述
conftest.py

# -*- coding: utf-8 -*-
"""
conftest - 
Author: duxiaowei
Date: 2024/7/19
"""
import time

import pytest
from selenium.webdriver.common.by import By

import cs_auto.web.com.common as common


@pytest.fixture(scope="session", autouse=True)
def web_start():
    # 设置环境
    # data = {'url': 'http://lemut.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 221208530, 'pwd': 'Lexin,18766227989'}
    data = {'url': 'http://lemut.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 13256883967, 'pwd': 'kf,13256883967'}
    # data = {'url': 'http://lemut-prev.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 221208530, 'pwd': 'Lexin,18766227989'}
    # 坐席 - 登陆
    driver = common.login(data)
    driver.implicitly_wait(20)
    # 展开左侧
    driver.find_element(By.XPATH, '//div[@class="aRight"]').click()
    time.sleep(2)
    return driver

# -*- coding: utf-8 -*-
"""
conftest - 
Author: duxiaowei
Date: 2024/7/19
"""
import time

import pytest
from selenium.webdriver.common.by import By

import cs_auto.web.com.common as common


@pytest.fixture(scope="session", autouse=True)
def web_start():
    # 设置环境
    # data = {'url': 'http://lemut.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 221208530, 'pwd': 'Lexin,18766227989'}
    data = {'url': 'http://lemut.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 13256883967, 'pwd': 'kf,13256883967'}
    # data = {'url': 'http://lemut-prev.qd-aliyun-dmz-ack-internal.haier.net/ut/login', 'name': 221208530, 'pwd': 'Lexin,18766227989'}
    # 坐席 - 登陆
    driver = common.login(data)
    driver.implicitly_wait(20)
    # 展开左侧
    driver.find_element(By.XPATH, '//div[@class="aRight"]').click()
    time.sleep(2)
    return driver

# 关闭浏览器
@pytest.fixture(scope="session", autouse=True)
def web_end(web_start):
    yield
    web_start.close()


run.py

# -*- coding: utf-8 -*-
"""
run - 
Author: duxiaowei
Date: 2024/7/19
"""
import os

import pytest

if __name__ == '__main__':
    # pytest.main(["lemut_yywh_test.py::Test_运营维护::test_安装机器人信息采集"])
    pytest.main(["知识库_test.py::Test_业务受理::test_问答推荐","知识库_test.py::Test_业务受理::test_Uhome燃气热水器", "知识库_test.py::Test_业务受理::test_产品大类"])
    # 清空目录,并重新生成新的文件
    # os.system("allure generate ./allure_result -o ./allure-report --clean")
    # # 切换目录
    # os.system("cd D:\\code\\python\\cs_auto\\web\\test_auto\\allure-report")
    # 打开报告
    # os.system("allure serve D:\\code\\python\\cs_auto\\web\\test_auto\\allure-report")



# pytest.main(["lemut_yqgl_test.py::Test_舆情管理","lemut_yhqx_test.py::Test_用户与权限"])
# 运行生成测试报告:allure generate ./allure_result -o ./allure-report --clean
# allure使用了两种方式来渲染页面。分别是 allure open 和 allure serve。
# allure open:用于在本地渲染和查看结果;
# allure serve:用于在本地渲染后对外展示结果。

pytest.ini

[pytest]

testpaths = ./web
addopts = -vs --alluredir ./allure_result --reruns=0 --reruns-delay=3

lemut_ywsl_test.py

# -*- coding: utf-8 -*-
"""
lemut_select - 业务受理 10-
Author: duxiaowei
Date: 2024/7/17
"""
import time

import allure
import pytest
from selenium.webdriver.common.by import By


# 业务受理
@allure.feature("业务受理")
@pytest.mark.run(order=10)
class Test_业务受理:

    @pytest.fixture(scope="function", autouse=True)
    def setup(self, web_start):
        self.driver = web_start
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div/span[text()="业务受理"]').click()
        time.sleep(2)
        yield
        time.sleep(1)
        # 关闭当前页签,打开-业务查询页签
        self.driver.find_element(By.XPATH, '//div/span[text()="业务受理"]').click()

    # 客满维护
    @pytest.mark.run(order=11)
    @allure.title("客满维护")
    @pytest.mark.parametrize('HIC信息单号,开始天,结束天', [("YT02407120021805", "2024-07-11", "2024-07-12")])
    def test_客满维护(self, HIC信息单号, 开始天, 结束天):
        self.driver.find_element(By.XPATH, '//ul/li[text()="客满维护"]').click()
        time.sleep(2)
        try:
            self.driver.find_element(By.XPATH, '//label[text()="HIC信息单号:"]/following-sibling::div/div/input').send_keys(
                HIC信息单号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="挂机时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').send_keys(
                开始天)
            time.sleep(1)
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].clear()
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].send_keys(结束天)
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div[@class="el-picker-panel__footer"]/button[2]/span').click()

            time.sleep(1)  # 查询
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//div[@class!="el-table__fixed"]/div/table/tbody/tr/td[3]/div/span[text()="' + HIC信息单号 + '"]').text
            print(text)
            # 导出
            self.driver.find_element(By.XPATH,
                                     '//div[@id="clientSatList"]/div/form/div[2]/div/div[2]/button/span').click()
            time.sleep(2)
            assert text == HIC信息单号
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"客户满意度")]/i').click()

    # 电商督办
    @pytest.mark.run(order=12)
    @allure.title("电商督办")
    @pytest.mark.parametrize('信息单号,开始天,结束天', [("YT02407120020689", "2024-07-05", "2024-07-12")])
    def test_电商督办(self, 信息单号, 开始天, 结束天):
        self.driver.find_element(By.XPATH, '//ul/li[text()="电商督办"]').click()
        try:
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').send_keys(
                信息单号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="录入时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').send_keys(
                开始天)
            time.sleep(1)
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].clear()
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].send_keys(结束天)
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div[@class="el-picker-panel__footer"]/button[2]/span').click()

            time.sleep(1)  # 查询
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(2)  # 详情页
            self.driver.find_element(By.XPATH,
                                     '//div[@class!="el-table__fixed"]/div/table/tbody/tr/td/div/span/button/span[text()="详情"]').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//th[contains(text(),"信息单号:")]/following-sibling::td/span').text
            print(text)
            # 进入详情页
            assert text == 信息单号
            # 关闭
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/button[@aria-label="Close"]/i').click()
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"电商督办")]/i').click()

    # 电商邀评
    @pytest.mark.run(order=13)
    @allure.title("电商邀评")
    @pytest.mark.parametrize('订单编号,开始天,结束天', [("3949535376648537739", "2024-07-05", "2024-07-13")])
    def test_电商邀评(self, 订单编号, 开始天, 结束天):
        self.driver.find_element(By.XPATH, '//ul/li[text()="电商邀评"]').click()
        try:
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//label[text()="订单编号:"]/following-sibling::div/div/input').send_keys(
                订单编号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH,
                                     '//i[@class="el-input__icon el-range__close-icon"]').click()
            self.driver.find_element(By.XPATH, '//label[text()="邀评新增时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//label[text()="邀评新增时间:"]/following-sibling::div/div/input').send_keys(
                开始天)
            self.driver.find_elements(By.XPATH,
                                      '//label[text()="邀评新增时间:"]/following-sibling::div/div/input')[
                1].send_keys(结束天)
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            # 导出
            self.driver.find_element(By.XPATH,
                                     '//span[text()="评价导入"]/parent::button/parent::div/following-sibling::div/button/span').click()
            time.sleep(2)
            # 进入详情页
            self.driver.find_element(By.XPATH,
                                     '//div[@class!="el-table__fixed"]/div/table/tbody/tr/td/div/span/button/span[text()="闭环"]').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="reviewUserInfo"]/div[1]/div[2]/table/tbody[1]/tr/td[1]/div/input').get_attribute(
                'value')
            # 判断值是否正确
            assert text == 订单编号
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"邀评客户信息")]/i').click()
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"电商邀评")]/i').click()

    # 工贸督办
    @pytest.mark.run(order=14)
    @allure.title("工贸督办")
    @pytest.mark.parametrize('信息单号,开始天,结束天', [("JN02407120022700", "2024-07-05", "2024-07-13")])
    def test_工贸督办(self, 信息单号, 开始天, 结束天):
        self.driver.find_element(By.XPATH, '//ul/li[text()="工贸督办"]').click()
        try:
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').send_keys(
                信息单号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="入库时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').send_keys(
                开始天)
            time.sleep(1)
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].clear()
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].send_keys(结束天)
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div[@class="el-picker-panel__footer"]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()

            time.sleep(2)
            # 进入详情页
            self.driver.find_element(By.XPATH,
                                     '//div[@class!="el-table__fixed"]/div/table/tbody/tr/td/div/span/button/span[text()="查看详情"]').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="industrySuperviseDetail"]/div[1]/div[2]/table/tbody[2]/tr/td[3]/div/input').get_attribute(
                'value')
            # 判断值是否正确
            assert text == 信息单号
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"督办详情")]/i').click()
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"工贸督办")]/i').click()

    # 抱怨信息督办库
    @pytest.mark.run(order=15)
    @allure.title("抱怨信息督办库")
    @pytest.mark.parametrize('信息单号,开始天,结束天', [("JH02407120022611", "2024-07-05", "2024-07-13")])
    def test_抱怨信息督办库(self, 信息单号, 开始天, 结束天, web_start):
        self.driver.find_element(By.XPATH, '//ul/li[text()="抱怨信息督办库"]').click()
        try:
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').clear()
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').send_keys(
                信息单号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="录单时间(起):"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').send_keys(
                开始天)
            time.sleep(2)
            # 时间框-确定
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]//div[2]/button[2]/span').click()
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="录单时间(止):"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').send_keys(
                结束天)
            time.sleep(1)
            # 时间框-确定
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]//div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()

            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="complainInfoDatabase"]/div[2]/div[1]/div[3]//tr/td[3]').text
            assert text == 信息单号
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"抱怨信息督办库")]/i').click()

    # 小海跳闸审核查询
    @pytest.mark.run(order=16)
    @allure.title("小海跳闸审核查询")
    @pytest.mark.parametrize('信息单号,开始天,结束天', [("DL02407120002842", "2024-07-05", "2024-07-13")])
    def test_小海跳闸审核查询(self, 信息单号, 开始天, 结束天, web_start):
        self.driver.find_element(By.XPATH, '//ul/li[text()="小海跳闸审核查询"]').click()
        try:
            time.sleep(2)
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').clear()
            self.driver.find_element(By.XPATH, '//label[text()="信息单号:"]/following-sibling::div/div/input').send_keys(
                信息单号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="登记开始时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').send_keys(
                开始天)
            time.sleep(1)
            # 时间框-确定
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]//div[2]/button[2]/span').click()
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="登记结束时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div[@class="el-picker-panel__body"]/div[1]/span[1]/div/input').send_keys(
                结束天)
            time.sleep(1)
            # 时间框-确定
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]//div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()

            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//*[@id="tripList"]/div[2]/div[1]/div[3]/table/tbody/tr/td[2]/div/span/button').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="tripDetail"]/div[1]/div[2]/table/tbody[1]/tr/td[1]/div/input').get_attribute(
                'value')
            # 判断值是否正确
            assert text == 信息单号
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"小海跳闸审核查询详情")]/i').click()
            time.sleep(1)
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"小海跳闸审核查询")]/i').click()

    # 舆情工单处理
    @pytest.mark.run(order=17)
    @allure.title("舆情工单处理")
    @pytest.mark.parametrize('舆情工单号,开始天,结束天', [("202407120115", "2024-07-05", "2024-07-13")])
    def test_舆情工单处理(self, 舆情工单号, 开始天, 结束天):
        self.driver.find_element(By.XPATH, '//ul/li[text()="舆情工单处理"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"高级查询")]').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//label[text()="舆情工单号:"]/following-sibling::div/div/input').send_keys(
                舆情工单号)
            time.sleep(1)
            # 创建时间
            self.driver.find_element(By.XPATH, '//label[text()="创建时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').send_keys(
                开始天)
            time.sleep(1)
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].clear()
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].send_keys(结束天)
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div[@class="el-picker-panel__footer"]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            # 鼠标-滑动到浏览器底部
            self.driver.execute_script("window.scrollTo(0, document.body.clientHeight)")
            # 详情
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//*[@id="industrySupervise"]/div[2]/div[1]/div[3]/table/tbody/tr/td[2]/div/span/button[1]/span').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="industrySupervise"]/div[3]/div/div[2]/div/div[1]/form/div[2]/div[1]/div/div').text
            # 判断值是否正确
            assert text == 舆情工单号

            # 关闭
            time.sleep(1)
            # 关闭
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/button[@aria-label="Close"]/i').click()
            time.sleep(1)
        finally:
            self.driver.execute_script("window.scrollTo(0, 0)")
            self.driver.find_element(By.XPATH, '//span[contains(text(),"舆情工单处理")]/i').click()

lemut_yywh_test.py

# -*- coding: utf-8 -*-
"""
lemut_select - 运营维护, 30-44
话术维护 -弹窗要前端修改为:增加话术操作
Author: duxiaowei
Date: 2024/7/24
"""

import time
import allure
import pytest
from selenium.webdriver.common.by import By


# 运营维护
@pytest.mark.run(order=30)
@allure.feature("运营维护")
class Test_运营维护:

    @pytest.fixture(scope="function", autouse=True)
    def setup(self, web_start):
        self.driver = web_start
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div/span[text()="运营维护"]').click()
        time.sleep(2)
        yield
        time.sleep(1)
        # 关闭当前页签,打开-业务查询页签
        self.driver.find_element(By.XPATH, '//div/span[text()="运营维护"]').click()

    # 自动应答账号
    @pytest.mark.run(order=31)
    @allure.title("自动应答账号")
    def test_自动应答账号(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="自动应答账号"]').click()
        try:
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="autoAnswerCode"]/div/div/div/table/tbody/tr[1]/td[2]/div/span').text
            time.sleep(1)
            assert text is not None or text != ""
        finally:
            # 关闭
            self.driver.find_element(By.XPATH, '//span[contains(text(),"自动应答账号")]/i').click()

    # 弹屏信息维护
    @pytest.mark.run(order=32)
    @allure.title("弹屏信息维护")
    def test_弹屏信息维护(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="弹屏信息维护"]').click()
        try:
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(2)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="getMessageList"]/div/div/div/div/table/tbody/tr[1]/td[2]/div/span').text
            # 判断有数据
            assert int(text) == 1
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//*[@id="getMessageList"]/div/form/div/div/div[2]/button[2]/span').click()
            time.sleep(2)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="新增弹屏信息"]/following-sibling::button/i').click()
        finally:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"弹屏信息维护")]/i').click()

    # 话术维护
    @pytest.mark.run(order=33)
    @allure.title("话术维护")
    def test_话术维护(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="话术维护"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//label[text()="话术类型:"]/following-sibling::div/div/div/span/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//ul/li/span[text()="过渡语"]').click()
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            assert self.driver.find_element(By.XPATH,
                                            '//*[@id="classList"]/div/div/div/table/tbody/tr[1]/td[5]/div/span').text == "过渡语"

            self.driver.find_element(By.XPATH,
                                     '//*[@id="classList"]/div/form/div[2]/div/div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="增加话术操作"]/following-sibling::button/i').click()
        finally:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"话术维护")]/i').click()

    # 话术类型维护
    @pytest.mark.run(order=34)
    @allure.title("话术类型维护")
    def test_话术类型维护(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="话术类型维护"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//label[text()="渠道类型:"]/following-sibling::div/div/div/span/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//ul/li/span[text()="微信/易信"]').click()
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            # 判断有数据
            assert self.driver.find_element(By.XPATH,
                                            '//*[@id="classList"]/div/div/div/table/tbody/tr[1]/td[3]/div/span').text == "微信/易信"

            self.driver.find_element(By.XPATH,
                                     '//*[@id="classList"]/div/form/div[2]/div/div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="增加话术类型操作"]/following-sibling::button/i').click()
        finally:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"话术类型维护")]/i').click()

    # 安装机器人信息采集
    @pytest.mark.run(order=35)
    @allure.title("安装机器人信息采集")
    def test_安装机器人信息采集(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="安装机器人信息采集"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(2)
            # 判断有数据
            textTotal = self.driver.find_element(By.XPATH,'//*[@id="kdxfTelList"]/div[2]/div[2]/span[1]').text
            count = textTotal.split(" ")[1]

            assert int(count) > 0
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"安装机器人信息采集")]/i').click()

    # 智能IVR报表
    @pytest.mark.run(order=36)
    @allure.title("智能IVR报表")
    def test_智能IVR报表(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="智能IVR报表"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="telRecordQuery"]/div/div/div/div/table/tbody/tr[1]/td[1]/div/span').text
            # 判断有数据
            assert int(text) == 1
        finally:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"智能IVR报表")]/i').click()

    # 分机管理
    @pytest.mark.run(order=37)
    @allure.title("分机管理")
    def test_分机管理(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="分机管理"]').click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="commerceExtension"]/div/div/div/div/table/tbody/tr[1]/td[2]/div/span').text
            # 判断有数据
            assert int(text) == 1
            self.driver.find_element(By.XPATH,
                                     '//*[@id="commerceExtension"]/div/form/div[2]/div/div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="分机号绑定"]/following-sibling::button/i').click()
            time.sleep(1)
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"分机管理")]/i').click()

    # 关键字检索维护
    @pytest.mark.run(order=38)
    @allure.title("关键字检索维护")
    def test_关键字检索维护(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="关键字检索维护"]').click()
        try:
            time.sleep(1)

            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="keyWordsManage"]/div/div/div/div/table/tbody/tr[1]/td[2]/div/span').text
            # 判断有数据
            assert int(text) == 1
            self.driver.find_element(By.XPATH,
                                     '//*[@id="keyWordsManage"]/div/form/div[2]/div/div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="新增关键字信息"]/following-sibling::button/i').click()
            time.sleep(1)
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"关键字检索维护")]/i').click()

    # 直接派单弹屏维护
    @pytest.mark.run(order=39)
    @allure.title("直接派单弹屏维护")
    def test_直接派单弹屏维护(self):
        time.sleep(1)
        直接派单弹屏维护 = self.driver.find_element(By.XPATH, '//ul/li[text()="直接派单弹屏维护"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 直接派单弹屏维护)
        time.sleep(1)
        直接派单弹屏维护.click()

        try:
            time.sleep(1)

            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="faultTreeMessage"]/div/div/div/div/table/tbody/tr[1]/td[2]/div/span').text
            # 判断有数据
            assert int(text) == 1
            self.driver.find_element(By.XPATH,
                                     '//*[@id="faultTreeMessage"]/div/form/div[2]/div/div[2]/button[2]/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="新增故障树弹屏信息"]/following-sibling::button/i').click()
            time.sleep(1)
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"直接派单弹屏维护")]/i').click()

    # 产品大类维护
    @pytest.mark.run(order=40)
    @allure.title("产品大类维护")
    def test_产品大类维护(self):
        time.sleep(1)
        产品大类维护 = self.driver.find_element(By.XPATH, '//ul/li[text()="产品大类维护"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 产品大类维护)
        time.sleep(1)
        产品大类维护.click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="proKindMainten"]/div/div/div/div/table/tbody/tr[1]/td[1]/div/span').text
            # 判断有数据
            assert int(text) == 1
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"产品大类维护")]/i').click()

    # 代报管理
    @pytest.mark.run(order=41)
    @allure.title("代报管理")
    def test_代报管理(self):
        time.sleep(1)
        代报管理 = self.driver.find_element(By.XPATH, '//ul/li[text()="代报管理"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 代报管理)
        time.sleep(1)
        代报管理.click()
        time.sleep(1)
        try:
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="autoAnswerCode"]/div/div/div/div/table/tbody/tr[1]/td[1]/div/span').text
            # 判断有数据
            assert int(text) == 1
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//*[@id="autoAnswerCode"]/div/form/div[2]/div/div[2]/button[2]').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//span[text()="新增"]/following-sibling::button/i').click()
            time.sleep(1)

        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"代报管理")]/i').click()

    # 短信发送记录查询
    @pytest.mark.run(order=42)
    @allure.title("短信发送记录查询")
    @pytest.mark.parametrize('手机号,开始天,结束天', [("17664080420", "2024-07-11", "2024-07-13")])
    def test_短信发送记录查询(self, 手机号, 开始天, 结束天):
        time.sleep(1)
        短信发送记录查询 = self.driver.find_element(By.XPATH, '//ul/li[text()="短信发送记录查询"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 短信发送记录查询)
        time.sleep(1)
        短信发送记录查询.click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="客服专项"]').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//label[text()="手机号:"]/following-sibling::div/div/input[not(@id)]').send_keys(手机号)
            time.sleep(1)
            # 时间框
            self.driver.find_element(By.XPATH, '//label[text()="发送时间:"]/following-sibling::div/div/input').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').clear()
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]').send_keys(
                开始天)
            time.sleep(1)
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].clear()
            self.driver.find_elements(By.XPATH,
                                      '//div[not(contains(@style,"display"))]/div/div/div/span/span/div/input[@class="el-input__inner"]')[
                2].send_keys(结束天)
            self.driver.find_element(By.XPATH,
                                     '//div[not(contains(@style,"display"))]/div[@class="el-picker-panel__footer"]/button[2]/span').click()
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)

            tds = self.driver.find_elements(By.XPATH,
                                            '//*[@id="duibeiMessage"]/div/div/div/table/tbody/tr/td[5]/div/span')
            # 判断有一个td的内容:推送智能报单链接
            assert any(lambda td: td.text == "推送智能报单链接" for td in tds)
        finally:
            # 关闭
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[contains(text(),"短信发送记录查询")]/i').click()

    # 字典项维护
    @pytest.mark.run(order=43)
    @allure.title("字典项维护")
    def test_字典项维护(self):
        time.sleep(1)
        字典项维护 = self.driver.find_element(By.XPATH, '//ul/li[text()="字典项维护"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 字典项维护)
        time.sleep(1)
        字典项维护.click()
        try:
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="tableWithNoPagnation"]/div/div/table/tbody/tr[1]/td[1]/div/span').text
            # 判断有数据
            assert int(text) == 1
            time.sleep(1)
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"字典项维护")]/i').click()

    # 老用户复购指引维护
    @pytest.mark.run(order=44)
    @allure.title("老用户复购指引维护")
    def test_老用户复购指引维护(self):
        time.sleep(1)
        老用户复购指引维护 = self.driver.find_element(By.XPATH, '//ul/li[text()="老用户复购指引维护"]')
        # 滚动到元素使其可见
        self.driver.execute_script("arguments[0].scrollIntoView(true);", 老用户复购指引维护)
        time.sleep(1)
        老用户复购指引维护.click()
        try:
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//span[text()="查询"]').click()
            time.sleep(1)
            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="rebuy-guide"]/div/div/div/div/table/tbody/tr[1]/td[1]/div/span').text
            # 判断有数据
            assert int(text) == 1
        finally:
            time.sleep(1)

            self.driver.find_element(By.XPATH, '//span[contains(text(),"老用户复购指引维护")]/i').click()

知识库_test.py

# -*- coding: utf-8 -*-
"""
知识库 - 
Author: duxiaowei
Date: 2024/7/30
"""

import time
import allure
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains  # 鼠标右键操作模拟

# 业务受理
@allure.feature("业务受理-知识库")
@pytest.mark.run(order=100)
class Test_业务受理:

    @pytest.fixture(scope="function", autouse=True)
    def setup(self, web_start):
        self.driver = web_start
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div/span[text()="业务受理"]').click()
        time.sleep(2)
        yield
        time.sleep(1)
        # 关闭当前页签,打开-业务查询页签
        self.driver.find_element(By.XPATH, '//div/span[text()="业务受理"]').click()

    # 产品中心,跳转
    @pytest.mark.run(order=101)
    @allure.title("知识库-产品卡片-三包法卡片跳转")
    def test_产品中心_三包法(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 产品卡片跳转
            # 悬停 按钮,等2秒
            labelIcon = self.driver.find_element(By.XPATH, '//*[@id="rightNav"]')
            labelIcon.click()
            ActionChains(self.driver).move_to_element(labelIcon).perform()
            time.sleep(1)
            # 点击-产品中心
            self.driver.find_element(By.XPATH, '//li/div[@class="orderTitle" and text()="产品中心"]').click()
            time.sleep(3)
            # 获取所有句柄
            handles1 = self.driver.window_handles
            self.driver.switch_to.window(handles1[1])
            # 产品卡片跳转,判断
            time.sleep(1)
            assert self.driver.find_element(By.XPATH, '//li[@role="menuitem" and text()="产品中心"]').text == "产品中心"
            self.driver.close()

            # 切换回,主页面
            self.driver.switch_to.window(handles1[0])

            # 三包法
            # 悬停 按钮,等2秒
            labelIcon = self.driver.find_element(By.XPATH, '//*[@id="rightNav"]')
            labelIcon.click()
            ActionChains(self.driver).move_to_element(labelIcon).perform()
            time.sleep(1)
            # 点击-三包法
            self.driver.find_element(By.XPATH, '//li/div[@class="orderTitle" and text()="三包法"]').click()
            time.sleep(2)
            # 获取所有句柄
            handles2 = self.driver.window_handles
            self.driver.switch_to.window(handles2[1])
            # 产品卡片跳转,判断
            time.sleep(2)
            assert self.driver.find_element(By.XPATH, '//span[text()="搜 索"]/parent::button/parent::div/preceding-sibling::input').get_attribute("value") == "三包"
            self.driver.close()

        finally:
            self.driver.switch_to.window(handles2[0])
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()

    # 智能推荐-产品大类,模糊查询验证
    @pytest.mark.run(order=102)
    @allure.title("智能推荐-产品大类")
    def test_产品大类(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 智能推荐
            self.driver.find_element(By.XPATH, '//*[@id="tab-intelligence"]').click()
            time.sleep(1)
            # 产品大类,输入
            self.driver.find_element(By.XPATH, '//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys("冰箱")
            time.sleep(1)
            # 点击放大镜
            self.driver.find_element(By.XPATH,'//i[@class="el-icon-search pGlass pointer"]').click()
            time.sleep(1)
            # 点击,冰箱,产品大类区分方法
            self.driver.find_element(By.XPATH,'//*[@id="pane-intelligence"]/div/div/div/div/div/div/div/ul').click()
            time.sleep(1)
            # 点击,统帅
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div/div[3]/div/div/span').click()
            time.sleep(1)
            # 点击,500L以下
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]//span[contains(text(),"500升以下")]').click()
            time.sleep(1)
            # 点击,统帅冰箱
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]//span[contains(text(),"统帅冰箱")]').click()
            input = self.driver.find_element(By.XPATH, '//*[@id="orderLogIn"]/div[1]/form/div[1]/div[1]/div/div/div/div/input').get_attribute("value")
            # 判断包含 ,统帅
            assert "统帅冰箱" in input

        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()

    # 智能推荐-产品大类,模糊查询验证
    @pytest.mark.run(order=103)
    @allure.title("sop退换机")
    def test_sop退换机(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,维修
            self.driver.find_element(By.XPATH, '//*[@id="tab-1"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,
                                            '//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("家用空调")
            # 选择 家用空调
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li[17]/span[contains(text(),"家用空调")]').click()
            time.sleep(1)

            服务类型 = self.driver.find_element(By.XPATH, '//span[text()="服务类型:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            # 鼠标悬停后,出现x,点击删除框中内容
            ActionChains(self.driver).move_to_element(服务类型).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            服务类型.send_keys("退机")
            # 选择 退机
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li[11]/span[contains(text(),"退机")]').click()
            time.sleep(3)
            # sop 推荐内容
            sop_text = self.driver.find_element(By.XPATH,'//*[@id="pane-intelligence"]/div/div/div/div/div/div/div/ul/div[2]').text
            time.sleep(1)
            assert "退换机指引流程" in sop_text
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()

    # 文章推荐
    @pytest.mark.run(order=104)
    @allure.title("文章推荐")
    def test_文章推荐(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,维修
            self.driver.find_element(By.XPATH, '//*[@id="tab-5"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,'//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,'//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("商用空调")
            self.driver.find_element(By.XPATH,'//div/div/div/ul/li[16]/span[contains(text(),"商用空调")]').click()
            # 选择 故障初判
            self.driver.find_element(By.XPATH, '//span[text()="故障初判:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys("安装")
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li/span[text()="安装"]').click()

            time.sleep(3)
            # 文章推荐
            text = self.driver.find_element(By.XPATH,'//*[@id="pane-intelligence"]/div/div/div/div[2]/div/div[2]/div').text
            self.driver.find_element(By.XPATH, '//*[@id="pane-intelligence"]/div/div/div/div[2]/div/div[2]/div/ul/li').click()

            # 获取所有句柄
            handles1 = self.driver.window_handles
            self.driver.switch_to.window(handles1[1])
            time.sleep(2)
            new_page_text = self.driver.find_element(By.XPATH, '//*[@id="fname"]/span').text
            assert new_page_text in text
            self.driver.close()
        finally:
            self.driver.switch_to.window(handles1[0])
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()

    # 安装指引类
    @pytest.mark.run(order=105)
    @allure.title("安装指引类")
    def test_安装指引(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,安装
            self.driver.find_element(By.XPATH, '//*[@id="tab-2"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,'//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,'//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("家用空调")
            self.driver.find_element(By.XPATH,'//div/div/div/ul/li/span[contains(text(),"家用空调")]').click()

            time.sleep(3)
            # 推荐
            self.driver.find_element(By.XPATH, '//*[@id="pane-intelligence"]/div//li[@class="sop-item"]/p').click()
            # 已到货
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div/div/span').click()
            # 首次安装
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div[2]/div[3]/div/div/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div[2]/div[5]/div/div[2]/div/div/span').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div[2]/div[5]/div/div[6]/div/div/span').click()
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div[2]/div[5]/div/div[10]/div/div/span').click() #
            textarea = self.driver.find_element(By.XPATH, '//*[@id="orderLogIn"]/div/form/div//textarea').get_attribute('value')
            assert "已提示收费" in textarea
        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()
    # Uhome燃气热水器
    @pytest.mark.run(order=106)
    @allure.title("Uhome燃气热水器")
    def test_Uhome燃气热水器(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,维修
            self.driver.find_element(By.XPATH, '//*[@id="tab-1"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,'//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,'//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("Uhome燃气热水器")
            self.driver.find_element(By.XPATH,'//div/div/div/ul/li/span[contains(text(),"Uhome燃气热水器")]').click()
            # 选择 故障初判
            self.driver.find_element(By.XPATH,
                                     '//span[text()="故障初判:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys(
                "E2")
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li/span[contains(text(),"E2")]').click()
            self.driver.find_element(By.XPATH, '//label[text()="来显号码:"]/following-sibling::div/div/input').send_keys("18251962523")

            time.sleep(3)
            # # 点击,咨询完毕
            self.driver.find_element(By.XPATH, '//*[@id="pane-intelligence"]//table/tbody/tr/td[2]/div/button[1]/span').click()
            time.sleep(3)
            textarea = self.driver.find_element(By.XPATH, '//span[text()="用户反映:"]/parent::div/parent::label/following-sibling::div/div/textarea').get_attribute('value')
            assert "给用户发送指导视频,用户接受,咨询完毕" in textarea
            time.sleep(1)
            # 切换回维修
            self.driver.find_element(By.XPATH, '//*[@id="tab-1"]').click()
            time.sleep(2)
            # # 点击,维修派单
            self.driver.find_element(By.XPATH,'//*[@id="pane-intelligence"]//table/tbody/tr/td[2]/div/button[2]/span').click()
            time.sleep(3)
            textarea2 = self.driver.find_element(By.XPATH,
                                                '//span[text()="用户反映:"]/parent::div/parent::label/following-sibling::div/div/textarea').get_attribute(
                'value')
            # print(textarea2)
            assert "用户不接受,派单售后" in textarea2

        finally:
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()


    # Sop推荐场景
    @pytest.mark.run(order=107)
    @allure.title("Sop推荐场景")
    def test_Sop推荐场景(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,维修
            self.driver.find_element(By.XPATH, '//*[@id="tab-1"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,'//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,'//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("冰箱")
            self.driver.find_element(By.XPATH,'//div/div/div/ul/li/span[contains(text(),"冰箱")]').click()

            # 选择 故障初判
            self.driver.find_element(By.XPATH,
                                     '//span[text()="故障初判:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys(
                "冰箱噪音大")
            time.sleep(1)
            self.driver.find_element(By.XPATH,'//div/div/div/ul/li/span[contains(text(),"冰箱噪音大")]').click()
            self.driver.find_element(By.XPATH, '//label[text()="来显号码:"]/following-sibling::div/div/input').clear()
            self.driver.find_element(By.XPATH, '//label[text()="来显号码:"]/following-sibling::div/div/input').send_keys("18251962523")
            time.sleep(3)
            # # 点击, 诊断书,冰箱噪音大
            self.driver.find_element(By.XPATH, '//*[@id="pane-intelligence"]//ul/div/div/li/p').click()
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div[@class="btn-box"]/span[contains(text(),"咕噜声")]').click()
            time.sleep(1)
            # 点击, 咨询完毕
            self.driver.find_element(By.XPATH, '//*[@id="sopig"]/div[2]/button').click()
            time.sleep(3)
            textarea = self.driver.find_element(By.XPATH, '//label[text()="故障思路:"]/following-sibling::div/div/textarea').get_attribute('value')

            assert "就会形成一定的咕噜声,这是正常现象,请您放心使用" in textarea

        finally:
            # pass
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()

    # 产品信息推荐
    @pytest.mark.run(order=108)
    @allure.title("产品信息推荐")
    def test_产品信息推荐(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,售后其他
            self.driver.find_element(By.XPATH, '//*[@id="tab-5"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,
                                            '//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("冰箱")
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li/span[contains(text(),"冰箱")]').click()

            # 产品型号
            self.driver.find_element(By.XPATH,
                                     '//span[text()="产品型号:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys(
                "BCD-218C ZB")
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div/ul/li[contains(text(),"BCD-218C ZB")]').click()

            time.sleep(3)

            text = self.driver.find_element(By.XPATH,
                                            '//*[@id="pane-intelligence"]//div[@class="smartRecomm-container"]//div[@role="button"]').text
            assert "BCD-218C ZB" in text



        finally:
            # pass
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()
    # 问答推荐
    @pytest.mark.run(order=109)
    @allure.title("问答推荐")
    def test_问答推荐(self):
        self.driver.find_element(By.XPATH, '//ul/li[text()="服务受理"]').click()
        time.sleep(2)
        try:
            # 点击,售后其他
            self.driver.find_element(By.XPATH, '//*[@id="tab-5"]').click()
            time.sleep(1)
            产品大类 = self.driver.find_element(By.XPATH,
                                            '//span[text()="产品大类:"]/parent::div/parent::label/following-sibling::div/div/div/input')
            ActionChains(self.driver).move_to_element(产品大类).perform()
            time.sleep(1)
            self.driver.find_element(By.XPATH,
                                     '//i[@class="el-select__caret el-input__icon el-icon-circle-close"]').click()
            time.sleep(1)
            产品大类.send_keys("冰箱")
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li/span[contains(text(),"冰箱")]').click()

            # 产品型号
            self.driver.find_element(By.XPATH,
                                     '//span[text()="产品型号:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys(
                "BCD-218C ZB")
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div/ul/li[contains(text(),"BCD-218C ZB")]').click()
            # 选择 故障初判
            self.driver.find_element(By.XPATH,
                                     '//span[text()="故障初判:"]/parent::div/parent::label/following-sibling::div/div/div/input').send_keys(
                "冰箱温度不会调节")
            time.sleep(1)
            self.driver.find_element(By.XPATH, '//div/div/div/ul/li/span[contains(text(),"冰箱温度不会调节")]').click()
            self.driver.find_element(By.XPATH, '//label[text()="来显号码:"]/following-sibling::div/div/input').clear()
            self.driver.find_element(By.XPATH,
                                     '//label[text()="来显号码:"]/following-sibling::div/div/input').send_keys(
                "18251962523")
            time.sleep(3)

            text = self.driver.find_element(By.XPATH,
                                                '//*[@id="pane-intelligence"]//div[@class="smartRecomm-container"]//div[@role="button"]').text
            assert "BCD-218C ZB" in text



        finally:
            # pass
            self.driver.find_element(By.XPATH, '//span[contains(text(),"服务受理")]/i').click()


  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值