monitor_subtask_status.py 1.99 KB
# -*- 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')