monitor_subtask_status.py
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
# @Time : 2020/12/17 9:17
# @Author : Young Lee
# @Email : young_lee2017@163.com
import time
def monitor_subtask_status(driver, task_name, excluded_list=None):
"""子任务下发状态监控
:param task_name: 大任务名称
:param excluded_list: 要排除的子任务ID列表
:return: 返回subtasks_status [subtask_name, subtask_status, subtask_id]
"""
if excluded_list is None:
excluded_list = []
print("监测子任务状态...")
subtasks_status = []
common_xpath = f"//div[@class='content']/div[2]//tbody/tr/td[3]/div[text()='{task_name}']"
expanded_bar = f"{common_xpath}/../preceding-sibling::td[2]/div/div"
subtasks_td = f"{common_xpath}/../../following-sibling::tr[1]/td/div"
if "el-table__expand-icon--expanded" not in driver.find_element_by_xpath(expanded_bar).get_attribute("class"):
driver.find_element_by_xpath(expanded_bar).click()
time.sleep(1)
if driver.find_element_by_xpath(subtasks_td).get_attribute("class") == "notaskinfo":
return
subtasks_ele = driver.find_elements_by_xpath(subtasks_td)
for subtask_ele in subtasks_ele:
subtask_id = subtask_ele.find_element_by_xpath("./span[@class='label'][text()='任务ID']/following-sibling::span[1]").text
if subtask_id not in excluded_list:
subtask_name = subtask_ele.find_element_by_xpath("./span[@class='label'][text()='视频源文件']/following-sibling::span[1]").text
subtask_status = subtask_ele.find_element_by_css_selector(".taskstatus>span").text
subtasks_status.append([subtask_name, subtask_status, subtask_id])
driver.find_element_by_xpath(expanded_bar).click()
return subtasks_status
if __name__ == '__main__':
from unitinit import *
from login import login_fx
from jumppage import jump_page
login_fx(driver, login_url, user, passwd)
jump_page(driver, '任务管理', '任务设置')
monitor_subtask_status(driver, '测试任务wDShB')