Esempio n. 1
0
class BrowserEngine(object):
    """
    定义一个浏览器引擎类,跟进browser_type的值,控制启动不同的浏览器,主要是IE,Firefox,Chrome
    """
    readConfig = ReadConfigFile()
    driver = None

    def set_driver(self, driver):
        BrowserEngine.driver = driver
        return BrowserEngine.driver

    browser_type = readConfig.Browser

    def get_browser(self):
        """
        通过if语句来初始化不同浏览器的启动,默认启动Chrome
        :return:
        """
        #全局driver
        if self.browser_type == 'Firefox':
            driver = webdriver.Firefox()
        elif self.browser_type == 'Chrome':
            driver = webdriver.Chrome()
        elif self.browser_type == 'IE':
            driver = webdriver.Ie()

        driver.maximize_window()
        driver.implicitly_wait(5)
        driver.get(self.readConfig.login_url)
        return BrowserEngine().set_driver(driver)
Esempio n. 2
0
class Login_Page(object):
    def __init__(self, driver, logger):
        self.driver = driver
        self.logger = logger

    company_name = 'company'
    account_name = 'account'
    password = '******'
    login_button = 'login_btn'

    readConfig = ReadConfigFile()

    def input_company(self):
        self.driver.find_element_by_name(self.company_name).send_keys(
            self.readConfig.U_company)

    def input_account(self):
        self.driver.find_element_by_name(self.account_name).send_keys(
            self.readConfig.U_account)

    def input_password(self):
        self.driver.find_element_by_name(self.password).send_keys(
            self.readConfig.U_password)

    def click_login(self):
        self.driver.find_element_by_class_name(self.login_button).click()

    def login_wait(self):
        try:
            tips = Web_Element_Wait(self.driver).web_element_wait(
                5, 1, By.CLASS_NAME, self.error_tips)
            self.logger.warning(tips)
        except:
            pass
class Read_Old_Export(object):
    def __init__(self, driver, logger):
        self.driver = driver
        self.logger = logger

    readConfig = ReadConfigFile()

    def test_old_export(self):
        file_path = '../data/read_file2.xlsx'
        sheet_name = 'old_export'
        #打开excel
        workbook = xlrd.open_workbook(file_path)
        DataSheet = workbook.sheet_by_name(sheet_name)
        rowNum = DataSheet.nrows  #sheet行数
        i = 0
        last_module_name = ''
        count = rowNum
        for i in range(rowNum):
            module = DataSheet.row_values(i)
            while '' in module:
                module.remove('')
            module_list = module
            #偶数行(通过link_text获取的模块链接)数据处理
            if (i % 2 == 0):
                #偶数行数据处理
                last_module_name = Os_Rows_Process(
                    module_list, self.driver, self.logger).os_rows_process()
            elif i % 2 == 1 and module_list:
                #奇数行、非空数据处理
                for j in range(len(module_list)):
                    get_module_name = Js_Rows_Process(
                        module_list, j, self.driver).js_rows_process()
                    #判断导出照片、导出
                    Juge_Old_Export(self.driver, self.logger,
                                    get_module_name).juge_old_export()
            else:
                #奇数行、空数据处理
                get_module_name = last_module_name
                #判断导出照片、导出
                Juge_Old_Export(self.driver, self.logger,
                                get_module_name).juge_old_export()
            i = i + 1
            if (i % 2 == 0):
                #页面刷新到首页
                self.driver.get(self.readConfig.f5_url)
        if (i % 2 == 1 and i == count):
            #处理最后一行为偶数的数据(即页面无table切换)
            Juge_Old_Export(self.driver, self.logger,
                            last_module_name).juge_old_export()
            #页面刷新到首页
            self.driver.get(self.readConfig.f5_url)
        if (i == 0 and i == count):
            #处理最后一行为偶数(0)的数据(即页面无table切换)
            Juge_Old_Export(self.driver, self.logger,
                            last_module_name).juge_old_export()
            #页面刷新到首页
            self.driver.get(self.readConfig.f5_url)
Esempio n. 4
0
class Importe(object):
    def __init__(self, driver, logger, module_name):
        self.driver = driver
        self.logger = logger
        self.module_name = module_name

    readConfig = ReadConfigFile()

    #import_module_name,导入文件应该以模块名命名规则
    #1、奇数列为空,即列表中无table切换,导入文件名为“最后一个link_text导航栏名”;
    # 2、奇数列不为空,即列表中有table切换,导入文件名为“切换的table的名字”)

    import_text = '导入'
    iframe_name = 'app_iframe'

    #文件上传按钮
    import_file_button1 = 'upload-file'
    import_file_button2 = 'file'

    #确认导入按钮
    confirm_button1 = 'OK-Button'
    confirm_button2 = 'save_button'

    #导入成功的提示
    import_success_message = '//*[@id="task_body"]/div/div[1]/span[1]'
    #导入成功后,返回上一级按钮
    import_success_button = '//*[@id="task_body"]/div/div[1]/a'

    #返回上级按钮
    return_button = 'btn_back'
    #导入失败的提示
    error_message = '没有可导入的文件、导入文件名错误、导入失败或请求超时'

    def test_old_importe(self):
        iee = IsElementExist(self.driver, self.logger)
        if iee.is_element_exist_partial_link_text(self.import_text):
            elements = self.driver.find_elements_by_partial_link_text(
                self.import_text)
            number = len(elements)

            for id in range(number):
                time.sleep(2)
                elements = self.driver.find_elements_by_partial_link_text(
                    self.import_text)

                text = elements[id].text
                elements[id].click()
                time.sleep(2)
                try:
                    self.driver.switch_to.frame(self.iframe_name)
                except:
                    pass
                file_path = os.path.dirname(os.getcwd()) + '\\data\\'
                try:
                    if number == 1:
                        import_file = file_path + self.module_name + '.xls'
                    else:
                        import_file = file_path + self.module_name + str(
                            id + 1) + '.xls'
                    self.driver.find_element_by_id(
                        self.import_file_button1).send_keys(import_file)
                    time.sleep(2)
                    self.driver.find_element_by_id(
                        self.confirm_button1).click()
                except:
                    pass
                try:
                    if number == 1:
                        import_file = file_path + self.module_name + '.zip'
                    else:
                        import_file = file_path + self.module_name + str(
                            id + 1) + '.zip'
                    self.driver.find_element_by_name(
                        self.import_file_button2).send_keys(import_file)
                    time.sleep(2)
                    self.driver.find_element_by_id(
                        self.confirm_button2).click()
                except:
                    pass

                try:
                    #webdriver显示等待:WebDriverWait
                    message = WebDriverWait(self.driver, 60, 3, None).until(
                        EC.presence_of_element_located(
                            (By.XPATH, self.import_success_message)))
                    tips = message.text
                    self.logger.info(self.module_name + '-->' + text + ':' +
                                     tips)
                    time.sleep(1)
                    self.driver.find_element_by_xpath(
                        self.import_success_button).click()
                    time.sleep(1)
                    self.driver.find_element_by_class_name(
                        self.return_button).click()
                except:
                    self.logger.warning(self.module_name + self.error_message)
                    self.driver.get(self.readConfig.f5_url)
        else:
            pass

    def test_new_importe(self):

        iee = IsElementExist(self.driver, self.logger)

        if iee.is_element_exist_partial_link_text(self.import_text):
            elements = self.driver.find_elements_by_partial_link_text(
                self.import_text)
            number = len(elements)
            print(number)
            for id in range(number):
                elements = self.driver.find_elements_by_partial_link_text(
                    self.import_text)
                text = elements[id].text
                elements[id].click()
                time.sleep(2)
                try:
                    self.driver.switch_to.frame(self.iframe_name)
                except:
                    pass

                try:
                    file_path = os.path.dirname(os.getcwd()) + '\\data\\'
                    if number == 1:
                        import_file = file_path + self.module_name + '.xls'
                    else:
                        import_file = file_path + self.module_name + str(
                            id + 1) + '.xls'
                    self.driver.find_element_by_id(
                        self.import_file_button1).send_keys(import_file)
                    time.sleep(2)
                    self.driver.find_element_by_id(
                        self.confirm_button1).click()

                    #webdriver显示等待:WebDriverWait
                    message = WebDriverWait(self.driver, 60, 3, None).until(
                        EC.presence_of_element_located(
                            (By.XPATH, self.import_success_message)))
                    tips = message.text
                    self.logger.info(self.module_name + '-->' + text + ':' +
                                     tips)
                    time.sleep(1)
                    self.driver.find_element_by_xpath(
                        self.import_success_button).click()
                    time.sleep(1)
                    self.driver.find_element_by_class_name(
                        self.return_button).click()
                except:
                    self.logger.warning(self.module_name + self.error_message)
                    self.driver.get(self.readConfig.f5_url)
        else:
            pass
Esempio n. 5
0
class Read_New_Import(object):
    def __init__(self, driver, logger):
        self.driver = driver
        self.logger = logger

    readConfig = ReadConfigFile()

    def test_new_import(self):
        file_path = '../data/read_file2.xlsx'
        sheet_name = 'new_import'
        #打开excel
        workbook = xlrd.open_workbook(file_path)
        DataSheet = workbook.sheet_by_name(sheet_name)
        rowNum = DataSheet.nrows  #sheet行数
        i = 0
        last_module_name = ''
        count = rowNum
        for i in range(rowNum):
            module = DataSheet.row_values(i)
            while '' in module:
                module.remove('')
            module_list = module
            #偶数行(通过link_text获取的模块链接)数据处理
            if (i % 2 == 0):
                #偶数行数据处理
                last_module_name = Os_Rows_Process(
                    module_list, self.driver,
                    self.logger).os_rows_process_new()
            elif i % 2 == 1 and module_list:
                #奇数行、非空数据处
                num = len(module_list)
                for j in range(num):
                    get_module_name = Js_Rows_Process(
                        module_list, j, self.driver).js_rows_process_new()
                    #导入
                    Importe(self.driver, self.logger,
                            get_module_name).test_new_importe()
                    #跳出iframe表单
                    try:
                        self.driver.switch_to.default_content()
                    except:
                        pass
                self.driver.get(self.readConfig.f5_url)
            else:
                #奇数行、空数据处理
                get_module_name = last_module_name
                #导入
                Importe(self.driver, self.logger,
                        get_module_name).test_new_importe()
            i = i + 1
            if (i % 2 == 0):
                #页面刷新到首页
                self.driver.get(self.readConfig.f5_url)
        if (i % 2 == 1 and i == count):
            #处理最后一行为偶数的数据(即页面无table切换)
            Importe(self.driver, self.logger,
                    last_module_name).test_new_importe()
            #页面刷新到首页
            self.driver.get(self.readConfig.f5_url)
        if (i == 0 and i == count):
            #处理最后一行为偶数(0)的数据(即页面无table切换)
            Importe(self.driver, self.logger,
                    last_module_name).test_new_importe()
            #页面刷新到首页
            self.driver.get(self.readConfig.f5_url)