def iterator(self): test_case = {} self.BuildTestCase(test_case,self.List_action) for num in range(0,1): if num > 1: t = testRegManager(self.List_action) t.callmoudle(t.browser,t.cachedata,t.List_action,test_case) Common.tear_down(t.browser) else: self.callmoudle(self.browser,self.cachedata,self.List_action,test_case) Common.tear_down(self.browser)
def select_workstation(browser, workstation, cache): #判断工作站是否打开 if common.switch_window(browser, uum.workstation_name_collation1[workstation], cache): browser.switch_to_window( cache.get(uum.workstation_name_collation1[workstation])) else: browser.switch_to_window(cache.get('UUM Portal')) browser.find_element_by_link_text(workstation).send_keys(Keys.ENTER) time.sleep(1) handles = browser.window_handles end_time = time.time() + 100 while True: time.sleep(0.5) for handle in handles: if handle in cache.values(): continue browser.switch_to_window(handle) if re.sub('[A-Za-z0-9.]', '', browser.title).strip( ) == uum.workstation_name_collation1[workstation]: cache.set( re.sub('[A-Za-z0-9.]', '', browser.title).strip(), browser.current_window_handle) return if time.time() > end_time: log.info('%s页面加载失败!' % workstation) break
def test_login(browser, testcase, cache): log.info("开始运行登陆脚本") #判断该uum portal是否打开 if common.switch_window(browser, 'UUM Portal', cache): return #登录测试用例 browser.get(path.localhost) browser.implicitly_wait(20) # 判读用户是否已经登录 cookies = browser.get_cookies() for cookie in cookies: if 'CASTGC' in cookie.values(): browser.delete_all_cookies() browser.refresh() # browser.maximize_window() browser.find_element_by_xpath(portal.用户名).clear() browser.find_element_by_xpath(portal.用户名).send_keys( testcase[table.user_login['username']]) browser.find_element_by_xpath(portal.密码).clear() browser.find_element_by_xpath(portal.密码).send_keys( testcase[table.user_login['psw']]) browser.find_element_by_xpath(portal.登陆).send_keys(Keys.ENTER) time.sleep(2) if browser.title == 'UUM Portal': utility.writeFile('登录 pass') else: utility.writeFile('登录 fail') # browser.find_element_by_xpath(portal.input[2]['key']).click() # cache[browser.title] = browser.current_window_handle cache.set(browser.title, browser.current_window_handle) log.info("登陆脚本运行结束")
def test_logout(browser, cache): # 判断该uum portal是否打开 log.info("开始运行退出脚本") if common.switch_window(browser, 'UUM Portal', cache): print(cache) browser.switch_to_window(cache.get('UUM Portal')) browser.find_element_by_xpath( "//button[contains(text(),'退出系统')]").click() browser.find_element_by_xpath("//button[contains(text(),'是')]").click() else: raise Exception('请先登录!') log.info("退出脚本运行结束")
result = 0 def outp_message(browser): special_elements = browser.find_elements_by_xpath(div[3]['key']) outp_type_code = [] outp_date = [] if len(special_elements) > 1: for special_element in special_elements: outp_type_code.append( special_element.find_elements_by_tag_name('div')[1].text) outp_date.append( special_element.find_elements_by_tag_name('div')[4].text) return [outp_type_code, outp_date] if __name__ == '__main__': cache = Cache({}) browser = Common.browser() testcase = {'用户名': 'jfli', '密码': '123456'} login.test_login(browser, testcase, cache) test_case = { '患者卡号': '%E?;1004627675=99015017425?+E?', '患者姓名': '', '号源类别': '专家', '专科编码': '083', '专科名称': '', '医生': '' } test_regist_button(browser, test_case, cache)
zipname = zip.namelist() #返回压缩包中所有文件的文件名 zip.extractall() #解压所有文件 zip.close() f = open(zipname[0]) lines = f.readline() # print(lines) f.close() # 拼写制卡卡号 card = '%E?;' + lines.rstrip('\n').split("|")[1] + '?+E?' cache.set('patient_card', card) log.info(card) Utility.writeFile(card) # 删除解压文件 if os.path.exists(zipname[0]): os.remove(zipname[0]) if __name__ == "__main__": browser = common.browser() cache = Cache({}) testcase = {'用户名': 'jwang', '密码': '123456'} cache.set('resultType', '1') cache.set('specialName', '急诊内科') cache.set('userId', '%E?;2001065723=99015011437?+E?') login.test_login(browser, testcase, cache) test_businessCard(browser, cache) browser.find_elements_tag_name('img')[21].click() browser.find_elements_by_xpath('//img')[21].click()
def test_reservation_regist(browser,cache): #判断检查预约工作站是否打开 login.select_workstation(browser, '检查预约', cache) work_select.select_department(browser,cache) browser.find_element_by_xpath(reservation.div[0]['key']).click() browser.find_element_by_link_text('预约登记管理').click() time.sleep(2) apply_list = list(cache['检查单'].keys()) #选取预约类型(门诊o 住院i) reservation_type = reservation.div[1]['key'] #刷卡 swip_card = reservation.div[2]['key'] #是否预约按钮区域 res_button = reservation.div[3]['key'] #申请单列表区域 application_list = reservation.div[4]['key'] #患者列表区域 pai_detail = reservation.div[5]['key'] #申请单明细区域 application_detail = reservation.div[6]['key'] # 预约日期区域 calendar_xpath = reservation.div[7]['key'] #预约资源明细区域 res_resource_detail = reservation.div[8]['key'] #提示框 prompt = reservation.div[9]['key'] #确认预约框 sure_res = reservation.div[10]['key'] # reservation_type_elements = browser.find_element_by_xpath(reservation_type).find_elements_by_tag_name('button') if cache['pai_type'] == 'o': browser.find_element_by_link_text('门诊预约').click() elif cache['pai_type'] == 'i': browser.find_element_by_link_text('住院预约').click() swip_card_element = browser.find_element_by_xpath(swip_card).find_elements_by_tag_name('input') swip_card_element[0].send_keys(str(cache['userId'])+'\n') time.sleep(2) #选取申请单 for apply in apply_list: browser.find_element_by_xpath("//div[contains(text(),'"+apply+"')]").click() application_list_elements = browser.find_element_by_xpath(application_list).find_elements_by_tag_name('div') #预约当前时间最近的且预约人数<可预约人数 #当前时间 date = time.strftime("%Y-%m-%d", time.localtime()) remove_js = "document.getElementsByTagName('input')[16].removeAttribute('readonly')" focus_js = "document.getElementsByTagName('input')[16].blur()" input_locator = (By.XPATH,calendar_xpath+'//input[1]') img_locator = (By.XPATH,calendar_xpath+'//img[1]') common.calendar(browser,remove_js,focus_js,input_locator,img_locator,date) time.sleep(2) now = time.strftime("%Y-%m-%d %H:%M", time.localtime()) table_elements = browser.find_element_by_xpath(res_resource_detail).find_elements_by_tag_name('table') for table_element in table_elements: div_elements = table_element.find_elements_by_tag_name('div') if div_elements[3].text>now: print(div_elements[5].text) if div_elements[4].text>div_elements[5].text: div_elements[4].click() break browser.find_element_by_xpath("//button[contains(text(),'预约并确认')]").click() browser.find_element_by_xpath("//button[contains(text(),'是')]").click() # browser.find_element_by_xpath("//button[text()='确认')]").click() locator = (By.XPATH,"//button[text()='确认']") on_click(browser,locator) time.sleep(4) url = "检查预约单" utility.microsoft_xps_document_writer(url)
def __init__(self,List_action,ip): #浏览器对象 self. browser = Common.browser(ip) self.cachedata = Cache({}) self.List_action = List_action