Commit 43c60e13 by 宋鹏博

代码上传

parents
# Created by pytest automatically.
v
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by pytest.
# For information about cache directory tags, see:
# https://bford.info/cachedir/spec.html
# pytest cache directory #
This directory contains data from the pytest's cache plugin,
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
**Do not** commit this to version control.
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
from common.untils import DriverTools
class BasePage:
def __init__(self, type="web"):
if type == "web":
self.driver = DriverTools.get_driver()
elif type == "app":
self.driver = DriverTools.get_app_driver()
else:
print("页面类型输入错误,请输入web/app")
# 查找元素
def find_ele(self, loc, time=10, fre=1):
ele = WebDriverWait(self.driver, time, fre).until(lambda x: x.find_element(*loc))
return ele
# 输入内容
def input_text(self, loc, value):
ele = self.find_ele(loc)
ele.clear()
ele.send_keys(value)
# 滚动条
def scroll(self, x, y):
js = "window.scrollTo({},{})".format(x, y)
self.driver.execute_script(js)
# 下拉框文本选择
def select_text(self, loc, text):
select = Select(self.find_ele(loc))
select.select_by_visible_text(text)
# 获取标题
def get_title(self):
title = self.driver.title
return title
# 获取url
def get_url(self):
url = self.driver.current_url
return url
# 鼠标悬停
def mouse_stop(self, loc):
action = ActionChains(self.driver)
action.move_to_element(self.find_ele(loc))
action.perform()
# 获取弹出框文本内容
def alert_text(self):
alert = self.driver.switch_to.alert
text = alert.text
return text
# 切换弹窗
def windows_change(self, num):
self.driver.switch_to.window(self.driver.window_handles[num])
# 关闭弹窗
def close_window(self):
self.driver.close()
# mysql数据库
import pymysql
from config import host, user, database_pwd, database, port
class DButils:
__conn = None
__cursor = None
# 连接数据库
@classmethod
def get_conn(cls):
if cls.__conn is None:
cls.__conn = pymysql.connect(host=host, port=port, user=user, password=database_pwd, database=database,
charset="utf8")
return cls.__conn
# 创建游标方法
@classmethod
def get_cursor(cls):
if cls.__cursor is None:
cls.__cursor = cls.get_conn().cursor()
return cls.__cursor
# sql执行查询方法
@classmethod
def select_sql(cls, sql):
result = None
try:
cursor = cls.get_cursor()
cursor.execute(sql)
result = cursor.fetchall()
except Exception as e:
print(e)
finally:
cls.close_cursor()
cls.close_conn()
return result
# 数据库的增删改操作
@classmethod
def uid_sql(cls, sql):
try:
conn = cls.get_conn()
cursor = cls.get_cursor()
cursor.execute(sql)
conn.commit()
except Exception as e:
print(e)
cls.get_conn().rollback()
finally:
cls.close_cursor()
cls.close_conn()
# 关闭游标方法
@classmethod
def close_cursor(cls):
if cls.__cursor:
cls.__cursor.close()
cls.__cursor = None
# 关闭连接
@classmethod
def close_conn(cls):
if cls.__conn:
cls.__conn.close()
cls.__conn = None
import json
from selenium.webdriver.support.wait import WebDriverWait
from common.untils import DriverTools
from config import file_path
def get_text(loc, time=10, fre=1):
ele = WebDriverWait(DriverTools.get_driver(), time, fre).until(lambda x: x.find_element(*loc))
return ele.text
def get_app_text(loc, time=10, fre=1):
ele = WebDriverWait(DriverTools.get_app_driver(), time, fre).until(lambda x: x.find_element(*loc))
return ele.text
def get_texts(loc, time=10, fre=1):
eles = WebDriverWait(DriverTools.get_driver(), time, fre).until(lambda x: x.find_elements(*loc))
ele_list = []
for ele in eles:
ele_list.append(ele.text)
return ele_list
def get_app_texts(loc, time=10, fre=1):
eles = WebDriverWait(DriverTools.get_app_driver(), time, fre).until(lambda x: x.find_elements(*loc))
ele_list = []
for ele in eles:
ele_list.append(ele.text)
return ele_list
def read_json(file_name):
path = file_path + "/data/" + file_name
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
list1 = []
for i in data:
temp = tuple(i.values())
list1.append(temp)
return list1
from selenium import webdriver
from appium import webdriver as appwebdriver
from selenium.webdriver.chrome.options import Options
from config import appium_server_url, caps
class DriverTools:
__driver = None
__app_driver = None
__options = None
# 初始化web驱动
@classmethod
def get_driver(cls):
if cls.__driver is None:
cls.__options = Options()
cls.__options.add_argument('--headless')
cls.__options.add_argument('--disable-gpu')
cls.__options.add_argument('--no-sandbox')
cls.__options.add_argument('--disable-dev-shm-usage')
cls.__options.add_argument('--remote-debugging-port=9222')
cls.__options.add_argument('--window-size=1366x768')
cls.__driver = webdriver.Chrome(options=cls.__options)
# cls.__driver.maximize_window()
cls.__driver.implicitly_wait(10)
return cls.__driver
# 关闭web驱动
@classmethod
def quit_driver(cls):
if cls.__driver:
cls.__driver.quit()
cls.__driver = None
# 打开app驱动
@classmethod
def get_app_driver(cls):
if cls.__app_driver is None:
cls.__app_driver = appwebdriver.Remote(appium_server_url, caps)
cls.__app_driver.implicitly_wait(10)
return cls.__app_driver
# 关闭app驱动
@classmethod
def quit_app_driver(cls):
if cls.__app_driver:
cls.__app_driver.quit()
cls.__app_driver = None
import os
# 文件路径设置
file_path = os.path.dirname(__file__)
# appium配置
caps = {
"platformName": "android", # 平台名
"platformVersion": "7.0", # 平台版本号
"deviceName": "emulator-5554", # 设备名
"appPackage": "com.android.settings", # 启动应用包名
"appActivity": "com.android.settings.Settings" # 启动应用界面名
}
appium_server_url = "http://127.0.0.1:4723/wd/hub"
# 路径
path = file_path + "/uifile/"
updata_pdf_name = "七下英语活页.pdf"
updata_pdf_path = path + updata_pdf_name
updata_word_name = "司令的女人.docx"
updata_word_path = path + updata_word_name
updata_picture_name = "图片检测.png"
updata_picture_path = path + updata_picture_name
updata_video_name = "血腥.mp4"
updata_video_path = path + updata_video_name
updata_qrcode_name = "首屏涉黄涉政二维码.png"
updata_qrcode_path = path + updata_qrcode_name
updata_traditional_name = "繁体字测试.docx"
updata_traditional_path = path + updata_traditional_name
updata_music_name = "审校音频.mp3"
updata_music_path = path + updata_music_name
word_text = r'司令在省城犯了死罪的消息传到村里之前,我们一直认为他是我们这茬人里最有福气的一个。司令是外号,他的乳名叫八月,学名叫孙国栋。我们在村子里念小学时,他的外号就叫响了,连我们那个爱好写诗、开口就合辙押韵的李诗经老师也叫。李老师给我们上语文课,看到黑板不干净,就说:"司令同学,请你上前;抬起你脸,擦擦黑板;小心灰尘,迷了你眼!""唉!"他爽快地答应着走上讲台擦黑板。受李诗经老师影响,我们也喜欢说四言句。李老师说,天下的诗歌、文章,都是从四言句化出来的,只要四言诗作得好,那就是一鞭一道痕,一掌一掴血,一刀一个窟窿,那就没有什么文体能难住你了。星期天我们约司令去放牛,站在大街上 - -他家临街 - -齐声喊叫:"司令司令,你这懒种;日上三竿,太阳晒腚。东洼放牛,南洼割草;沟里摸鱼,河里洗澡;你去不去?不去拉倒。"司令的娘孙寡妇从屋子里走出来,将半截身体探出土墙,不高兴地说:"你们这些孩子,怎么叫俺司令呢?俺有大号的,俺叫孙国栋。""大婶大婶,不要翻脸,我们保证,不再乱喊。"我们真诚地向她道着歉,然后大声喊叫:"司令司令,你真能磨,大闺女上轿,没你罗嗦!"司令攥着一块地瓜从屋子里蹿出来,大声嚷着:"别急别急,各位伙计,若不等我,不够意思!"司令娘对司令说:"往后他们叫你司令不许答应!"司令在我们那班差不多大小的孩子里是个头蹿得最高的,据说他的爹就是个大个子,大个子爹做出大个子儿,天经地义。他的爹外号叫旅长,爹旅长,儿司令,一代更比一代强。也许他的外号就是从他爹的外号的基础上提拔起来的?谁知道呢!司令的爹六○年生活困难时撑死了 - -一架飞机掉在我们村头上,司令的爹和几个村民用担架将受伤的飞行员送到机场,机场里抬出一筐馒头慰劳他们,司令的爹贪食,一口气吃了十七个。口家的路上,走着走着,嘭的一 '
knowledge_text = "测试"
find_word_text = "测试工程师"
# 测试环境编辑empid
AI_review_empid = 2372
AI_Prequalification_empid = 16583
# 生产环境编辑empid
# AI_review_empid = 4236
# AI_Prequalification_empid = 87834
# 测试环境域名
login_url = "https://aistudio.raysgo.com/login"
# 生产环境域名
# login_url = "https://aistudio.5rs.me/login"
# 测试环境用户id
userid = 1002164
# 生产环境用户id
# userid = 1000032332
# 测试环境账号密码
user_name = "13837988386"
password = "Aa1012436291"
# 生产环境账号密码
# user_name = "17711331133"
# password = "Qwe123456"
# 测试环境数据库
host = "122.112.227.235"
user = "userop"
database_pwd = "0#ztXqUzECGen8E"
database = "aireview"
port = 3306
# # 生产环境数据库
# host = "192.168.8.234"
# user = "aireview110"
# database_pwd = "4yFSvSBc"
# database = "aireview"
# port = 3306
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage
from config import AI_review_empid, AI_Prequalification_empid
# AI编辑工作室首页
class AIER(BasePage):
def __init__(self):
super().__init__('web')
# AI审校编辑
self.AI_review = (By.CSS_SELECTOR, f"div[id='studio-empId-{AI_review_empid}'] div[class='studio-item-inner']")
# AI预审编辑
self.AI_Prequalification = (
By.CSS_SELECTOR, f"div[id='studio-empId-{AI_Prequalification_empid}'] div[class='studio-item-inner']")
# 点击AI预审
def to_AI_Prequalification(self):
self.find_ele(self.AI_Prequalification).click()
# 点击AI审校
def to_AI_review(self):
self.find_ele(self.AI_review).click()
import time
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage
# AI预审编辑页面
class Aiprequalification(BasePage):
def __init__(self):
super().__init__('web')
# 上传按钮
self.update_key = (By.XPATH, "//div[@class='proofred_UploadBtn']//span[1]")
# 发送按钮
self.send_file = (By.XPATH, "//button[contains(text(),'发送')]")
# 上传文件
self.update_file=(By.XPATH,"(//input[@id='file'])[2]")
def update_pdf(self,updata_path):
self.find_ele(self.update_key).click()
time.sleep(5)
self.find_ele(self.update_file).send_keys(updata_path)
time.sleep(5)
self.find_ele(self.send_file).click()
import time
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage
from common.DButils import DButils
from common.untils import DriverTools
from paga.AIEditingRoomPage import AIER
from paga.LoginPage import Login
# Ai审校编辑页面
class Aireview(BasePage):
def __init__(self):
super().__init__('web')
# 图书审校按钮
self.book_review_btn = (By.XPATH, "//label[@class='ant-radio-button-wrapper ant-radio-button-wrapper-checked "
"proofreading-type-box']")
# 文本审校按钮
self.text_revierw_btn = (By.XPATH, "//div[@class='proofreading-type-checkbox']//div[2]//label[1]")
# 繁体字审校按钮
self.traditional_review_btn = (
By.XPATH, "(//label[@class='ant-radio-button-wrapper proofreading-type-box'])[2]")
# 多媒体审校按钮
self.media_review_btn = (By.XPATH, "(//label[@class='ant-radio-button-wrapper proofreading-type-box'])[3]")
# 查词查术语
self.find_word_btn = (By.XPATH, "(//label[@class='ant-radio-button-wrapper proofreading-type-box'])[4]")
# 知识查证按钮
self.find_knowledge_btn = (By.XPATH, "(//label[@class='ant-radio-button-wrapper proofreading-type-box'])[5]")
# 更多按钮
self.more_btn = (By.XPATH, "//div[@class='more-btn']")
# 发送按钮
self.send_btn = (By.XPATH, "//button[contains(text(),'发送')]")
# 输入框
self.input_box = (By.XPATH, "//div[@role='textbox']")
# 上传按钮
self.update_key = (By.XPATH, "//div[@class='proofred_UploadBtn']//span[1]")
# 上传文件
self.update_file = (By.XPATH, "(//input[@id='file'])[2]")
# 优先多检出
self.more_find = (By.XPATH, "(//div[@class='btn-item'])[2]")
# 优先少误报
self.few_dind = (By.XPATH, "(//div[@class='btn-item'])[1]")
# 开始审校按钮
self.start_review_btn = (By.XPATH, "//button[@type='button']")
# 图书审校
def book_review(self, updata_path):
self.find_ele(self.book_review_btn).click()
time.sleep(2)
self.find_ele(self.update_key).click()
time.sleep(3)
self.find_ele(self.update_file).send_keys(updata_path)
time.sleep(5)
self.find_ele(self.send_btn).click()
time.sleep(5)
self.find_ele(self.more_find).click()
time.sleep(2)
self.find_ele(self.start_review_btn).click()
# 文本审校
def text_revierw(self, text):
self.find_ele(self.text_revierw_btn).click()
time.sleep(1)
self.find_ele(self.input_box).send_keys(text)
time.sleep(1)
self.find_ele(self.send_btn).click()
# 繁体字文档审校
def traditional_review(self, updata_path):
self.find_ele(self.traditional_review_btn).click()
self.find_ele(self.update_key).click()
time.sleep(2)
self.find_ele(self.update_file).send_keys(updata_path)
time.sleep(5)
self.find_ele(self.send_btn).click()
# 多媒体审校
def media_review(self, media_list):
self.find_ele(self.media_review_btn).click()
for i in media_list:
self.find_ele(self.update_key).click()
time.sleep(2)
self.find_ele(self.update_file).send_keys(i)
time.sleep(1)
time.sleep(5)
self.find_ele(self.send_btn).click()
# 查词查术语
def find_word(self, text):
self.find_ele(self.more_btn).click()
time.sleep(1)
self.find_ele(self.find_word_btn).click()
time.sleep(1)
self.find_ele(self.input_box).send_keys(text)
time.sleep(1)
self.find_ele(self.send_btn).click()
# 知识查找
def find_knowledge(self, text):
self.find_ele(self.more_btn).click()
time.sleep(1)
self.find_ele(self.find_knowledge_btn).click()
time.sleep(1)
self.find_ele(self.input_box).send_keys(text)
time.sleep(1)
self.find_ele(self.send_btn).click()
import time
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage
from common.untils import DriverTools
from config import password, user_name
from paga.AIEditingRoomPage import AIER
class Login(BasePage):
def __init__(self):
super().__init__('web')
# 登录账号
self.reader_username = (By.ID, 'userName')
# 登录密码
self.follow_password = (By.ID, 'pwd')
# 登录按钮
self.person_login = (By.XPATH, '/html/body/div/div/div/div[1]/div[3]/div/div/div[3]/form/div['
'4]/div/div/div/div/button')
# 错误弹窗
self.login_info = (By.XPATH, '/html/body/div[2]/div/div/div/div/div/span[2]')
def login(self, user, password):
self.find_ele(self.reader_username).send_keys(user)
time.sleep(1)
self.find_ele(self.follow_password).send_keys(password)
time.sleep(1)
self.find_ele(self.person_login).click()
time.sleep(1)
[pytest]
disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True
;addopts = -s --html=report/admin/test_report.html --self-contained-html
addopts = --alluredir=./report --clean-alluredir
testpaths = ./script
python_files = test*
python_classes = Test*
python_functions = test*
\ No newline at end of file
import time
import allure
from common.DButils import DButils
from common.untils import DriverTools
from config import user_name, password, word_text, \
updata_traditional_path, updata_music_path, updata_qrcode_path, updata_video_path, updata_picture_path, \
knowledge_text, login_url, userid, updata_pdf_path, updata_pdf_name
from paga.AIEditingRoomPage import AIER
from paga.AiPrequalificationPage import Aiprequalification
from paga.AiReviewPage import Aireview
from paga.LoginPage import Login
# AI审校ui自动化测试
class TestAireview:
# 类前置
def setup_class(self):
self.login = Login()
self.AIroom = AIER()
self.aiprequailification = Aiprequalification()
self.dbtuils = DButils()
self.aireview = Aireview()
def setup_method(self):
self.driver = DriverTools.get_driver().get(login_url)
self.login.login(user_name, password)
self.AIroom.to_AI_review()
# 类后置
def teardown_class(self):
DriverTools.quit_driver()
# 图书审校流程
@allure.feature("图书审校流程")
def test_book_review(self):
self.aireview.book_review(updata_pdf_path)
time.sleep(3)
data = self.dbtuils.select_sql(
f'SELECT file_name ,status FROM aireview.assistant_task where create_user ={userid} and assistant_code '
'="diction" order by biz_id desc limit 1;')
assert data[0][0] == updata_pdf_name
# 文本审校流程
@allure.feature("文本审校流程")
def test_text_revierw(self):
self.aireview.text_revierw(word_text)
time.sleep(5)
data = self.dbtuils.select_sql(f"SELECT file_type FROM aireview.assistant_task where create_user ={userid} "
"order by biz_id desc limit 1;")
assert data[0][0] == "text"
# 繁体字审校流程
@allure.feature("繁体字审校流程")
def test_traditional_review(self):
self.aireview.traditional_review(updata_traditional_path)
time.sleep(5)
data = self.dbtuils.select_sql(f"SELECT assistant_code FROM aireview.assistant_task where create_user ={userid} "
"order by biz_id desc limit 1;")
assert data[0][0] == "unsimplified"
# 多媒体审校流程
@allure.feature("多媒体审校流程")
def test_media_review(self):
self.aireview.media_review([updata_picture_path, updata_video_path, updata_qrcode_path, updata_music_path])
time.sleep(5)
# 查词查术语流程
@allure.feature("查词查术语流程")
def test_find_word(self):
self.aireview.find_word(knowledge_text)
time.sleep(5)
# 知识查证流程
@allure.feature("知识查证流程")
def test_find_knowledge(self):
self.aireview.find_knowledge(knowledge_text)
time.sleep(5)
import time
import allure
from common.DButils import DButils
from common.untils import DriverTools
from config import user_name, password, updata_pdf_path, login_url, userid, updata_pdf_name
from paga.AIEditingRoomPage import AIER
from paga.AiPrequalificationPage import Aiprequalification
from paga.LoginPage import Login
# AI预审ui自动化测试
class TestPrequalification:
# 类前置
def setup_class(self):
self.login = Login()
self.AI = AIER()
self.aiprequailification = Aiprequalification()
self.dbtuils = DButils()
def setup_method(self):
self.driver = DriverTools.get_driver().get(login_url)
self.login.login(user_name, password)
# 类后置
def teardown_class(self):
DriverTools.quit_driver()
# AI预审流程
@allure.feature("AI预审流程")
def test_uodate_file(self):
self.AI.to_AI_Prequalification()
time.sleep(3)
self.aiprequailification.update_pdf(updata_pdf_path)
time.sleep(300)
data = self.dbtuils.select_sql(
f"SELECT file_name,status FROM aireview.assistant_task where create_user ={userid} and assistant_code "
"='preliminarytrial' order by biz_id desc limit 1;")
assert data[0][0] == updata_pdf_name
assert data[0][1] == 99
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment