Commit ff54ef25 by Administrator

2.88提交

parent d2bc4ec8
...@@ -21,16 +21,14 @@ class BasePage: ...@@ -21,16 +21,14 @@ class BasePage:
# 查找元素 # 查找元素
def find_el(self, loc, time=10, fre=0.5): def find_el(self, loc, time=10, fre=0.5):
ele = WebDriverWait(self.driver, time, fre).until(lambda x: x.find_element(*loc)) ele = WebDriverWait(self.driver, time, fre).until(lambda x: x.find_element(*loc))
# wait = WebDriverWait(self.driver, time)
# ele = wait.until(
# EC.element_to_be_clickable(loc))
return ele return ele
def find_son_elements(self, ele, loc):
elements = ele.find_elements(*loc)
return elements
# 输入文本内容 # 输入文本内容
def input_text(self, loc, value): def input_text_by_loc(self, loc, value):
# 定义该元素对于的文本 # 定义该元素对于的文本
ele = self.find_el(loc) ele = self.find_el(loc)
# 先清空 # 先清空
...@@ -38,6 +36,13 @@ class BasePage: ...@@ -38,6 +36,13 @@ class BasePage:
# 再输入 # 再输入
ele.send_keys(value) ele.send_keys(value)
def input_text_by_ele(self, ele, value):
# 定义该元素对于的文本
# 先清空
time.sleep(1)
ele.clear()
# 再输入
ele.send_keys(value)
# 滚动条 # 滚动条
def scroll(self, x, y): def scroll(self, x, y):
...@@ -86,7 +91,7 @@ class BasePage: ...@@ -86,7 +91,7 @@ class BasePage:
console_handler = logging.StreamHandler() console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO) console_handler.setLevel(logging.INFO)
# 创建一个处理程序,用于输出到文件 # 创建一个处理程序,用于输出到文件
file_handler = logging.FileHandler('business_knowledge.log') file_handler = logging.FileHandler('business_knowledge1.log')
file_handler.setLevel(logging.INFO) file_handler.setLevel(logging.INFO)
# 创建一个格式化器,用于设置日志格式 # 创建一个格式化器,用于设置日志格式
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
......
...@@ -9,18 +9,18 @@ from selenium.webdriver.common.by import By ...@@ -9,18 +9,18 @@ from selenium.webdriver.common.by import By
from BasePage.BasePage import BasePage from BasePage.BasePage import BasePage
from Pages.login_page import LoginPage from Pages.login_page import LoginPage
from Util.Util import DriverUtils from Util.Util import DriverUtils
from selenium.webdriver.remote.webelement import WebElement
""" """
企业知识库--页面操作 企业知识库--页面操作
""" """
class BusinessKnowledgePage(BasePage): class BusinessKnowledgePage(BasePage):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.upload_document_helper = UploadDocumentHelper() self.upload_document_helper = UploadDocumentHelper()
self.document_list_helper = DocumentListControlHelper()
self.ai_editing = (By.XPATH, '//*[@id="App"]/div/header/div[2]/div[2]') # AI编辑工作室按钮 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.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') # 返回 self.quit = (By.XPATH, '//*[@id="App"]/div/section/div[1]/div[1]/div[1]/button/span') # 返回
...@@ -51,6 +51,7 @@ class BusinessKnowledgePage(BasePage): ...@@ -51,6 +51,7 @@ class BusinessKnowledgePage(BasePage):
# 去除 # 去除
self.removeButton = (By.XPATH, '//*[@id="website"]/div/div[2]/div[2]/div[1]/div/div[1]/div[2]') self.removeButton = (By.XPATH, '//*[@id="website"]/div/div[2]/div[2]/div[1]/div/div[1]/div[2]')
""" """
通用 通用
""" """
...@@ -74,7 +75,7 @@ class BusinessKnowledgePage(BasePage): ...@@ -74,7 +75,7 @@ class BusinessKnowledgePage(BasePage):
# 新建文件夹操作 输入长度测试点 # 新建文件夹操作 输入长度测试点
def newFolderControl(self, folderNameInput=None): def newFolderControl(self, folderNameInput=None):
self.find_el(self.newFolder).click() # 弹出输入框 self.find_el(self.newFolder).click() # 弹出输入框
self.input_text(self.folderName, folderNameInput) # 输入文件夹名称 self.input_text_by_loc(self.folderName, folderNameInput) # 输入文件夹名称
self.find_el(self.ensure).click() # 点击确认 self.find_el(self.ensure).click() # 点击确认
# 删除文件夹 # 删除文件夹
...@@ -90,7 +91,7 @@ class BusinessKnowledgePage(BasePage): ...@@ -90,7 +91,7 @@ class BusinessKnowledgePage(BasePage):
self.find_el(self.more).click() # 点击更多 self.find_el(self.more).click() # 点击更多
time.sleep(1) time.sleep(1)
self.find_el(self.updateFolderName).click() # 弹出修改弹框 self.find_el(self.updateFolderName).click() # 弹出修改弹框
self.input_text(self.folderName, updateFolderName) self.input_text_by_loc(self.folderName, updateFolderName)
time.sleep(1) time.sleep(1)
self.find_el(self.ensureDelete).click() # 点击确认 self.find_el(self.ensureDelete).click() # 点击确认
...@@ -107,7 +108,7 @@ class BusinessKnowledgePage(BasePage): ...@@ -107,7 +108,7 @@ class BusinessKnowledgePage(BasePage):
# 搜索 # 搜索
def searchDocument(self, keyName=None): def searchDocument(self, keyName=None):
self.input_text(self.searchInputText, keyName) self.input_text_by_loc(self.searchInputText, keyName)
time.sleep(2) time.sleep(2)
""" """
...@@ -191,6 +192,8 @@ class BusinessKnowledgePage(BasePage): ...@@ -191,6 +192,8 @@ class BusinessKnowledgePage(BasePage):
# 确定订阅 # 确定订阅
self.find_el(self.ensureSubscriptionWebsite).click() self.find_el(self.ensureSubscriptionWebsite).click()
""" """
上传文档-三种方式 上传文档-三种方式
""" """
...@@ -208,14 +211,14 @@ class UploadDocumentHelper(BasePage): ...@@ -208,14 +211,14 @@ class UploadDocumentHelper(BasePage):
self.ensureButton = (By.XPATH,'/html/body/div[3]/div/div[2]/div/div[2]/div[3]/div/button[2]') # 确定 self.ensureButton = (By.XPATH,'/html/body/div[3]/div/div[2]/div/div[2]/div[3]/div/button[2]') # 确定
self.urlText = (By.XPATH,'//*[@id="url"]') self.urlText = (By.XPATH,'//*[@id="url"]')
self.getContentButton = (By.CLASS_NAME,'ant-btn ant-btn-primaryx') self.getContentButton = (By.CLASS_NAME,'ant-btn ant-btn-primary')
""" """
方式一:上传文档 方式一:上传文档
文档类型 文档类型
文档大小 文档大小
""" """
def uploadDocumentControl(self,str_paths): def uploadDocumentControl(self,str_paths=None):
time.sleep(1) time.sleep(1)
for str_path in str_paths: for str_path in str_paths:
...@@ -230,19 +233,19 @@ class UploadDocumentHelper(BasePage): ...@@ -230,19 +233,19 @@ class UploadDocumentHelper(BasePage):
""" """
粘贴文本 粘贴文本
""" """
def pasteTextControl(self,title,content): def pasteTextControl(self,title=None,content=None):
self.find_el(self.pasteTextButton).click() self.find_el(self.pasteTextButton).click()
self.input_text(self.titleText,title) self.input_text_by_loc(self.titleText,title)
self.input_text(self.contentText,content) self.input_text_by_loc(self.contentText,content)
self.find_el(self.ensureButton).click() self.find_el(self.ensureButton).click()
""" """
导入网站 导入网站
""" """
def uploadUrlControl(self,url_link): def uploadUrlControl(self,url_link=None):
self.find_el(self.importWebsiteButton).click() self.find_el(self.importWebsiteButton).click()
time.sleep(1) time.sleep(1)
self.input_text(self.urlText,url_link) self.input_text_by_loc(self.urlText,url_link)
time.sleep(2) time.sleep(2)
button = self.find_el(self.getContentButton) button = self.find_el(self.getContentButton)
# 使用 ActionChains 将鼠标移动到按钮上再点击 # 使用 ActionChains 将鼠标移动到按钮上再点击
...@@ -251,20 +254,155 @@ class UploadDocumentHelper(BasePage): ...@@ -251,20 +254,155 @@ class UploadDocumentHelper(BasePage):
# 使用JavaScript将焦点移动到页面其他元素,使文本域失去焦点 # 使用JavaScript将焦点移动到页面其他元素,使文本域失去焦点
# driver.execute_script("arguments[0].blur();", text_area) # driver.execute_script("arguments[0].blur();", text_area)
time.sleep(2) time.sleep(2)
time.sleep(1)
"""
文档列表操作
"""
"""
文档列表操作 对话操作 删除操作 更多【修改名称、复制、移动到】
"""
class DocumentListControlHelper(BasePage):
def __init__(self):
super().__init__()
# 获取文档内容--此处获取的是一页的全部列表
self.documentListDiv = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody')
self.documentDiv = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody/tr')
self.documentDeleteButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody//button[.//span[text()="删除"]]')
self.modelFooter = (By.CLASS_NAME,"ant-modal-footer") # 对于此块代码 无法通过xpath获取
self.modalBody = (By.CLASS_NAME,"ant-modal-body") # 对于此块代码 无法通过xpath获取
self.quit = (By.XPATH, '//*[@id="App"]/div/section/div[1]/div[1]/div[1]/button/span') # 返回
self.statusStudy = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody/tr/td[3]/div')
self.documentDialogueButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody//span[text()="对话"]')
self.moreButton = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody/tr[1]/td[5]/div/span/label/button')
# self.documents = self.find_son_elements(self.find_el(self.documentListDiv), self.documentDiv)
self.controlList = (By.XPATH,'//*[@id="App"]/div/section/div[1]/div[2]/div/div/div[2]/div/div[2]/div[3]/div/div/div/div/div/div/div/table/tbody/tr[1]/td[5]/div/span/ul')
# 删除
def documentListDeleteControl(self,count=None):
documents = self.find_son_elements(self.find_el(self.documentListDiv), self.documentDiv)
documents_length = len(documents)
if count <= documents_length:
res_count = count
else:
res_count = documents_length
for i in range(res_count):
buttons = self.find_son_elements(self.find_el(self.documentListDiv),self.documentDeleteButton)
time.sleep(1)
buttons[0].click()
time.sleep(2)
self.find_el(self.modelFooter).find_elements(By.TAG_NAME,"button")[1].click()
logging.info("--------成功删除一条文档记录---------")
time.sleep(1)
# 对话
def documentListDialogueControl(self,count=None):
statuses = self.find_son_elements(self.find_el(self.documentListDiv),self.statusStudy)
documents = self.find_son_elements(self.find_el(self.documentListDiv),self.documentDiv)
documents_length = len(documents)
if count > documents_length:
logging.info(f"--------超过此页展示的文档---------")
return
i = 0
for statusDiv,document in zip(statuses,documents):
i = i + 1
if count == i:
status_value = statusDiv.get_attribute("class")
logging.info(f"--------第{i}文档状态为:{status_value}---------")
if status_value.find("success") != -1: # index / in
logging.info("--------包含success-----------------") # success
document.find_element(By.XPATH, './/span[text()="对话"]').click() # 点击进入文档对话 .代表当前路径 //代表隔代
time.sleep(2)
self.find_el(self.quit).click()
time.sleep(2)
logging.info("-------------完成------------") # success
return
else:
logging.info("--------不包含success 不可点击对话--------") # fail
return
# 更多
def more_control(self, document=None, type=None):
if document:
document.find_element(By.XPATH, './/span[text()="更多"]').click()
time.sleep(2)
else:
logging.info("------------点击第一个更多------------")
self.find_el(self.moreButton).click()
if type == 1: # 修改名称
document.find_element(By.XPATH, './/ul/li[1]/div').click()
elif type == 2: # 复制
document.find_element(By.XPATH, './/ul/li[2]/div').click()
elif type == 3: # 移动
document.find_element(By.XPATH, './/ul/li[3]/div').click()
time.sleep(2)
# 修改名称
def update_document_name_control(self,new_document_name=None,count=None):
time.sleep(3)
statuses = self.find_son_elements(self.find_el(self.documentListDiv), self.statusStudy)
documents = self.find_son_elements(self.find_el(self.documentListDiv), self.documentDiv)
i = 0
for status_div,document in zip(statuses,documents):
i = i + 1
if count == i :
status_value = status_div.get_attribute("class")
if status_value.find("success") != -1:
logging.info(f"-------------文档为success状态了--------")
self.more_control(document,1)
logging.info(f"-------------第{i}个文档被点击更多-修改名称了--------")
time.sleep(1)
input_text = self.find_el(self.modalBody).find_element(By.XPATH,".//input[@placeholder='请输入文件名称']")
self.input_text_by_ele(input_text,new_document_name)
time.sleep(1)
self.find_el(self.modelFooter).find_elements(By.TAG_NAME, "button")[1].click()
logging.info(f"-------------第{i}个文档修改名称完成--------")
time.sleep(2)
else:
logging.info(f"-------------不可点击 状态为fail 无更多按钮--------")
# 复制到/移动到 type 2 3
def copy_document_control(self, count=None, type=None, folder_name=None):
time.sleep(3)
statuses = self.find_son_elements(self.find_el(self.documentListDiv), self.statusStudy)
documents = self.find_son_elements(self.find_el(self.documentListDiv), self.documentDiv)
i = 0
for status_div, document in zip(statuses, documents):
i = i + 1
if count == i:
status_value = status_div.get_attribute("class")
if status_value.find("success") != -1:
logging.info(f"-------------文档为success状态了--------")
self.more_control(document, type)
logging.info(f"-------------第{i}个文档被点击更多-复制/移动至了--------")
time.sleep(1)
catalog_items = self.find_el(self.modalBody).find_elements(By.CLASS_NAME,"Catalog-List")
flog = None
for catalog_item in catalog_items: # type: WebElement
reality_text_button = catalog_item.find_element(By.XPATH,'.//span')
reality_text = reality_text_button.get_attribute('innerText')
logging.info(f"-------------真实的文件夹名:{reality_text}--------")
if reality_text == folder_name: # 如果相同说明是需要复制到的文件夹
reality_text_button.click() # 点击 选择
time.sleep(1)
self.find_el(self.modelFooter).find_elements(By.TAG_NAME, "button")[1].click()
flog = True
time.sleep(2)
if not flog:
logging.info(f"-------------没有此文件夹名称:{folder_name}--------")
break
logging.info(f"-------------第{i}个文档复制/移动完成--------")
time.sleep(2)
else:
logging.info(f"-------------不可点击 状态为fail 无更多按钮--------")
""" """
文档对话 文档对话
""" """
class DocumentDialogueHelper(BasePage):
def __init__(self):
super().__init__()
"""
文件夹对话
"""
if __name__ == '__main__': if __name__ == '__main__':
...@@ -278,8 +416,12 @@ if __name__ == '__main__': ...@@ -278,8 +416,12 @@ if __name__ == '__main__':
time.sleep(1) time.sleep(1)
businessKnowledge.entranceBusinessKnowledge() businessKnowledge.entranceBusinessKnowledge()
time.sleep(1) time.sleep(1)
businessKnowledge.upload_document_helper.uploadUrlControl("https://blog.csdn.net/FezZZZ/article/details/120878765") businessKnowledge.document_list_helper.copy_document_control(2,"团队共享知识库")
# businessKnowledge.document_list_helper.documentListDialogueControl(2)
# businessKnowledge.document_list_helper.documentListControl(3)
time.sleep(2) time.sleep(2)
# businessKnowledge.upload_document_helper.uploadUrlControl("https://blog.csdn.net/FezZZZ/article/details/120878765")
# time.sleep(2)
# businessKnowledge.upload_document_helper.pasteTextControl("标题","内容内内容内内容内内容内内容内内容内内容内内容内内容" # businessKnowledge.upload_document_helper.pasteTextControl("标题","内容内内容内内容内内容内内容内内容内内容内内容内内容"
# "内内容内内容内内容内内容内内容内内容内内容内内容内内容内" # "内内容内内容内内容内内容内内容内内容内内容内内容内内容内"
......
...@@ -20,8 +20,8 @@ class LoginPage(BasePage): ...@@ -20,8 +20,8 @@ class LoginPage(BasePage):
self.login_click = (By.XPATH,'//*[@id="App"]/div/div/div[1]/div[3]/div/div/div[3]/form/div[4]/div/div/div/div/button') self.login_click = (By.XPATH,'//*[@id="App"]/div/div/div[1]/div[3]/div/div/div[3]/form/div[4]/div/div/div/div/button')
def login_username(self,username=None,password=None): def login_username(self,username=None,password=None):
self.input_text(self.username,username) self.input_text_by_loc(self.username,username)
self.input_text(self.password,password) self.input_text_by_loc(self.password,password)
self.find_el(self.login_click).click() self.find_el(self.login_click).click()
# driver.find_element(By.XPATH, "//*[@id='App']/div/div/div[1]/span").click() # driver.find_element(By.XPATH, "//*[@id='App']/div/div/div[1]/span").click()
# driver.find_element(By.XPATH, "//*[@id='App']/div/div/div[2]/ul/li[2]/ul/li[1]").click() # driver.find_element(By.XPATH, "//*[@id='App']/div/div/div[2]/ul/li[2]/ul/li[1]").click()
......
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