def camera_management(driver): into_two_level(driver, '设备管理') driver.find_element_by_xpath("//a[contains(text(),'摄像头')]").click() num = random_str(4) + str(random.randint(1000000, 9999999)) random_ip = "rtsp://" + "192.168.1.%d" % random.randint(1, 255) # 增加摄像头 driver.find_elements_by_xpath("//button[contains(text(),'新增')]")[3].click() get_element(driver, ('xpath', "//input[@placeholder='请输入摄像头设备号']")).send_keys(num) get_element(driver, ('xpath', "//option[contains(text(),'253112612')]")).click() camera_element = "//*[@id='sxt']/form/div[4]/select/option[%d]" % random.randint( 1, 2) get_element(driver, ('xpath', camera_element)).click() get_element( driver, ('xpath', "//input[@placeholder='请输入rtsp地址']")).send_keys(random_ip) driver.find_element_by_xpath("//button[contains(text(),'确认')]").click() get_elements( driver, ('xpath', "//input[@placeholder='请输入设备号筛选']"))[1].send_keys(num) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[3].click() assert str(num) == get_element( driver, ('xpath', "//*[@id='sxt-table']/tbody/tr[1]/td[2]")).text, "不在location中,新增失败" # 更新摄像头 get_element(driver, ('xpath', "//*[@id='sxt-table']/tbody/tr/td[6]/a")).click() num1 = random_str(4) + str(random.randint(1000000, 9999999)) get_element(driver, ('xpath', "//input[@placeholder='请输入摄像头设备号']")).clear() get_element(driver, ('xpath', "//input[@placeholder='请输入摄像头设备号']")).send_keys(num1) driver.find_elements_by_xpath("//button[contains(text(),'确认')]")[1].click() get_elements(driver, ('xpath', "//input[@placeholder='请输入设备号筛选']"))[1].clear() get_elements( driver, ('xpath', "//input[@placeholder='请输入设备号筛选']"))[1].send_keys(num1) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[3].click() assert str(num1) == get_element( driver, ('xpath', "//*[@id='sxt-table']/tbody/tr[1]/td[2]")).text, "不在location中,新增失败" # 删除闸机 get_element(driver, ('xpath', "//*[@id='sxt-table']/tbody/tr/td[1]")).click() get_elements(driver, ('xpath', "//button[contains(text(),'删除')]"))[3].click() get_elements(driver, ('xpath', "//button[contains(text(),'确认')]"))[2].click() get_element(driver, ('id', "success")).click() assert is_element_present(driver, ('xpath', "//td[@colspan='6']")), "删除闸机失败"
def brake_machine(driver): into_two_level(driver, '设备管理') driver.find_element_by_xpath("//a[contains(text(),'闸机')]").click() num = random_str(4) + str(random.randint(1000000, 9999999)) random_ip = "192.168.1.%d" % random.randint(1, 255) # 增加闸机 driver.find_elements_by_xpath("//button[contains(text(),'新增')]")[2].click() get_element(driver, ('xpath', "//input[@placeholder='请输入闸机设备号']")).send_keys(num) get_element(driver, ('xpath', "//option[contains(text(),'hpface联调闸机')]")).click() get_element( driver, ('xpath', "//input[@placeholder='请输入闸机IP']")).send_keys(random_ip) driver.find_element_by_xpath("//button[contains(text(),'确认')]").click() get_element(driver, ('xpath', "//input[@placeholder='请输入设备号筛选']")).send_keys(num) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[2].click() assert str(num) == get_element( driver, ('xpath', "//*[@id='zj-table']/tbody/tr[1]/td[2]")).text, "不在location中,新增失败" # 更新闸机 get_element(driver, ('xpath', "//*[@id='zj-table']/tbody/tr/td[5]/a")).click() num1 = random_str(4) + str(random.randint(1000000, 9999999)) get_element(driver, ('xpath', "//input[@placeholder='请输入闸机号码']")).clear() get_element(driver, ('xpath', "//input[@placeholder='请输入闸机号码']")).send_keys(num1) driver.find_elements_by_xpath("//button[contains(text(),'确认')]")[1].click() get_element(driver, ('xpath', "//input[@placeholder='请输入设备号筛选']")).clear() get_element(driver, ('xpath', "//input[@placeholder='请输入设备号筛选']")).send_keys(num1) get_elements(driver, ('xpath', "//button[contains(text(),'筛选')]"))[2].click() assert str(num1) == get_element( driver, ('xpath', "//*[@id='zj-table']/tbody/tr[1]/td[2]")).text, "不在location中,新增失败" # 删除闸机 get_element(driver, ('xpath', "//*[@id='zj-table']/tbody/tr/td[1]")).click() get_elements(driver, ('xpath', "//button[contains(text(),'删除')]"))[2].click() get_elements(driver, ('xpath', "//button[contains(text(),'确认')]"))[2].click() get_element(driver, ('id', "success")).click() assert is_element_present(driver, ('xpath', "//td[@colspan='5']")), "删除闸机失败"
def setUp(self): conf = ConfigParser() self.path = setting_path() self.file_path = r'C:\Users\%s\Desktop\UIAutotest\Page\file\1.jpg' % ( str(getpass.getuser())) conf.read(self.path) self.username = conf.get('management', 'Hujinping') self.password = conf.get('management', 'password') url = conf.get('testUrl', 'url') self.browser = browse_driver.Firefox() self.browser.maximize_window() self.browser.get(url) self.certificate_number = random_str(6) pass
def setUp(self): conf = ConfigParser() self.path = setting_path() self.file_path = r'C:\Users\%s\Desktop\UIAutotest\Page\file\1.jpg' % ( str(getpass.getuser())) conf.read(self.path) self.username = conf.get('management', 'Hujinping') self.password = conf.get('management', 'password') url = conf.get('testUrl', 'url') self.browser = browse_driver.Firefox() self.browser.maximize_window() self.browser.implicitly_wait(5) # 需要特别说明的是:隐性等待对整个driver的周期都起作用,所以只要设置一次即可, # 我曾看到有人把隐性等待当成了sleep在用,走哪儿都来一下… self.browser.get(url) self.certificate_number = random_str(6) pass
def company_add(ws_driver, result): requestDict = { "command": { "path": "employer.consumer.CompanyAdd" }, "parameters": { "sid": result['data']['sid'], "address_form": { "province": '浙江省' }, "company_form": { "name": get_company_name(), "org_no": get_org_no(), "credit_no": random_str(18) } } } result = ws_driver.web_socket_request(requestDict) return result
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 test_NewCompany(self): company_name = get_company_name() into_one_level(self.driver, '运维面板') into_two_level(self.driver, '注册公司管理') self.driver.find_element_by_xpath( "//button[contains(text(),'新增')]").click() self.driver.find_element_by_xpath( "//input[@placeholder='企业名称']").send_keys(company_name) self.driver.find_element_by_xpath( "//input[@placeholder='0000XX0000']").send_keys(random_str(18)) # a = self.driver.find_element_by_xpath(".//*[@id='company-address']/div/div[1]/select") # a.find_element_by_xpath("//option[@value='北京市']").click() # 方法1 self.driver.find_element_by_xpath( ".//*[@id='company-address']/div/div[1]/select/option[12]").click( ) # 方法2 省 # Select(a).select_by_value('内蒙古自治区') # 方法3 self.driver.find_element_by_xpath( ".//*[@id='company-address']/div/div[2]/select/option[2]").click( ) # 市 self.driver.find_element_by_xpath( ".//*[@id='company-address']/div/div[3]/select/option[3]").click( ) # 区 self.driver.find_element_by_xpath( "//input[@placeholder='输入街道名称']").send_keys('南京路') self.driver.find_element_by_xpath( "//input[@placeholder='门派号、小区名称、房间号']").send_keys('3号') information = '室内装潢及设计、园林绿化、园林绿化工程施工等' self.driver.find_element_by_xpath( "//textarea[@placeholder='长度不超过500个字符']").send_keys(information) get_element( self.driver, ('xpath', "//input[@placeholder='企业固定电话格式 例:0759-7654321']")).send_keys( get_telephone()) self.driver.find_element_by_xpath( "//input[@placeholder='输入法人姓名']").send_keys(getRandomName()) self.driver.find_element_by_xpath( "//button[contains(text(),'完成')]").click() self.driver.refresh() sleep(2) elem = "//td[contains(text(),%s)]" % company_name get_element( self.driver, ('xpath', "//input[@placeholder='请输入公司名称筛选']")).send_keys(company_name) get_element(self.driver, ('xpath', "//button[contains(text(),'搜索')]")).click() sleep(1) new_company_name = self.driver.find_elements_by_xpath(elem)[0].text assert new_company_name == company_name get_element(self.driver, ('xpath', "//input[@placeholder='请输入公司名称筛选']")).clear() get_element( self.driver, ('xpath', "//input[@placeholder='请输入公司名称筛选']")).send_keys(company_name) get_element(self.driver, ('xpath', "//button[contains(text(),'搜索')]")).click() elem = "//td[contains(text(),%s)]" % company_name select_company_name = self.driver.find_element_by_xpath(elem).text assert select_company_name == company_name # 全称查询公司 self.driver.find_element_by_xpath( "//input[@placeholder='请输入公司名称筛选']").clear() self.driver.find_element_by_xpath( "//input[@placeholder='请输入公司名称筛选']").send_keys(company_name[1:3]) self.driver.find_element_by_xpath( "//button[contains(text(),'搜索')]").click() assert company_name in select_company_name new_elem = "//td[contains(text(),%s)]" % company_name sleep(0.5) select_companys_name = self.driver.find_elements_by_xpath(new_elem) company_name_list = [] j = 0 # 公司的index 规律是每5个就是公司的text # 获取所有的公司名称 for i in range(int(len(select_companys_name) / 5)): company_name_list.insert( i, self.driver.find_elements_by_xpath(new_elem)[j].text) j += 5 print(company_name_list) assert company_name in company_name_list # 包含这个字段的公司,在列表里面