def setUp(self): self.sc = Config() self.b = BrowserDriver() self.driver = self.b.OpenBrowser() self.driver.implicitly_wait(30) # 全局隐形等待30S self.imgs = [] self.ym = YamlWrite()
class Test_Login(unittest.TestCase): def setUp(self): self.sc = Config() self.b = BrowserDriver() self.driver = self.b.OpenBrowser() self.driver.implicitly_wait(30) # 全局隐形等待30S self.imgs = [] self.ym = YamlWrite() def tearDown(self): self.b.QuitBrowser() def addimg(self): self.imgs.append(self.driver.get_screenshot_as_base64()) return True def test_login_correct(self): """ 测试用户名密码正确登录""" try: # 将用例名称写入casename.yaml文件中 self.ym.Write_Yaml( self.sc.getCasename_path(), {'casename': '用例%s执行开始' % sys._getframe().f_code.co_name}) logger.info('开始执行用例%s' % sys._getframe().f_code.co_name) self.b.by_find_element('name', 'account').send_keys( self.sc.getConfig('User').get('username')) self.b.by_find_element('name', 'password').send_keys( self.sc.getConfig('User').get('password')) self.b.driver.implicitly_wait(30) # 设置全局隐形等待时间 self.addimg() self.assertEqual('无纸化会议1', self.b.get_page_title()) logger.info('用例%s执行成功' % sys._getframe().f_code.co_name) except: logger.info('用例%s执行失败' % sys._getframe().f_code.co_name) raise def test_login_error_1(self): """ 测试用户名正确密码错误登录""" try: # 将用例名称写入casename.yaml文件中 self.ym.Write_Yaml( self.sc.getCasename_path(), {'casename': '用例%s执行开始' % sys._getframe().f_code.co_name}) logger.info('开始执行用例%s' % sys._getframe().f_code.co_name) self.b.by_find_element('name', 'account').send_keys( self.sc.getConfig('User').get('username')) self.b.by_find_element('name', 'password').send_keys('123') self.b.driver.implicitly_wait(30) # 设置全局隐形等待时间 self.addimg() self.assertEqual('无纸化会议1', self.b.get_page_title()) logger.info('用例%s执行成功' % sys._getframe().f_code.co_name) except: logger.info('用例%s执行失败' % sys._getframe().f_code.co_name) raise
def setUp(self): self.sc = Config() self.b = BrowserDriver() self.driver = self.b.OpenBrowser() self.driver.implicitly_wait(5) # 全局隐形等待30S self.imgs = [] self.ym = YamlWrite() # 每次执行用例前都登陆网页 self.b.by_find_element('name', 'account').send_keys( self.sc.getConfig('User').get('username')) self.b.by_find_element('name', 'password').send_keys( self.sc.getConfig('User').get('password')) self.b.by_find_element('id', 'login').click() # 点击用户分组 self.b.by_find_element('link_text', '组织架构').click()
def __init__(self): self.tk = tkinter.Tk() screenwidth = self.tk.winfo_screenwidth() screenheight = self.tk.winfo_screenheight() alignstr = '%dx%d+%d+%d' % (400, 500, (screenwidth - 400) / 2, (screenheight - 500) / 2) self.tk.resizable(0, 0) self.tk.geometry(alignstr) self.tk.title("无纸化自动化测试") self.ipvar = tkinter.StringVar() self.brwoservar = tkinter.StringVar() self.modulevar = tkinter.StringVar() self.path = "" self.r = Run_All() self.sc = Config() self.oldv = None YamlWrite().Write_Yaml(self.sc.getCasename_path(),{'casename':self.oldv})
def btn(self): if self.ipvar.get()=='' or self.ipvar.get()==None: tkinter.messagebox.showinfo('提示', 'IP地址不能为空') elif not re.match(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$",self.ipvar.get()): tkinter.messagebox.showinfo('提示','IP地址格式不正确') elif self.path=='' or self.path==None: self.save_path() # 报告地址为空时,点击Case会弹出路径选择 else: value = {'ip': self.ipvar.get(), 'browser': self.brwoservar.get(),'reportPath':self.path+'\\','moudle':self.modulevar.get()} YamlWrite().Write_Yaml(self.sc.getWriteIP(),value) # 将value写入ip.yaml文件中 # threads = [] # threads.append(threading.Thread(target=Run_All().Run_test_case_all)) # threads.append(threading.Thread(target=pc.listout)) # for t in threads: # t.daemon = True # t.start() self.listout() Run_All().Run_test_case_all()
def setUp(self): self.sc = Config() self.b = BrowserDriver() self.driver = self.b.OpenBrowser() self.driver.implicitly_wait(10) # 全局隐形等待30S self.imgs = [] self.ym = YamlWrite() # 每次执行用例前都登陆网页 self.b.by_find_element('name', 'account').send_keys( self.sc.getConfig('User').get('username')) self.b.by_find_element('name', 'password').send_keys( self.sc.getConfig('User').get('password')) self.b.by_find_element('id', 'login').click() # 点击用户分组 self.b.by_find_element( 'css', '#wrap > div > div.matter.clear > div.left_b.clear.fl.pob > div > div:nth-child(2) > div > ul > a:nth-child(2)' ).click()
def setUp(self): self.sc = Config() self.b = BrowserDriver() self.driver = self.b.OpenBrowser() self.driver.implicitly_wait(5) # 全局隐形等待30S self.imgs = [] self.ym = YamlWrite() # 每次执行用例前都登陆网页 self.b.by_find_element('name', 'account').send_keys(self.sc.getConfig('User').get('username')) self.b.by_find_element('name', 'password').send_keys(self.sc.getConfig('User').get('password')) self.b.by_find_element('id', 'login').click() # 先前往用户列表判断是否用用户 self.b.by_find_element('link_text', '用户列表').click() if self.b.isElementExist('xpath','//*[@id="datagrid-row-r1-1-0"]/td[4]/div') == False: # 判断列表内是否有用户,如果没有就创建用户 # 创建10个用户 for i in range(1, 20): if i % 2: self.b.by_find_element('class', 'l-btn-text').click() self.b.by_find_element('name', 'account').send_keys('admin%s' % i) self.b.by_find_element('name', 'password').send_keys('123456') self.b.by_find_element('name', 'username').send_keys('测试用户') self.b.by_find_element('xpath', '//*[@id="layui-layer%s"]/div[2]/form/div[2]/button[1]' % i).click() time.sleep(1) else: continue # 获取共x记录 self.usercount = self.b.by_find_element('css', '.pagination-info').text self.usercount = self.usercount[8:-2] # 再进入会议列表 self.b.by_find_element('link_text', '会议列表').click() # 获取总页数 self.page = self.b.by_find_element('xpath', '//*[@id="wrap"]/div/div[3]/div[2]/div/div[2]/div/div/div[3]/table/tbody/tr/td[8]/span').text self.page = self.page[1:-1] List = [] # 判断会议列表数据是否为空,或只有1页 if self.page == '0' or self.page == '1': # 将列表所有的会议名称添加进集合 for i in self.b.by_find_elements('css', '.datagrid-cell-c1-name'): List.append(i.text) else: for p in range(int(self.page)-1): for i in self.b.by_find_elements('css', '.datagrid-cell-c1-name'): List.append(i.text) self.b.by_find_element('css', '.pagination-next').click() time.sleep(1) # 每次执行用例都判断会议列表中是否有数据 if '测试铭牌设置' not in List: # 点击新增会议 self.b.by_find_element('link_text', '新增会议').click() # 会议名称 self.b.by_find_element('name', 'name').send_keys('测试铭牌设置') # 点击开始时间 self.b.by_find_element('css', '#add_meeting > div > div:nth-child(2) > div.Participants_fr.fl > ' 'span:nth-child(2) > input.textbox-text.validatebox-text').click() # 点击结束时间 self.b.by_find_element('css', '#add_meeting > div > div:nth-child(2) > div.Participants_fr.fl > ' 'span:nth-child(5) > input.textbox-text.validatebox-text').click() # 点击增加时间 self.b.by_find_element('css', 'body > div:nth-child(26) > div > div:nth-child(2) > span > ' 'span > a > a.spinner-arrow-up').click() # 点击确定 self.b.by_find_element('css', 'body > div:nth-child(26) > div > div.datebox-button > table > ' 'tbody > tr > td:nth-child(2) > a').click() # 点击新增确定 self.b.by_find_element('css', '#add_meeting > div > div:nth-child(7) > div:nth-child(1) > button').click() time.sleep(1) '''选择参会人''' # 点击'选择参会人' self.b.by_find_element('css', '.nav_one.n_1.fl.clear').click() time.sleep(1) # 鼠标悬浮在'请选择用户'上 self.b.move_to_element(By.CSS_SELECTOR, '.manage_btn.clear') # 全选用户 self.b.by_find_element('css', '#user-container > div > span > div.sprite_san.fr').click() # 点击确定 self.b.by_find_element('css', '.bottom_y.bottom_b1').click() time.sleep(1) # 进入会议资料界面 self.b.by_find_element('xpath', '//*[@id="wrap"]/div/div[3]/div[2]/div/div[2]/div/ul/a[5]').click() time.sleep(1) else: self.b.by_find_element('link_text', '测试铭牌设置').click() # 判断参会人界面中是否有参会人 if self.b.isElementExist('css', '#datagrid-row-r2-2-0 > td:nth-child(2) > div > span') == False: # 点击'选择参会人' self.b.by_find_element('css', '.nav_one.n_1.fl.clear').click() time.sleep(1) # 鼠标悬浮在'请选择用户'上 self.b.move_to_element(By.CSS_SELECTOR, '.manage_btn.clear') # 全选用户 self.b.by_find_element('css', '#user-container > div > span > div.sprite_san.fr').click() # 点击确定 self.b.by_find_element('css', '.bottom_y.bottom_b1').click() time.sleep(2) # 进入会议资料界面 self.b.by_find_element('xpath', '//*[@id="wrap"]/div/div[3]/div[2]/div/div[2]/div/ul/a[5]').click() time.sleep(1)