Commit c0a37b75 by Administrator

2.88提交

parent 39aa5df3
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (pythonProject01)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (UIProject)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
import time
import pyautogui
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from Util.Util import DriverUtils
import logging
# from common.utils import DriverTools
......@@ -10,6 +14,7 @@ from Util.Util import DriverUtils
class BasePage:
def __init__(self):
self.driver = DriverUtils.get_web_driver()
self.set_logger()
# 查找元素
def find_el(self, loc, time=10, fre=0.5):
......@@ -40,3 +45,31 @@ class BasePage:
# 调用select选择方法
sle.select_by_visible_text(text)
# 选择文件
def select_document(self,path_str=None):
time.sleep(1)
pyautogui.write(path_str)
time.sleep(1)
pyautogui.press('enter')
time.sleep(2)
# 设置日志记录器
def set_logger(self):
logging.basicConfig(level=logging.INFO)
self.logger = logging.getLogger(__name__)
# 创建一个处理程序,用于输出到控制台
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
# 创建一个处理程序,用于输出到文件
file_handler = logging.FileHandler('business_knowledge.log')
file_handler.setLevel(logging.INFO)
# 创建一个格式化器,用于设置日志格式
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# 将格式化器添加到处理程序
console_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
# 将处理程序添加到记录器
self.logger.addHandler(console_handler)
self.logger.addHandler(file_handler)
import logging
import time
import pytest
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
......@@ -8,6 +10,7 @@ from BasePage.BasePage import BasePage
from Pages.login_page import LoginPage
from Util.Util import DriverUtils
"""
企业知识库--页面操作
"""
......@@ -17,6 +20,7 @@ class BusinessKnowledgePage(BasePage):
def __init__(self):
super().__init__()
self.upload_document_helper = UploadDocumentHelper()
self.ai_editing = (By.XPATH, '//*[@id="App"]/div/header/div[2]/div[2]') # AI编辑工作室按钮
self.business_knowledge = (By.XPATH, '//*[@id="App"]/div/div/div[2]/ul/li[3]/div/div/span') # 企业知识库按钮
self.quit = (By.XPATH, '//*[@id="App"]/div/section/div[1]/div[1]/div[1]/button/span') # 返回
......@@ -127,18 +131,34 @@ class BusinessKnowledgePage(BasePage):
time.sleep(1)
# 模拟点击选项
if optionName == elementsFrequencyOption.text:
logging.info("-----选择的更新频率:%s-----", elementsFrequencyOption.text)
elementsFrequencyOption.click()
break
# 选中订阅的网站
def subscriptionWebsiteSelect(self, optionsName=None):
print(optionsName)
subscriptionWebsiteOptions = self.find_el(self.subscriptionWebsiteListDiv).find_elements(By.XPATH,'//*[@id="website"]/div/div[2]/div[1]/div[contains(@class,"website-item")]')
subscriptionWebsiteOptionTexts = self.find_el(self.subscriptionWebsiteListDiv).finf_elements(By.XPATH,'//*[@id="website"]/div/div[2]/div[1]/div/label/span[2]/div/div/div')
subscriptionWebsiteOptionTexts = self.find_el(self.subscriptionWebsiteListDiv).find_elements(By.XPATH,'//*[@id="website"]/div/div[2]/div[1]/div/label/span[2]/div/div/div')
time.sleep(1)
for subscriptionWebsiteOption,subscriptionWebsiteOptionText in zip(subscriptionWebsiteOptions,subscriptionWebsiteOptionTexts):
for optionName in optionsName:
if optionName == subscriptionWebsiteOptionText.text:
logging.info("-----选择的网站:%s-----",subscriptionWebsiteOptionText.text)
subscriptionWebsiteOption.click() # 选中
# 清空网站订阅内容
def clearSubscriptionWebsite(self):
self.find_el(self.clearButton).click()
# 移除订阅的网站
def removeSubscriptionWebsite(self,count=None):
for i in range(count):
self.find_el(self.removeButton).click()
# 确定订阅网站
def ensureSubscriptionWebsite(self):
self.find_el(self.ensureSubscriptionWebsite).click()
# 网站订阅-整个流程
def subscriptionWebsite(self):
......@@ -172,8 +192,40 @@ class BusinessKnowledgePage(BasePage):
self.find_el(self.ensureSubscriptionWebsite).click()
"""
上传文档
上传文档-三种方式
"""
class UploadDocumentHelper(BasePage):
def __init__(self):
super().__init__()
self.uploadDocumentButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[2]/div[1]') # 上传文档按钮
self.pasteTextButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[2]/div[2]') # 粘贴文本
self.importWebsiteButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[2]/div[3]') # 导入网站
self.clickUploadButton = (By.XPATH,'/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div[2]/div[2]/div[1]/div') # 点击上传
"""
方式一:上传文档
"""
def uploadDocumentControl(self,str_path):
time.sleep(1)
# for str_path in str_paths:
# time.sleep(1)
# self.find_el(self.uploadDocumentButton).click() # 点击 弹出弹窗
# logging.info(str_path)
# time.sleep(1)
# self.find_el(self.clickUploadButton).click() # 弹窗,选择文件
# self.select_document(str_path)
# time.sleep(1)
time.sleep(1)
self.find_el(self.uploadDocumentButton).click() # 点击 弹出弹窗
logging.info(str_path)
time.sleep(1)
self.find_el(self.clickUploadButton).click() # 弹窗,选择文件
self.select_document(str_path)
time.sleep(1)
"""
粘贴文本
......@@ -207,10 +259,21 @@ if __name__ == '__main__':
time.sleep(1)
businessKnowledge.entranceBusinessKnowledge()
time.sleep(1)
businessKnowledge.subscriptionWebsiteStart()
time.sleep(1)
businessKnowledge.subscriptionWebsiteFrequencySelect("三天更新一次")
time.sleep(1)
stry_paths = []
for i in range(15):
stry_paths.append('D:/Word/WORD'+str(i+1)+".docx")
businessKnowledge.upload_document_helper.uploadDocumentControl('D:/Word/WORD1.docx')
time.sleep(4)
# businessKnowledge.subscriptionWebsiteStart()
# time.sleep(1)
# businessKnowledge.subscriptionWebsiteFrequencySelect("三天更新一次")
# time.sleep(1)
# businessKnowledge.subscriptionWebsiteSelect(['出版商务周报官网','中国出版'])
# time.sleep(2)
# businessKnowledge.newFolderControl("文件夹名称188")
# time.sleep(2)
......
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