def attendance_machine_login(driver): into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() into_two_level(driver, '考勤机设置') get_elements( driver, ('xpath', "//i[@class='glyphicon glyphicon-facetime-video']"))[0].click() # 得到selenium打开的浏览器的所有句柄 all_hand = driver.window_handles # 切换句柄 driver.switch_to_window(all_hand[-1]) get_element(driver, ('id', 'firstname')).clear() sleep(0.5) get_element(driver, ('id', 'firstname')).send_keys('hpface固定ipc测试') get_element(driver, ('id', 'lastname')).send_keys('123456') get_element(driver, ('xpath', "//button[@class='btn btn-primary']")).click() sleep(0.5) if get_element(driver, ('id', 'LAY_demo2')).text == '成功:订阅': pass else: bug_photo(driver) assert False driver.close() driver.switch_to_window(all_hand[0])
def project_delay(driver): try: into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() sleep(0.5) get_element(driver, ('xpath', "//button[contains(text(),'项目延期')]")).click() sleep(1) num = 300 setting_input_time(driver) get_element(driver, ('xpath', "//input[@placeholder='选择日期需大于原总包合同结束时间']")).send_keys(get_future_date(num)) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() sleep(0.5) get_element(driver, ('id', 'success')).click() while 1: if is_element_present(driver, ('xpath', "//div[contains(text(),'延期时间必须大于总包合同的竣工日期')]")): sleep(0.1) get_element(driver, ('xpath', "//span[@class='layui-layer-setwin']/a")).click() get_element(driver, ('xpath', "//input[@placeholder='选择日期需大于原总包合同结束时间']")).clear() num += 20 get_element(driver, ('xpath', "//input[@placeholder='选择日期需大于原总包合同结束时间']")).send_keys(get_future_date(num)) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() sleep(0.5) get_element(driver, ('id', 'success')).click() else: break except Exception as e: print(e) bug_photo(driver) assert False
def workers_registration(driver, mobile, password): try: get_element(driver, ('accessibility_id', '新用户注册 ')).click() get_element(driver, ('accessibility_id', '我是工人')).click() get_element( driver, ('xpath', "//android.widget.EditText[@text='请输入正确的帐号(手机号)']" )).send_keys(mobile) get_element( driver, ('xpath', "//android.widget.Button[@content-desc='点击获取 ']")).click() get_element( driver, ('xpath', "//android.widget.EditText[@text='请输入校验码']")).send_keys('11111') get_element(driver, ('xpath', "//android.widget.EditText[@text='••••••••••']" )).send_keys(password) get_element(driver, ('xpath', "//android.widget.EditText[@text='•••••••••']" )).send_keys(password) except Exception as e: print(e) bug_photo(driver) assert False
def delete_area(driver): # 删除区域 into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() into_two_level(driver, '项目设置') # 区域个数 project_area_elements = "//div[@class='select-area-util-item select-area-util-area']" new_area_name = [] number = int(len(get_elements(driver, ('xpath', project_area_elements)))) for i in range(number): new_area_name.insert( i, get_elements(driver, ('xpath', project_area_elements))[i].text) project_element = "//div[@class='select-area-util-item select-area-util-area'and contains(text(),'%s')]" % \ new_area_name[number - 1] delete_project_element = project_element + "/div/div[3]" ActionChains(driver).move_to_element( get_element(driver, ('xpath', project_element))).perform() sleep(1) get_element(driver, ('xpath', delete_project_element)).click() get_element(driver, ('id', 'success')).click() sleep(2) new_number = int( len(get_elements(driver, ('xpath', project_area_elements)))) print(new_number, number) sleep(2) if number == int(new_number + 1): print('删除区域成功') else: bug_photo(driver) assert False
def workers_review(driver, worker_name): try: into_one_level(driver, "任务面板") sleep(0.5) into_two_level(driver, "我的任务") get_element(driver, ('xpath', "//button[contains(text(),'签订用工合同')]")).click() get_element( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr[1]/td[9]/a")).click() get_element( driver, ('xpath', "//button[@class='btn btn-sm btn-success']")).click() get_element(driver, ('xpath', "//textarea")).send_keys('s') get_element(driver, ('xpath', "//a[@class='layui-layer-btn0']")).click() sleep(10) driver.find_element_by_xpath("//a[contains(text(),'我审核过的')]").click() sleep(2) worker_name += '用工合同签订审核' element_len = get_elements( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr")) title_text = [] for i in range(1, len(element_len)): element = "//*[@id='task-mytask-table']/tbody/tr[%d]/td[4]" % i text = get_element(driver, ('xpath', element)).text title_text.insert(i, text) print(title_text) information = '用工合同签订失败' assert worker_name in title_text, "%s" % information except Exception as e: print(e) bug_photo(driver) assert False
def verify_worker_exists(driver, workers_name): # 平台运维验证工人是否存在 try: into_one_level(driver, '运维面板') sleep(0.5) into_two_level(driver, '注册用户管理') # 查询工人姓名 get_element( driver, ('xpath', "//input[@placeholder='工人姓名']")).send_keys(workers_name) # 搜索 get_element(driver, ('xpath', "//button[contains(text(),'搜索')]")).click() if is_element_present_3s(driver, ('xpath', "//tbody/tr/td[2]/a"), 3): get_element(driver, ('xpath', "//tbody/tr/td[2]/a")).click() sleep(1) role = get_element( driver, ('xpath', "//*[@id='basic']/div/div[2]/div[4]/div/span")).text print(role) assert role == '签约工人' else: print('签订终止合同工人的合同失败') assert False sleep(1.5) except Exception as e: print(e) bug_photo(driver) assert False
def change_workman_contract_date(driver): try: now_date = get_future_date(90) into_one_level(driver, "任务面板") sleep(1) into_two_level(driver, "发起申请") get_element(driver, ('xpath', "//div[contains(text(),'用工合同期限修改')]")).click() get_elements( driver, ('xpath', "//input[@class='form-control input-sm']"))[0].click() get_element(driver, ('id', 'realname')).send_keys('曹永') get_element(driver, ('id', 'realsearch')).click() sleep(0.5) get_element( driver, ('xpath', "//*[@id='lay-user-f']/tbody/tr/td[1]/input")).click() get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() sleep(0.5) setting_input_time(driver) get_element( driver, ('xpath', "//input[@placeholder='请选择日期']")).send_keys(now_date) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() get_element(driver, ('id', "success")).click() assert is_element_present(driver, ( 'xpath', "//div[contains(text(),'成功')]/i[@class='layui-layer-ico layui-layer-ico1' ]" )) except Exception as e: print(e) bug_photo(driver) assert False
def request_for_overtime(driver, remark, file_path): """ # 加班申请 :param driver: :param remark:备注信息 :param file_path: 附件路径 :return: """ into_one_level(driver, '任务面板') sleep(1) into_one_level(driver, '发起申请') get_element(driver, ('xpath', "//div[contains(text(),'加班申请')]")).click() get_element(driver, ('id', 'leaveAdd')).click() sleep(0.5) element = "//*[@id='lay-user-f']/tbody/tr" for i in range(0, len(get_elements(driver, ('xpath', element))), 2): elements = "//tr[@data-index='%s']/td/input" % i get_element(driver, ('xpath', elements)).click() sleep(0.1) get_element(driver, ('xpath', "//button[contains(text(),'添加至已选')]")).click() get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() setting_input_time(driver) get_elements(driver, ('xpath', "//div[@class='col-sm-6']/input"))[0].send_keys( get_now_dates()) get_element( driver, ('xpath', "//input[@placeholder='选择时间需小于加班结束时间']")).send_keys('20:00') get_element( driver, ('xpath', "//input[@placeholder='选择时间需大于加班开始时间']")).send_keys('21:00') overtime_type = "//select[@class='form-control input-sm']/option[%s]" % str( random.randint(1, 2)) get_element(driver, ('xpath', overtime_type)).click() get_element( driver, ('xpath', "//textarea[@class='form-control']")).send_keys(remark) get_element( driver, ('xpath', "//div[@id='uploadFile']/input")).send_keys(file_path) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() get_element(driver, ('id', "success")).click() sleep(0.5) into_one_level(driver, '我的任务') get_element(driver, ('xpath', "//a[contains(text(),'我发起的')]")).click() try: get_element(driver, ('xpath', "//button[contains(text(),'加班工作流')]")).click() get_element( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr[1]/td[8]/a")).click() assert_element = "//div[@class='tsk-inp col-xs-8' and contains(text(),'%s')]" % remark assert is_element_present(driver, ('xpath', assert_element)) except Exception as e: print(e) bug_photo(driver) assert False
def batch_add_workman(driver, file_path, remark): # 批量发起请假申请 """ :param driver: :param file_path: 附件路径 :param remark: 备注信息 :return: """ into_one_level(driver, '任务面板') sleep(1) into_one_level(driver, '发起申请') get_element(driver, ('xpath', "//div[contains(text(),'请假申请')]")).click() sleep(0.5) # 请假类型 element = "//select[@class='form-control input-sm']/option[%s]" % str( random.randint(1, 7)) get_element(driver, ('xpath', element)).click() get_element(driver, ('id', 'leaveAdd')).click() sleep(0.5) for i in range(0, 3): elements = "//tr[@data-index='%s']/td/input" % i get_element(driver, ('xpath', elements)).click() sleep(0.1) get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() setting_input_time(driver) get_elements(driver, ('xpath', "//input[@placeholder='选择日期在合同范围内']"))[0].send_keys( get_now_dates()) get_elements(driver, ('xpath', "//input[@placeholder='选择日期在合同范围内']"))[1].send_keys( get_tomorrow_dates()) get_element( driver, ('xpath', "//textarea[@class='form-control']")).send_keys(remark) get_element( driver, ('xpath', "//div[@id='uploadFile']/input")).send_keys(file_path) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() get_element(driver, ('id', "success")).click() sleep(1.5) into_one_level(driver, '我的任务') get_element(driver, ('xpath', "//a[contains(text(),'我发起的')]")).click() try: get_element(driver, ('xpath', "//button[contains(text(),'请假工作流')]")).click() sleep(3) get_element( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr[1]/td[8]/a")).click() assert_element = "//div[@class='tsk-inp col-xs-8' and contains(text(),'%s')]" % remark is_element_present(driver, ('xpath', assert_element)) except Exception as e: print(e) print('工人已经存在请假工作流,无法继续发起') bug_photo(driver) assert False
def general_contract(driver, contract_name, contract_awarding, contracting, project_name): """ :param driver: :param contract_name:合同名称 :param contract_awarding: 发包方 :param contracting: 总承包方 :param project_name: 工程名称 :return: """ driver.implicitly_wait(5) try: into_one_level(driver, '任务面板') sleep(0.5) into_two_level(driver, '发起申请') # WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath("//div[contains(text(),'新建总包合同')")).click() driver.find_element_by_xpath("//div[contains(text(),'新建总包合同')]").click() # get_element(driver, ('XPATH', "//div[contains(text(),'新建总包合同'")).click() sleep(0.5) driver.find_element_by_xpath("//input[@placeholder='请输入合同名称']").send_keys(contract_name) sleep(0.5) # 发包方 get_element(driver, ('id', 'select2-fbfName-container')).click() get_element(driver, ('xpath', "//input[@type='search']")).send_keys(contract_awarding) sleep(0.5) get_element(driver, ('xpath', "//input[@type='search']")).send_keys(Keys.ENTER) # 承包方 get_element(driver, ('id', "select2-cbfName-container")).click() driver.find_element_by_xpath("//input[@type='search']").send_keys(contracting) sleep(0.5) driver.find_element_by_xpath("//input[@type='search']").send_keys(Keys.ENTER) driver.find_element_by_xpath("//input[@placeholder='请输入工程名称']").send_keys(project_name) select_city(driver) driver.find_element_by_xpath("//input[@placeholder='请输入工程详细地址']").send_keys('南京路168号') driver.find_element_by_xpath("//input[@placeholder='类目(必填)']").send_keys('建筑') driver.find_element_by_xpath("//input[@placeholder='年份(必填)']").click() driver.find_element_by_xpath("//span[@class='year active']").click() driver.find_element_by_xpath("//input[@placeholder='编号(必填)']").send_keys(random.randint(10000, 99999)) project_information = '土方开挖,土方回填,钢筋工程,模板工程,混凝土工程,砌体工程,装饰装修工程等' contract_scope = "售楼部的美女,工程部的汉,项目部的光棍满街转!财务的花,预算的草,施工队的和尚到处跑!食堂的饭,宿舍的床,搞工程的女人吓死郎!" driver.find_elements_by_xpath("//textarea[@placeholder='必填']")[0].send_keys(project_information) driver.find_elements_by_xpath("//textarea[@placeholder='必填']")[1].send_keys(contract_scope) setting_input_time(driver) driver.find_element_by_xpath("//input[@placeholder='选择日期不得晚于计划竣工日期']").send_keys(get_now_dates()) driver.find_element_by_xpath("//input[@placeholder='选择日期不得早于今天']").send_keys(get_future_date(300)) driver.find_elements_by_xpath("//input[@placeholder='必填']")[0].send_keys(random.randint(100, 200)) driver.find_elements_by_xpath("//input[@placeholder='必填']")[1].send_keys(random.randint(100000, 999999)) driver.find_element_by_xpath("//input[@placeholder='请输入项目经理姓名']").send_keys("暂无") driver.find_element_by_xpath("//input[@placeholder='选择日期不得晚于当前日期']").send_keys(get_now_dates()) select_city_choice(driver) driver.find_elements_by_xpath("//input[@placeholder='必填']")[2].send_keys("南京路256号") driver.find_element_by_xpath("//button[@type='submit']").click() print(get_element(driver, ('id', "LAY_demo2")).text) assert get_element(driver, ('id', "LAY_demo2")).text == "成功" except Exception as e: print(e) bug_photo(driver) assert False
def to_apply_for_leave(driver, file_path, remark): """ :param driver: :param file_path: 附件路径 :param remark: 备注 :return: """ into_one_level(driver, '任务面板') sleep(1) into_one_level(driver, '发起申请') get_element(driver, ('xpath', "//div[contains(text(),'请假申请')]")).click() sleep(0.5) element = "//select[@class='form-control input-sm']/option[%s]" % str( random.randint(1, 7)) get_element(driver, ('xpath', element)).click() get_element(driver, ('id', 'leaveAdd')).click() get_element(driver, ('id', 'realname')).send_keys('曹永') get_element(driver, ('id', 'realsearch')).click() sleep(0.5) get_element( driver, ('xpath', "//*[@id='lay-user-f']/tbody/tr/td[1]/input")).click() get_element(driver, ('xpath', "//button[contains(text(),'添加至已选')]")).click() get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() setting_input_time(driver) get_elements(driver, ('xpath', "//input[@placeholder='选择日期在合同范围内']"))[0].send_keys( get_now_dates()) get_elements(driver, ('xpath', "//input[@placeholder='选择日期在合同范围内']"))[1].send_keys( get_tomorrow_dates()) get_element( driver, ('xpath', "//textarea[@class='form-control']")).send_keys(remark) get_element( driver, ('xpath', "//div[@id='uploadFile']/input")).send_keys(file_path) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() get_element(driver, ('id', "success")).click() sleep(2) into_one_level(driver, '我的任务') get_element(driver, ('xpath', "//a[contains(text(),'我发起的')]")).click() try: get_element(driver, ('xpath', "//button[contains(text(),'请假工作流')]")).click() get_element( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr[1]/td[8]/a")).click() assert_element = "//div[@class='tsk-inp col-xs-8' and contains(text(),'%s')]" % remark assert is_element_present(driver, ('xpath', assert_element)) except Exception as e: print(e) bug_photo(driver) assert False
def logout(driver): driver.find_element_by_id("dropdownMenu-set").click() driver.find_element_by_xpath("//a[contains(text(),'注销')]").click() try: is_element_present(driver, ('xpath', "//button[contains(text(),'登录')]")) except Exception as e: print(e) print('注销失败') bug_photo(driver) return False
def change_time_of_attendance(driver, remark, file_path): try: into_one_level(driver, '任务面板') sleep(1) into_one_level(driver, '发起申请') get_element(driver, ('xpath', "//div[contains(text(),'修改出勤时间')]")).click() get_element(driver, ('id', 'leaveAdd')).click() sleep(0.5) element = "//*[@id='lay-user-f']/tbody/tr" for i in range(0, len(get_elements(driver, ('xpath', element))), 2): elements = "//tr[@data-index='%s']/td/input" % i get_element(driver, ('xpath', elements)).click() sleep(0.1) get_element(driver, ('xpath', "//button[contains(text(),'添加至已选')]")).click() get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() setting_input_time(driver) get_element( driver, ('xpath', "//input[@placeholder='选择日期不得小于当前日期']")).send_keys( get_now_dates()) get_elements( driver, ('xpath', "//input[@placeholder='']"))[0].send_keys('08:00') get_elements( driver, ('xpath', "//input[@placeholder='']"))[1].send_keys('17:00') get_element( driver, ('xpath', "//textarea[@class='form-control']")).send_keys(remark) get_element( driver, ('xpath', "//div[@id='uploadFile']/input")).send_keys(file_path) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() get_element(driver, ('id', "success")).click() sleep(0.5) into_one_level(driver, '我的任务') get_element(driver, ('xpath', "//a[contains(text(),'我发起的')]")).click() get_element( driver, ('xpath', "//button[contains(text(),'修改出勤时间工作流')]")).click() get_element( driver, ('xpath', "//*[@id='task-mytask-table']/tbody/tr[1]/td[8]/a")).click() assert_element = "//div[@class='tsk-inp col-xs-8' and contains(text(),'%s')]" % remark assert is_element_present(driver, ('xpath', assert_element)) except Exception as e: print(e) bug_photo(driver) assert False
def subcontract(driver, project_name, labor_company, sub_contract, labor_people): """ :param driver: 驱动 :param project_name: 工程名称 :param labor_company: 劳务公司 :param sub_contract: 分包合同名称 :param labor_people: 劳务经理 :return: """ try: into_one_level(driver, '任务面板') sleep(0.5) into_two_level(driver, '发起申请') driver.find_element_by_xpath("//div[contains(text(),'新建分包合同')]").click() driver.find_element_by_xpath("//span[contains(text(),'输入工程名称')]").click() get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(project_name) sleep(0.5) get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(Keys.ENTER) sleep(1) driver.find_element_by_xpath("//span[contains(text(),'输入公司关键字查找')]").click() get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(labor_company) sleep(0.5) get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(Keys.ENTER) # 分包合同名称 get_elements(driver, ('xpath', "//input[@placeholder='必填']"))[0].send_keys(sub_contract) information = "地基与基础、建筑装饰装修、建筑幕墙、钢结构、机电设备安装、电梯安装、消防设施、建筑防水、防腐保温、园林古建筑、爆破与拆除、电信工程、管道工程等" get_element(driver, ('xpath', "//textarea[@placeholder='必填']")).send_keys(information) setting_input_time(driver) get_element(driver, ('xpath', "//input[@placeholder='选择日期不得晚于计划竣工日期']")).send_keys(get_now_dates()) get_element(driver, ('xpath', "//input[@placeholder='选择日期不得早于今天']")).send_keys(get_future_date(299)) driver.find_element_by_xpath("//span[contains(text(),'输入姓名查找')]").click() get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(labor_people) sleep(1) get_element(driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(Keys.ENTER) get_elements(driver, ('xpath', "//input[@placeholder='必填']"))[1].send_keys(random.randint(10000, 99999)) QA_standard(driver, random.randint(0, 1)) remuneration_pay(driver, random.randint(0, 1)) the_contract_comes_into_effect(driver, random.randint(0, 1)) material_equipment_management(driver, random.randint(0, 1)) sub_insurance(driver, random.randint(0, 1)) dispute_resolution(driver, random.randint(0, 1)) laws_and_regulations(driver, random.randint(0, 1)) sleep(0.5) driver.find_element_by_xpath("//button[contains(text(),'完成')]").click() print(get_element(driver, ('id', "LAY_demo2")).text) assert get_element(driver, ('id', "LAY_demo2")).text == "成功" except Exception as e: print(e) bug_photo(driver) assert False
def web_employee_registration(browser, name, mobile, password, company_name): # 企业员工注册 """ :param browser: :param name: :param mobile: :param password: :param company_name: :return: """ browser.find_element_by_xpath("//button[contains(text(),'注册')]").click() sleep(0.5) browser.find_element_by_xpath("//div[contains(text(),'企业员工')]").click() get_element(browser, ('xpath', "//input[@data-pattern-message='请输入正确的手机号码']")).send_keys(mobile) sleep(0.5) get_elements(browser, ('xpath', "//span[contains(text(),'点击获取验证码')]"))[0].click() if is_element_present_3s(browser, ('xpath', "//div[contains(text(),'此号码已经存在,无需注册')]"), 5): get_element(browser, ('id', 'username')).send_keys(get_mobile()) if is_element_present_3s(browser, ('xpath', "//input[@data-tip='请输入真实姓名']"), 4): get_element(browser, ('xpath', "//input[@placeholder='手机验证码']")).send_keys('11111') else: browser.find_element_by_xpath("//div[contains(text(),'企业员工')]").click() get_element(browser, ('xpath', "//input[@data-pattern-message='请输入正确的手机号码']")).send_keys(mobile) get_element(browser, ('xpath', "//input[@placeholder='短信校验码']")).clear() get_element(browser, ('xpath', "//input[@placeholder='短信校验码']")).send_keys('11111') get_element(browser, ('xpath', "//input[@data-tip='请输入真实姓名']")).send_keys(name) get_element(browser, ('id', "password1")).send_keys(password) get_element(browser, ('xpath', "//input[@data-tip='请再新输入密码']")).send_keys(password) get_element(browser, ('xpath', "//b[@role='presentation']")).click() get_element(browser, ('xpath', "//input[@class='select2-search__field' and @type='search']")).send_keys( company_name) sleep(0.5) get_element(browser, ('xpath', "//input[@class='select2-search__field' and @type='search']")).send_keys(Keys.ENTER) get_element(browser, ('xpath', "//input[@class='agree-input']")).click() get_element(browser, ('xpath', "//button[contains(text(),'创建账户')]")).click() sleep(0.5) a = get_element(browser, ('xpath', "//div[contains(text(),'成功:公司职员注册')]")).text if '成功:公司职员注册' == a: pass else: print("失败:公司职员注册") bug_photo(browser) assert False sleep(2) browser.find_element_by_xpath("//button[contains(text(),'登录')]").click() get_element(browser, ('id', "username")).send_keys(mobile) get_element(browser, ('id', "password")).send_keys(password) get_element(browser, ('id', "loginButton")).click()
def update_PM(driver): into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() sleep(1) get_element(driver, ('xpath', "//button[contains(text(),'修改项目经理')]")).click() get_element(driver, ('xpath', "//select[@class='form-control input-sm']/option[2]")).click() get_element(driver, ('xpath', "//button[@class='btn btn-primary btn-sm']")).click() get_element(driver, ('id', 'success')).click() try: '更新成功' == get_element(driver, ('id', 'LAY_demo2')).text except Exception as e: print(e) bug_photo(driver) assert False
def initiate_artifacts(driver, file_path): # 工件审核 into_one_level(driver, '任务面板') sleep(1) into_one_level(driver, '发起申请') get_element(driver, ('xpath', "//div[contains(text(),'工件审核')]")).click() sleep(0.5) get_elements( driver, ('xpath', "//i[@class='glyphicon glyphicon-plus']"))[0].click() input_element = "//*[@id='lay-user-f']/tbody/tr[1]/td[1]/input" get_element(driver, ('xpath', input_element)).click() get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() element = "//select[@class='form-control input-sm']/option[2]" try: get_element(driver, ('xpath', element)).click() except Exception as e: print(e) assert False, "没有此工件" get_element(driver, ('xpath', "//input[@placeholder='数量为整数']")).send_keys( random.randint(1, 9)) setting_input_time(driver) get_element(driver, ('xpath', "//input[@placeholder='选择日期需小于或等于今天']")).send_keys( get_now_dates()) get_elements( driver, ('xpath', "//div[@class='col-sm-6']/input[1]"))[2].send_keys('优秀') get_element(driver, ('xpath', "//input[@data-min-message='输入值不能小于0']")).send_keys( random.randint(1, 100)) get_element( driver, ('xpath', "//div[@id='uploadFile']/input")).send_keys(file_path) get_element(driver, ('xpath', "//button[contains(text(),'提交申请')]")).click() sleep(0.5) get_element(driver, ('id', 'success')).click() sleep(1) try: '成功' == get_element( driver, ('xpath', "//div[@class='layui-layer-content layui-layer-padding']")).text except Exception as e: print(e) bug_photo(driver) assert False
def verify_real_name(driver, name, identity, path1, path2): """ :param driver: :param name: 姓名 :param identity: 身份证号 :param path1: 身份证正面路径 :param path2:身份证反面路径 :return: """ sleep(1) get_element(driver, ('id', 'dropdownMenu-set')).click() if is_element_present_3s(driver, ('xpath', "//a[contains(text(),'实名认证')]"), 2): sleep(1) get_element(driver, ('xpath', "//a[contains(text(),'实名认证')]")).click() else: pass if is_element_present( driver, ('xpath', "//button[@class='zdy-btn-blue reg-btn']")): sleep(4) get_element( driver, ('xpath', "//button[@class='zdy-btn-blue reg-btn']")).click() get_element(driver, ('xpath', "//input[@placeholder='真实姓名(必须填写)']")).clear() get_element( driver, ('xpath', "//input[@placeholder='真实姓名(必须填写)']")).send_keys(name) get_element(driver, ('xpath', "//input[@placeholder='身份证号(必须填写)']")).send_keys(identity) get_element(driver, ('id', "file1")).send_keys(path1) get_element(driver, ('id', "file2")).send_keys(path2) driver.find_element_by_xpath( "//button[contains(text(),'完成认证')]").click() sleep(5) if is_element_present(driver, ('xpath', "//a[contains(text(),'个人面板')]")): assert get_element(driver, ('id', 'dropdownMenu-set')).text == name, "认证失败" else: bug_photo(driver) assert False, "没跳转到实名认证后的页面" else: print("该用户已经实名认证")
def basic_information(driver): sleep(3) try: get_element(driver, ('xpath', "//div[@data-target='#mo-basic']")).click() get_element( driver, ('xpath', "//button[@class='btn btn-primary btn-sm']/i")).click() len_element = len( get_elements(driver, ('xpath', "//div[@id='selectWorkType']/div"))) for i in range(1, len_element, 3): element = "//div[@id='selectWorkType']/div[%s]/div/div[1]" % i get_element(driver, ('xpath', element)).click() sleep(0.1) get_element(driver, ('xpath', "//a[contains(text(),'确定')]")).click() # 省 len_province = len( get_elements(driver, ('xpath', "//div[12]/select/option"))) province_element = "//div[12]/select/option[%s]" % str( random.randint(2, len_province)) get_element(driver, ('xpath', province_element)).click() sleep(0.2) # 市 len_city = len( get_elements(driver, ('xpath', "//div[13]/select/option"))) city_element = "//div[13]/select/option[%s]" % str( random.randint(2, len_city)) get_element(driver, ('xpath', city_element)).click() sleep(0.2) # 区 len_district = len( get_elements(driver, ('xpath', "//div[14]/select/option"))) district_element = "//div[14]/select/option[%s]" % str( random.randint(2, len_district)) get_element(driver, ('xpath', district_element)).click() get_element(driver, ('xpath', "//textarea[@type='text']")).send_keys('潘松区88号') get_elements(driver, ('xpath', "//button[contains(text(),'保存')]"))[0].click() assert get_element(driver, ('id', "LAY_demo2")).text == '更新成功' a = get_element(driver, ('id', "LAY_demo2")).text print(a) except Exception as e: print(e) bug_photo(driver) assert False
def work_experience(driver): company_name = getCompanyName() project_name = company_name[2:-4] + '工程' start_date = get_pass_dates(random.randint(300, 400)) end_date = get_pass_dates(random.randint(100, 299)) information = "上士闻道勤而行之;中士闻道若存若亡;下士闻道大笑之,不笑不足以为道。执行是一日复一日的" try: if is_element_present(driver, ('xpath', "//i[@data-target='#mo-work-add']")): get_element(driver, ('xpath', "//i[@data-target='#mo-work-add']")).click() else: get_element(driver, ('xpath', "//div[@data-target='#mo-work']")).click() get_element(driver, ( 'xpath', "//div[@data-target='#mo-work-add' and contains(text(),'添加工作经验')]" )).click() get_elements( driver, ('xpath', "//div[@class='col-sm-6']/input[@placeholder='']" ))[1].send_keys(company_name) sleep(1) setting_input_time(driver) get_elements( driver, ('xpath', "//input[@data-max-time='']"))[2].send_keys(start_date) end_date_element = "//input[@data-min-time='%s']" % start_date get_element(driver, ('xpath', end_date_element)).send_keys(end_date) get_elements( driver, ('xpath', "//div[@class='col-sm-6']/input[@placeholder='']" ))[2].send_keys(project_name) get_element(driver, ('xpath', "//div[@class='col-sm-6']/textarea[@class='form-control']" )).send_keys(information) get_elements(driver, ('xpath', "//button[contains(text(),'完成')]"))[1].click() sleep(0.5) element = "//h4[contains(text(),'%s')]" % company_name assert is_element_present(driver, ('xpath', element)) except Exception as e: print(e) bug_photo(driver) assert False
def termination_of_the_contract(driver, workers_name): try: into_one_level(driver, '工程面板') sleep(0.5) into_two_level(driver, '工人管理') # 查询工人姓名 get_element( driver, ('xpath', "//div[@id='table-toolbar']/input")).send_keys(workers_name) # 搜索 get_element(driver, ('xpath', "//div[@id='table-toolbar']/button")).click() get_element(driver, ( 'xpath', "//a[contains(text(),'查看详情') and @class='table-a-link']")).click() get_elements( driver, ('xpath', "//a[contains(text(),'查看详情') and @class='table-a-link']" ))[1].click() sleep(1.5) get_element(driver, ('xpath', "//button[contains(text(),'合同终止')]")).click() get_element(driver, ('id', 'success')).click() assert get_element(driver, ('xpath', "//div[@id='LAY_demo2']")).text == '成功' sleep(3) get_element( driver, ('xpath', "//div[@id='table-toolbar']/input")).send_keys(workers_name) get_element(driver, ('xpath', "//div[@id='table-toolbar']/button")).click() sleep(1) if is_element_present_3s( driver, ('xpath', "//a[contains(text(),'查看详情') and @class='table-a-link']"), 2): assert False, '终止合同后,还可以搜到工人' else: pass except Exception as e: print(e) bug_photo(driver) assert False
def change_phone_number(driver, mobile, new_mobile, password): # 更换手机号 get_element(driver, ('id', 'dropdownMenu-set')).click() get_element( driver, ('xpath', "//a[@role='menuitem' and contains(text(),'账号设置') ]")).click() get_element(driver, ('xpath', "//a[contains(text(),'更改手机号')]")).click() sleep(0.5) get_element( driver, ('xpath', "//input[@placeholder='请输入原手机号码']")).send_keys(mobile) get_elements( driver, ('xpath', "//span[contains(text(),'点击获取验证码') and @class='get-btn' ]" ))[0].click() get_elements( driver, ('xpath', "//div[@class='col-sm-5']/input"))[0].send_keys('11111') get_elements(driver, ('xpath', "//button[contains(text(),'下一步')]"))[0].click() sleep(2) get_element( driver, ('xpath', "//input[@placeholder='请输入新手机号码']")).send_keys(new_mobile) get_elements( driver, ('xpath', "//span[contains(text(),'点击获取验证码') and @class='get-btn' ]" ))[1].click() get_elements( driver, ('xpath', "//div[@class='col-sm-5']/input"))[1].send_keys('11111') get_elements(driver, ('xpath', "//button[contains(text(),'下一步')]"))[1].click() sleep(6) try: web_login(driver, new_mobile, password) print('重置密码,且登陆成功') except Exception as e: print(e) print("重置密码失败") bug_photo(driver) assert False
def add_education_experience(driver): sleep(3) try: if is_element_present(driver, ('xpath', "//i[@data-target='#mo-edu-add']")): get_element(driver, ('xpath', "//i[@data-target='#mo-edu-add']")).click() else: get_element(driver, ('xpath', "//div[@data-target='#mo-edu']")).click() get_element(driver, ( 'xpath', "//div[@data-target='#mo-edu-add' and contains(text(),'添加教育经历')]" )).click() work_type = "//div[1]/div[1]/select[@class='form-control']/option[%s]" % str( random.randint(1, 10)) get_elements(driver, ('xpath', work_type))[1].click() get_element(driver, ('xpath', "//input[@placeholder='专业']")).send_keys('建筑') start_dates = get_pass_dates(random.randint(200, 300)) end_dates = get_pass_dates(random.randint(50, 199)) setting_input_time(driver) get_element(driver, ( 'xpath', "//input[@placeholder='' and @class='form-control input-sm form-date val-start-date']" )).send_keys(start_dates) get_elements(driver, ( 'xpath', "//input[@placeholder='' and @class='form-control input-sm form-date']" ))[-1].send_keys(end_dates) school_name = getCompanyName()[2:-4] + '学校' get_element( driver, ('xpath', "//input[@placeholder='学校名称']")).send_keys(school_name) get_elements(driver, ('xpath', "//button[contains(text(),'完成')]"))[2].click() title = school_name + '(' + start_dates + '——' + end_dates + ')' element = "//h4[contains(text(),'%s')]" % title assert is_element_present(driver, ('xpath', element)) except Exception as e: print(e) bug_photo(driver) assert False
def android_login(driver, username, password): try: get_element( driver, ('id', "com.zld.zld_face_rec_app:id/et_name")).send_keys(username) get_element( driver, ('id', "com.zld.zld_face_rec_app:id/et_pwd")).send_keys(password) get_element(driver, ('id', "com.zld.zld_face_rec_app:id/btn_login")).click() # 通过定位 点击第一个班组 sleep(2) driver.tap([(0, 231), (1080, 420)], 100) sleep(1) agree_with_permissions(driver) sleep(1) assert is_element_present_3s( driver, ('id', "com.zld.zld_face_rec_app:id/fl_message")), '登陆失败' except Exception as e: print(e) bug_photo(driver) assert False
def add_team(driver, team_name): into_one_level(driver, '工程面板') sleep(1) into_two_level(driver, '组织构架') # 新增班组按钮 get_element(driver, ('xpath', "//button[@class='btn btn-primary btn-sm']")).click() sleep(1) get_elements(driver, ('xpath', "//input[@class='form-control input-sm']"))[2].clear() # 输入班组名称 get_elements(driver, ('xpath', "//input[@class='form-control input-sm']"))[2].send_keys(team_name) # 选择班组长 get_element(driver, ('xpath', "//*[@id='add-team']/form/div[3]/div/select/option[2]")).click() # 选择质量员 get_element(driver, ('xpath', "//*[@id='add-team']/form/div[4]/div/select/option[2]")).click() # 确定 get_element(driver, ('xpath', "//*[@id='add-team']/form/div[5]/div/button[1]")).click() sleep(1) team_name_element = "//div[contains(text(),'%s')]" % team_name if is_element_present(driver, ('xpath', team_name_element)): pass else: bug_photo(driver) print('新增班组失败') assert False # 修改班组 driver.find_element_by_xpath(team_name_element).click() get_element(driver, ('xpath', "//button[contains(text(),'修改班组')]")).click() new_team_name = getRandomName() sleep(1) get_elements(driver, ('xpath', "//input[@class='form-control input-sm']"))[2].clear() # 输入新的班组名称 get_elements(driver, ('xpath', "//input[@class='form-control input-sm']"))[2].send_keys(new_team_name) # 确定 get_element(driver, ('xpath', "//*[@id='add-team']/form/div[5]/div/button[1]")).click() sleep(1) new_team_name_element = "//div[contains(text(),'%s')]" % new_team_name if is_element_present(driver, ('xpath', new_team_name_element)): pass else: bug_photo(driver) print('新增班组失败') assert False get_element(driver, ('xpath', new_team_name_element)).click() get_element(driver, ('xpath', "//button[contains(text(),'删除班组')]")).click() get_element(driver, ('xpath', "//a[@class='layui-layer-btn0']")).click() sleep(1) if is_element_present(driver, ('xpath', team_name_element)): bug_photo(driver) print('新增班组失败') assert False else: pass
def personal_certificate(driver, file_path): sleep(3) try: if is_element_present(driver, ('xpath', "//i[@data-target='#mo-book-add']")): get_element(driver, ('xpath', "//i[@data-target='#mo-book-add']")).click() else: get_element(driver, ('xpath', "//div[@data-target='#mo-book']")).click() get_element(driver, ( 'xpath', "//div[@data-target='#mo-book-add' and contains(text(),'添加证书')]" )).click() work_type = "//div[1]/div[1]/select[@class='form-control']/option[%s]" % str( random.randint(2, 39)) get_elements(driver, ('xpath', work_type))[0].click() certificate_number = random_str() + get_org_no()[:-3] get_element( driver, ('xpath', "//input[@placeholder='请输入工种证书号']")).send_keys(certificate_number) level_education = "//div[3]/div[1]/select[@class='form-control']/option[%s]" % str( random.randint(2, 11)) get_elements(driver, ('xpath', level_education))[0].click() setting_input_time(driver) get_element( driver, ('xpath', "//input[@placeholder='选择日期不得晚于当前日期']")).send_keys( get_pass_dates(random.randint(200, 400))) get_element( driver, ('xpath', "//input[@placeholder='选择日期大于等于领证日期']")).send_keys( get_pass_dates(random.randint(50, 199))) get_element( driver, ('xpath', "//input[@placeholder='选择日期大于使用开始日期']")).send_keys( get_tomorrow_dates()) get_element( driver, ('xpath', "//div[7]/div[1][@class='col-sm-6']/input")).send_keys('政府') if len(get_elements(driver, ('xpath', "//input[@name='file']"))) == 2: get_elements( driver, ('xpath', "//input[@name='file']"))[0].send_keys(file_path) get_elements( driver, ('xpath', "//input[@name='file']"))[1].send_keys(file_path) else: get_elements( driver, ('xpath', "//input[@name='file']"))[-2].send_keys(file_path) get_elements( driver, ('xpath', "//input[@name='file']"))[-1].send_keys(file_path) # 利用js 获取当前元素位置 driver.execute_script( "arguments[0].scrollIntoView();", get_element(driver, ('xpath', "//button[contains(text(),'提交')]"))) sleep(0.5) get_element(driver, ('xpath', "//button[contains(text(),'提交')]")).click() element = "//h4[contains(text(),'%s')]" % certificate_number assert is_element_present(driver, ('xpath', element)), "添加证书失败" except Exception as e: print(e) bug_photo(driver) assert False
def family_information(driver): sleep(3) try: get_element(driver, ('xpath', "//div[@data-target='#mo-home']")).click() get_element( driver, ('xpath', "//input[@data-duplex-changed='show1']")).click() get_elements( driver, ('xpath', "//div[@class='pi-plane-con-text']/input"))[0].clear() get_elements( driver, ('xpath', "//div[@class='pi-plane-con-text']/input"))[0].send_keys('2') setting_input_time(driver) # 结婚日期 get_elements(driver, ('xpath', "//div[@id='marry']/input"))[0].send_keys( get_pass_dates(100)) get_elements( driver, ('xpath', "//div[@class='pi-plane-con-text']/input"))[1].send_keys( getPeopleName()) get_elements( driver, ('xpath', "//div[@class='pi-plane-con-text']/input"))[2].send_keys( get_mobile()) relation_element = "//div[2]/div/div[6]/select/option[%s]" % str( random.randint(2, 8)) get_element(driver, ('xpath', relation_element)).click() len_province = len( get_elements(driver, ('xpath', "//div[2]/div/div[7]/select/option"))) province_element = "//div[2]/div/div[7]/select/option[%s]" % str( random.randint(2, len_province)) get_element(driver, ('xpath', province_element)).click() sleep(1) len_city = len( get_elements(driver, ('xpath', "//div[2]/div/div[8]/select/option"))) city_element = "//div[2]/div/div[8]/select/option[%s]" % str( random.randint(2, len_city)) get_element(driver, ('xpath', city_element)).click() sleep(1) len_district = len( get_elements(driver, ('xpath', "//div[2]/div/div[9]/select/option"))) district_element = "//div[2]/div/div[9]/select/option[%s]" % str( random.randint(1, len_district)) get_element(driver, ('xpath', district_element)).click() get_element(driver, ('xpath', "//div[2]/div/div[10]/input")).send_keys('塔克拉玛干') get_element(driver, ('xpath', "//div[2]/div/div[11]/input")).send_keys('厄尔') get_elements(driver, ('xpath', "//button[contains(text(),'保存')]"))[1].click() assert get_element(driver, ('id', "LAY_demo2")).text == '更新成功' a = get_element(driver, ('id', "LAY_demo2")).text print(a) except Exception as e: print(e) bug_photo(driver) assert False
def attendance_machine(driver, people): global name1_text into_two_level(driver, '设备管理') driver.find_element_by_xpath("//a[contains(text(),'考勤卡')]").click() name_text = [] num = random.randint(100000, 999999) driver.find_element_by_xpath("//button[contains(text(),'新增')]").click() get_element( driver, ('xpath', "//input[@placeholder='请输入4-10位考勤卡号']")).send_keys(num) get_element( driver, ('xpath', "//span[@class='select2-selection__placeholder']")).click() get_element( driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(people) sleep(0.5) get_element( driver, ('xpath', "//input[@class='select2-search__field']")).send_keys( Keys.ENTER) driver.find_element_by_xpath("//button[contains(text(),'确定')]").click() if is_element_present(driver, ('xpath', "//div[contains(text(),'该用户已绑定考勤卡')]")): # 解绑考勤卡 sleep(7) get_element(driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).send_keys(people) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[0].click() for i in range( len( get_elements(driver, ('xpath', "//*[@id='kqk-table']/tbody/tr"))), 0, -1): unbind_element = "//*[@id='kqk-table']/tbody/tr[%d]/td[4]/a" % i get_element(driver, ('xpath', unbind_element)).click() get_element( driver, ('xpath', "//*[@id='k']/form/div[4]/button[3]")).click() assert is_element_present( driver, ('xpath', "//i[@class='layui-layer-ico layui-layer-ico1']")), "解绑考勤卡失败" sleep(0.5) # 输入空格 查看全部 get_element(driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).clear() get_element( driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).send_keys(' ') sleep(0.5) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[0].click() driver.find_element_by_xpath("//button[contains(text(),'新增')]").click() get_element( driver, ('xpath', "//input[@placeholder='请输入4-10位考勤卡号']")).send_keys(num) get_element( driver, ('xpath', "//span[@class='select2-selection__placeholder']")).click() get_element( driver, ('xpath', "//input[@class='select2-search__field']")).send_keys(people) sleep(0.5) get_element( driver, ('xpath', "//input[@class='select2-search__field']")).send_keys( Keys.ENTER) driver.find_element_by_xpath("//button[contains(text(),'确定')]").click() if is_element_present( driver, ('xpath', "html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/div[2]/div[2]/div[2]/div[4]/div[2]/ul/li[1]/a" )): get_element(driver, ( 'xpath', "html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/div[2]/div[2]/div[2]/div[4]/div[2]/ul/li[1]/a" )).click() sleep(0.5) element_len = get_elements(driver, ('xpath', "//*[@id='kqk-table']/tbody/tr")) for i in range(1, len(element_len) + 1): element = "//*[@id='kqk-table']/tbody/tr[%d]/td[2]" % i name_text.insert(i, get_element(driver, ('xpath', element)).text) assert str(num) in name_text, "考勤卡添加失败1" else: element_len_now = get_elements( driver, ('xpath', "//*[@id='kqk-table']/tbody/tr")) for i in range(1, len(element_len_now)): element = "//*[@id='kqk-table']/tbody/tr[%d]/td[2]" % i name_text.insert(i, get_element(driver, ('xpath', element)).text) assert str(num) in name_text, "考勤卡添加失败2" name1_text = [] for h in range( 1, len( get_elements(driver, ('xpath', "//*[@id='kqk-table']/tbody/tr"))) + 1): element = "//*[@id='kqk-table']/tbody/tr[%d]/td[3]" % h if get_element(driver, ('xpath', element)).text != '-': name1_text.insert(h, get_element(driver, ('xpath', element)).text) if is_element_present( driver, ('xpath', "html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/div[2]/div[2]/div[2]/div[4]/div[2]/ul/li[4]/a" )): get_element(driver, ( 'xpath', "html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/div[2]/div[2]/div[2]/div[4]/div[2]/ul/li[4]/a" )).click() sleep(0.5) sleep(1) get_element(driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).send_keys( str(name1_text[0])) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[0].click() assert name1_text[0] == get_element( driver, ('xpath', "//*[@id='kqk-table']/tbody/tr/td[3]")).text, "考勤卡筛选成功,or 筛选失败" # 解绑考勤卡 get_element(driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).clear() get_element( driver, ('xpath', "//input[@placeholder='请输入考勤卡号或姓名筛选']")).send_keys(num) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[0].click() get_element( driver, ('xpath', "//*[@id='kqk-table']/tbody/tr/td[1]/input")).click() sleep(0.5) driver.find_elements_by_xpath("//button[contains(text(),'删除')]")[0].click() get_elements(driver, ('xpath', "//button[contains(text(),'确定')]"))[3].click() get_element(driver, ('id', 'success')).click() if is_element_present( driver, ('xpath', "//div[contains(text(),'考勤卡不存在或无法删除已经绑定用户的考勤卡,请重新选择用户,或者先解绑')]")): sleep(7) try: # get_element(driver, ('xpath', "//button[contains(text(),'取消')]")).click() get_element( driver, ('xpath', "//*[@id='kqk-table']/tbody/tr/td[4]/a")).click() get_element( driver, ('xpath', "//*[@id='k']/form/div[4]/button[3]")).click() get_element(driver, ('xpath', "//*[@id='kqk-table']/tbody/tr/td[1]/input")).click() get_elements( driver, ('xpath', "//button[contains(text(),'删除')]"))[0].click() get_elements( driver, ('xpath', "//button[contains(text(),'确定')]"))[3].click() get_element(driver, ('id', 'success')).click() except Exception as e: bug_photo(driver) print(e) assert is_element_present(driver, ('id', "LAY_demo2")), "删除考勤卡失败"
def setting_attendance_machine(driver, attendance_machine_name, machine_type_id=1): """ :param driver: :param attendance_machine_name: 考勤机的名称 :param machine_type_id: 1 固定 2 移动 3 gps (目前2,3不支持) :return: """ into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() into_two_level(driver, '考勤机设置') # 增加考勤机 sleep(1) get_element(driver, ('xpath', "//button[contains(text(),'增加')]")).click() machine_type = "//*[@id='kqj-box']/form/div[1]/div/select/option[%d]" % machine_type_id get_element(driver, ('xpath', machine_type)).click() get_element( driver, ('xpath', "//div[@id='kqj-box']/form/div[4]/div/input")).send_keys('123456') get_element(driver, ('xpath', "//div[@id='kqj-box']/form/div[2]/div/input" )).send_keys(attendance_machine_name) sleep(1) # 工程区域 project_areas = len( get_elements( driver, ('xpath', "//*[@id='kqj-box']/form/div[3]/div/select/option"))) sleep(0.5) try: project_areas_elements = "//*[@id='kqj-box']/form/div[3]/div/select/option[%s]" % str( random.randint(1, project_areas - 2)) print(project_areas_elements) except Exception as e: print(e) bug_photo(driver) assert False, '工程区域点击无响应' get_element(driver, ('xpath', project_areas_elements)).click() if is_element_present_3s(driver, ('xpath', "//button[contains(text(),'选择位置')]"), 3): get_element(driver, ('xpath', "//button[contains(text(),'选择位置')]")).click() sleep(2) class_name = 'MozillaWindowClass' title_name = '杭州智链达建筑工人服务平台 - Mozilla FireFox' # 查找句柄 hwnd = win32gui.FindWindow(class_name, title_name) click_position(hwnd, 1299, 582) sleep(1.5) get_element(driver, ('xpath', "//a[@class='layui-layer-btn0']")).click() # 确定 get_element(driver, ('xpath', "//button[@class='btn btn-primary']")).click() element_len = "//*[@id='engineering-set-table']/tbody/tr" number = len(get_elements(driver, ('xpath', element_len))) title_list = [] if '添加成功' == get_element_3s(driver, ('id', "LAY_demo2"), 2).text: print('pass') else: bug_photo(driver) assert False for i in range(1, number + 1): name_elements = "//*[@id='engineering-set-table']/tbody/tr[%d]/td[1]/span" % i title_list.insert(i, get_element(driver, ('xpath', name_elements)).text) try: attendance_machine_name in title_list except Exception as e: print(e) bug_photo(driver) assert False # s删除考勤机 # 删除按钮 delete_element = "//*[@id='engineering-set-table']/tbody/tr[%d]/td[7]/a[2]" % len( get_elements(driver, ('xpath', element_len))) # 删除考勤机的名字 delete_element_name = "//*[@id='engineering-set-table']/tbody/tr[%d]/td[1]/span" % len( get_elements(driver, ('xpath', element_len))) # 考勤机的时候排序不正确,导致的异常 delete_name = get_element(driver, ('xpath', delete_element_name)).text get_element(driver, ('xpath', delete_element)).click() get_element(driver, ('id', 'success')).click() new_title_list = [] sleep(1) for i in range(1, len(get_elements(driver, ('xpath', element_len))) + 1): name_elements = "//*[@id='engineering-set-table']/tbody/tr[%d]/td[1]/span" % i new_title_list.insert( i, get_element(driver, ('xpath', name_elements)).text) if delete_name in new_title_list: assert False, print(delete_name) else: print('删除成功')
def setting_area(driver, area_name): ''' :param driver: :param area_name: 区域名称 :return: ''' # 增加区域 into_one_level(driver, '工程面板') sleep(1) get_elements(driver, ('xpath', "//a[contains(text(),'设置')]"))[1].click() into_two_level(driver, '项目设置') # 增加区域 get_element(driver, ('xpath', "//div[contains(text(),'添加区域 ')]")).click() sleep(1) class_name = 'MozillaWindowClass' title_name = '杭州智链达建筑工人服务平台 - Mozilla FireFox' # 查找句柄 hwnd = win32gui.FindWindow(class_name, title_name) click_position(hwnd, 146, 177) sleep(8) get_element(driver, ('xpath', "//button[contains(text(),'开始描点')]")).click() click_position(hwnd, 673, 453) sleep(0.5) click_position(hwnd, 1158, 468) sleep(0.5) click_position(hwnd, 701, 700) sleep(0.5) get_element(driver, ('xpath', "//button[contains(text(),'停止描点')]")).click() # 区域名称 get_element( driver, ('xpath', "//textarea[@name='area-name']")).send_keys(area_name) get_element(driver, ('xpath', "//button[contains(text(),'保存')]")).click() get_element(driver, ('id', 'success')).click() project_area_elements = "//div[@class='select-area-util-item select-area-util-area']" area_names = [] for i in range(len(get_elements(driver, ('xpath', project_area_elements)))): area_names.insert( i, get_elements(driver, ('xpath', project_area_elements))[i].text) try: area_name in area_names except Exception as e: print(e) bug_photo(driver) assert False project_element = "//div[@class='select-area-util-item select-area-util-area'and contains(text(),'%s')]" % area_name # 鼠标悬停在元素上面 ActionChains(driver).move_to_element( get_element(driver, ('xpath', project_element))).perform() # 修改区域 update_project_element = project_element + "/div/div[2]" sleep(1) get_element(driver, ('xpath', update_project_element)).click() click_position(hwnd, 146, 177) sleep(1) get_element(driver, ('xpath', "//button[contains(text(),'开始描点')]")).click() click_position(hwnd, 638, 460) get_element(driver, ('xpath', "//button[contains(text(),'保存')]")).click() get_element(driver, ('id', 'success')).click() sleep(0.5) try: '成功' == get_element( driver, ('xpath', "//div[@class='layui-layer-content layui-layer-padding']")).text except Exception as e: print(e) bug_photo(driver) assert False sleep(1) into_two_level(driver, '考勤机设置') attendance_machine_area_names = get_attendance_machine_area_name(driver) try: area_name in attendance_machine_area_names except Exception as e: print(e) print('增加区域后,没有增加GPS、移动人脸考勤机') bug_photo(driver) assert False