def page_num(self): '''拿条数''' kk = self.get_element_by_xpath(page_nums).text log_info(kk) tt = regex("\d+", kk) log_info(tt) return tt
def check_database(self,sql): log_info(u"检查数据库") time.sleep(2) db = Oracle() result = db.run_sql(sql) db.disconnect() return result
def test_apply_page(self): log_info(u"跳转到角色列表页面") role = System(self.driver) role.skip() role.get_text_obscure('角色管理').click() role.get_text_obscure('角色列表').click() log_info(u"查询最新的数据") sql = ''' select role_name,role_desc from (select * from t_role_info order by create_time desc ) aa where rownum =1 ''' db = Oracle() result = db.run_sql(sql) role_name = unicode(result[0], 'utf-8') role_desc = unicode(result[1], 'utf-8') role.input_text('用户角色', role_name) role.get_text_accurate('查询').click() #检查序号 role.assert2('1', role.row_check(1).text, u'序号') #检查用户角色 role.assert2(role_name, role.row_check(2).text, u'用户角色') #检查角色描述 role.assert2(role_desc, role.row_check(3).text, u'角色描述')
def view_channel(self): '''渠道详情中的基本信息''' aa = self.page_num() kk = self.channel_data() time.sleep(2) if int(aa) > 0: self.view(channer_no=kk) tt = [] for i in range(1, 20): base_info1 = '(' + base_info + ')' + '[%d]' % i jieguo = self.get_element_by_xpath(base_info1).text if i == 6: jieguo = regex(('\d+'), jieguo) elif i == 10: jieguo = regex(('\d+'), jieguo) elif i == 11: jieguo = regex(('\d+'), jieguo) elif i == 12: jieguo = regex(('\d+'), jieguo) else: pass print '%d' % i + jieguo tt.append(jieguo) log_info(tt) return tt else: a = 0 return a
def test_apply_page(self): log_info(u"跳转到角色列表页面") object = System(self.driver) object.skip() time.sleep(2) object.get_text_obscure('组织架构').click() time.sleep(2) object.get_element_by_xpath('//*[@id="app"]/div/div[1]/div/div/ul/li[2]/li/li[4]/ul/li/li/span').click() time.sleep(2) object.get_text_obscure('中福彩').click() time.sleep(2) #点击第一行的修改按钮 object.row_check(8).click() #生成唯一ID dep_id = str(object.create_id()) #部门负责人 user_name = u'部门负责人' + dep_id object.input_text('部门负责人',user_name) #负责人电话 user_mobile = u'13534075566' object.input_text('负责人电话',user_mobile) #备注 desc = u'备注' + dep_id object.input_text('备注',desc) #状态 try: #如果是关闭状态,点击关闭变成开启 object.get_text_accurate('关闭').click() except: #如果不是关闭状态,点击开启变成关闭 object.get_text_accurate('开启').click() object.get_text_obscure('提交并保存').click() #所以状态为0,关闭 status = 0 else: status = 1 object.get_text_obscure('提交并保存').click() #根据部门名称,查询数据库数据 sql = ''' select principal,principal_mobile,remark,status from T_DEPT_INFO where principal='%s' '''%user_name db = Oracle() result = db.run_sql(sql) #得到部门负责人 user_name = unicode(result[0], 'utf-8') #得到负责人电话 user_mobile = unicode(result[1], 'utf-8') #得到备注 desc = unicode(result[2], 'utf-8') #检查 object.assert2(result[0],user_name,u'部门负责人') object.assert2(result[1],user_mobile,u'负责人电话') object.assert2(result[2],desc,u'备注') object.assert2(result[3],status,u'状态')
def delete_picture(self): """删除全部图片""" el = self.b.find_elements_by_xpath( "//span[@class='el-upload-list__item-delete']") for i in range(len(el)): self.b.execute_script("arguments[0].click();", el[i]) wait(1) log_info(u"删除全部的图片")
def select_recycled(self,str): """选择是否回收""" if str == 1: self.get_element_by_xpath("//label[text()='是否回收']/following-sibling::div/div/label[1]/span/span").click() log_info(u"是否回收选择:是") elif str == 2: self.get_element_by_xpath("//label[text()='是否回收']/following-sibling::div/div/label[2]/span/span").click() log_info(u"是否回收选择:否")
def select_Consumablestype(self, str): """选择耗材类型""" self.get_element_by_xpath("//input[@placeholder='请选择耗材类型']").click() if str == 1: self.get_element_by_xpath("//span[text()='投注卡']").click() log_info(u"耗材类型选择:投注卡") elif str == 2: self.get_element_by_xpath("//span[text()='其它']").click() log_info(u"耗材类型选择:其它")
def upload_picture(self, path): """上传图片""" el = self.get_element_by_xpath( "//input[@name='file']/preceding-sibling::i[1]") el.click() wait(1) os.system(path) wait(3) log_info(u"上传图片ok")
def ins(self): '''根据登陆用户拿相应的组织机构''' time.sleep(3) name=self.get_element_by_xpath(user_name).text user_ins_sql = ''' SELECT t.ins_id from T_USER_INS t left join T_USER_INFO k on t.user_id=k.user_id where k.account='%s' '''%name kk=Oracle().run_sql_list(user_ins_sql) log_info(kk) print "kk=%s"%kk kk1=kk[0] log_info(kk1) return kk1
def get_data(self, sql): try: log_info(u'执行sql语句:%s' % sql) self.cursor = self.conn.cursor() self.cursor.execute(sql) data = self.cursor.fetchall() return data except Exception, e: #回滚 self.conn.rollback() log_info(e)
def select_partsname(self, str): """选择配件名称""" button = self.get_element_by_xpath("//input[@placeholder='请选择配件名称']") self.b.execute_script("arguments[0].click()", button) wait(1) el = self.b.find_elements_by_xpath("//span[contains(text(),'%s')]" % str) el[0].click() name = el[0].text log_info(u"配件名称选择:%s" % name) return name
def run_sql_dir(self, sql): try: a = [] log_info(u'执行sql语句:%s' % sql) self.cursor = self.conn.cursor() self.cursor.execute(sql) data = self.cursor.fetchall() print "data=%s" % data # self.cursor.close() return data except Exception, e: #回滚 self.conn.rollback() log_info(e)
def click_del_button(self, num=''): """点击删除设备按钮""" k = 0 for i in range(20): el = self.b.find_elements(*self.del_btn) if el: el[0].click() k = k + 1 wait(1) if k == num: log_info(u"删除了%s个可用机型" % k) break else: break log_info(u"删除了%s个可用机型" % k)
def test_apply_page(self): log_info(u"跳转到页面") object = UserManager(self.driver) object.skip() object.get_text_obscure('新建用户').click() #生成唯一ID user_code = str(object.create_id()) user_name = u'自动化测试名字' + str(user_code) object.input_text('姓名',user_name) object.input_text('用户账号',user_name) user_mobile = object.create_mobile() object.input_text('手机号码',user_mobile) user_mail = u'*****@*****.**' object.input_text('邮箱',user_mail) object.get_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/div/div/form/div[5]/div/div/div[1]/input').click() object.click_radio('中福彩') object.get_text_obscure('所属部门').click() object.get_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/div/div/form/div[6]/div/div/div[1]/input').click() object.click_radio('自动化测试部门') object.get_text_obscure('用户角色').click() object.get_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/div/div/form/div[8]/div/div/div[2]/input').click() object.get_text_obscure('自动化测试角色').click() object.get_text_obscure('提交并保存').click() log_info(u"检查数据") sql = ''' select user_name,account,mobile,email,user_status,cc.ins_name from t_user_info aa left join t_user_ins bb on aa.user_id = bb.user_id left join t_ins_info cc on cc.ins_id = bb.ins_id where account='%s' '''%user_name db = Oracle() result = db.run_sql(sql) object.assert2(result[0],user_name,u'姓名') object.assert2(result[1],user_name,u'用户账号') object.assert2(result[2],user_mobile,u'手机号码') object.assert2(result[3],user_mail,u'邮箱') object.assert2(result[4],0,u'状态') object.assert2(result[5],u'中福彩',u'机构名称')
def test_apply_page(self): log_info(u"跳转到角色列表页面") object = System(self.driver) object.skip() time.sleep(2) object.get_text_obscure('组织架构').click() time.sleep(2) object.get_element_by_xpath( '//*[@id="app"]/div/div[1]/div/div/ul/li[2]/li/li[4]/ul/li/li/span' ).click() time.sleep(2) object.get_text_obscure('中福彩').click() object.get_text_obscure('添加部门').click() #生成唯一ID id = str(object.create_id()) dep_name = u'自动化测试部门' + id object.input_text('部门名称', dep_name) #部门负责人 user_name = u'部门负责人' + id object.input_text('部门负责人', user_name) #负责人电话 user_mobile = u'13534075566' object.input_text('负责人电话', user_mobile) #备注 desc = u'备注' + dep_name object.input_text('备注', desc) #状态 try: object.get_text_accurate('关闭').click() except: object.get_text_obscure('提交并保存').click() else: object.get_text_obscure('提交并保存').click() log_info(u"检查数据") sql = ''' select department_name,principal,principal_mobile,remark,status from T_DEPT_INFO where department_name='%s' ''' % dep_name db = Oracle() result = db.run_sql(sql) object.assert2(result[0], dep_name, u'部门名称') object.assert2(result[1], user_name, u'部门负责人') object.assert2(result[2], user_mobile, u'负责人电话') object.assert2(result[3], desc, u'备注') object.assert2(result[4], 1, u'状态')
def user_login(self,user_name='zxl_test',password='******'): '''用户登录''' log_info(u"开始登录") self.p = self.driver.get("http://10.6.0.203:8888/#/login") # username = u'zxl_test' # password = u'123456' time.sleep(5) un = self.driver.find_element_by_xpath('''//input[starts-with(@placeholder,'请输入用户账号')]''') pw = self.driver.find_element_by_xpath('''//input[starts-with(@placeholder,'请输入用户密码')]''') login_btn = self.driver.find_element_by_xpath('''//span[contains(text(),'登录')]''') # un.clear() # pw.clear() un.send_keys(user_name) pw.send_keys(password) login_btn.click() time.sleep(5)
def run_sql_LOB(self, sql): try: a = [] log_info(u'执行sql语句:%s' % sql) self.cursor = self.conn.cursor() tt = self.cursor.execute(sql) for row in tt: ss = row[0].read() print "ss=%s" % ss print type(ss) a.append(ss) return a except Exception, e: #回滚 self.conn.rollback() log_info(e)
def pageresult1(self): '''渠道列表中表单数据''' aa = self.page_num() kk = self.get_element_by_xpath(viewpath).text #拿第一行的channel no time.sleep(2) if int(aa) > 0: tt = [] table_data1 = '(' + table_data + ')' + '[1]' jieguo = self.get_element_by_xpath(table_data1).text tt.append(jieguo) log_info(tt) return tt else: a = 0 return a
def querydetail(self, channel_no=''): '''查询详情中内容''' # tt=self.channel_data() if channel_no == '': tt = self.channel_data() else: tt = channel_no if int(tt) > 0: sql = '''SELECT t.ins_name AS insName, case WHEN d.channel_type=0 then '自营厅' WHEN d.channel_type=1 then '合作厅' else NULL END, ( SELECT tcgi.ch_level_name FROM t_channel_grade_info tcgi WHERE tcgi.ch_grade_id = d.channel_level_id ) channelLevelName,d.channel_no AS channelNo, case WHEN a.RUN_FIELD=0 then '自有' WHEN a.RUN_FIELD=1 then '租用' else NULL END,a.POINT_AREA, d.channel_address AS channelAddress, d.longitude, d.latitude, d.buy_card_limit buyCardLimit, d.try_card_limit tryCardLimit, d.recharge_count rechargeCount, d.CHANNEL_LIMIT FROM t_channel_info d LEFT JOIN t_partner c ON d.partner_id = c.id INNER JOIN t_ins_info t ON d.ins_id = t.ins_id LEFT JOIN T_FINANCE_INFO a on a.channel_id=d.channel_id WHERE d.channel_no = '%s' ''' % tt t = Oracle() kk = t.run_sql_dir(sql) log_info(kk) return kk else: a = 0 return a
def test_apply_page(self): log_info(u"跳转到系统管理页面") object = System(self.driver) object.skip() object.get_text_list('数据字典') object.get_text_list('数据字典') object.get_text_obscure('新增字典').click() #生成唯一ID unique_id = str(object.create_id()) disc_name = u'字典名称' + unique_id object.get_element_by_xpath( '//*[@id="main"]/div/div/div[3]/div/div/div[2]/div/div/form/div[1]/div/div/input' ).send_keys(disc_name) #object.input_text('数据字典名称',disc_name) disc_key = u'字典键' + unique_id object.input_text('数据字典键', disc_key) disc_value = u'字典键值' + unique_id object.input_text('字典数据值', disc_value) disc_desc = u'描述' + unique_id object.input_text('描述', disc_desc) object.get_text_obscure('提交并保存').click() log_info(u"检查数据") sql = ''' select name,key,value,description,is_allow_delete from T_DICT_DATA where name='%s' ''' % disc_name db = Oracle() result = db.run_sql(sql) object.assert2(result[0], disc_name, u'字典名称') object.assert2(result[1], disc_key, u'字典键') object.assert2(result[2], disc_value, u'字典值') object.assert2(result[3], disc_desc, u'字典描述') object.assert2(result[4], 1, u'状态')
def select_goodstype(self, str): """选择物品类别""" button = self.get_element_by_xpath("//input[@placeholder='请选择']") self.b.execute_script("arguments[0].click()", button) if str == 1: self.get_element_by_xpath("//span[text()='设备']").click() log_info(u"物品类别选择:设备") elif str == 2: self.get_element_by_xpath("//span[text()='配件']").click() log_info(u"物品类别选择:配件") elif str == 3: self.get_element_by_xpath("//span[text()='耗材']").click() log_info(u"物品类别选择:耗材") elif str == 4: self.get_element_by_xpath("//span[text()='设施']").click() log_info(u"物品类别选择:设施") wait(1)
def select_terminaltype(self, str): """选择设备类型""" button = self.get_element_by_xpath("//input[@placeholder='请选择设备类型']") self.b.execute_script("arguments[0].click()", button) if str == 1: self.get_element_by_xpath("//span[text()='终端机']").click() log_info(u"设备类型选择:终端机") elif str == 2: self.get_element_by_xpath("//span[text()='柜员机']").click() log_info(u"设备类型选择:柜员机") elif str == 3: self.get_element_by_xpath("//span[text()='其它']").click() log_info(u"设备类型选择:其它") wait(1)
def test_apply_page(self): log_info(u"跳转到页面") object = System(self.driver) object.skip() time.sleep(2) object.get_text_obscure('组织架构').click() time.sleep(2) object.get_element_by_xpath( '//*[@id="app"]/div/div[1]/div/div/ul/li[2]/li/li[4]/ul/li/li/span' ).click() time.sleep(2) object.get_text_obscure('中福彩').click() object.get_text_obscure('新增').click() log_info(u"删除香港机构的数据") sql = ''' delete from T_INS_INFO where region_code=810000 ''' db = Oracle() result = db.sql_delete(sql) #生成唯一ID unique_id = str(object.create_id()) object.input_text('机构名称', u'香港') #机构编码 ins_id = unique_id object.option_text('请输入机构编码').send_keys(ins_id) #区域 object.option_text('请选择').click() object.get_text_obscure('香港特别行政区').click() #object.click_radio('香港特别行政区') #备注 desc = u'备注' + unique_id object.input_text('备注', desc) object.get_text_obscure('提交并保存').click() log_info(u"检查数据") sql = ''' select ins_name,ins_code,region_code,remark from T_INS_INFO where ins_code='%s' ''' % ins_id db = Oracle() result = db.run_sql(sql) object.assert2(result[0], u'香港', u'机构名称') object.assert2(result[1], ins_id, u'机构编码') object.assert2(result[2], 810000, u'地区编码') object.assert2(result[3], desc, u'备注')
def test_apply_page(self): log_info(u"跳转到角色列表页面") role = System(self.driver) role.skip() role.get_text_obscure('角色管理').click() role.get_text_obscure('角色列表').click() log_info(u"查询最新的数据") sql = ''' select role_name,role_desc,role_code from (select * from t_role_info order by create_time desc ) aa where rownum =1 ''' db = Oracle() result = db.run_sql(sql) role_name = unicode(result[0], 'utf-8') role_desc = unicode(result[1], 'utf-8') role_code = unicode(result[2], 'utf-8') role.input_text('用户角色', role_name) role.get_text_accurate('查询').click() try: role.get_text_accurate('启用').click() except: role.get_text_obscure('编缉').click() else: role.get_text_obscure('确定').click() role.get_text_obscure('编缉').click() #生成唯一ID role_code1 = str(role.create_id()) role_name = u'自动化测试角色' + str(role_code1) role.input_text('用户角色', role_name) role_desc = u'自动化测试角色描述' + str(role_code1) role.input_text('描述', role_desc) role.get_text_accurate('提交并保存').click() log_info(u"检查数据") sql = ''' select role_code,role_name,role_desc,status from t_role_info where role_code='%s' ''' % role_code db = Oracle() result = db.run_sql(sql) role.assert2(result[0], role_code, u'角色编码') role.assert2(result[1], role_name, u'角色名称') role.assert2(result[2], role_desc, u'角色描述') role.assert2(result[3], 0, u'角色状态')
def run_sql(self, sql): try: a = [] log_info(u'执行sql语句:%s' % sql) self.cursor = self.conn.cursor() self.cursor.execute(sql) data = self.cursor.fetchall() #print data for row in data: for data1 in row: a.append(data1) log_info(a) return a except Exception, e: #回滚 self.conn.rollback() log_info(e)
def test_apply_page(self): log_info(u"跳转到页面") object = Process(self.driver) object.skip() time.sleep(2) object.get_text_obscure('渠道新建').click() time.sleep(2) #生成唯一ID unique_id = str(object.create_id()) #所属机构 object.option_text('请选择所属机构').click() object.click_radio('新疆') #渠道类型 object.get_text_obscure('渠道类型').click() time.sleep(2) object.option_text('请选择渠道类型').click() object.get_text_list('自营厅') #渠道编号 channel_code = unique_id object.input_text('渠道编号', channel_code) #渠道等级 object.option_text('请选择渠道等级').click() object.get_text_obscure('一级').click() #经营场所属性 object.option_text('请选择经营场所属性').click() object.get_text_obscure('自有').click() #销售厅面积 sale_hall_area = 100 object.input_text('销售厅面积', sale_hall_area) #销售厅面积 sale_hall_area = 100 object.input_text('销售厅面积', sale_hall_area) #渠道地址 object.option_text('请选择省 / 市 / 区').click() object.get_text_list('新疆') object.get_text_list('乌鲁木齐市') object.get_text_list('天山区') #详细地址 address = u'天山区111222' object.option_text('填写详细地址').send_keys(address) #姓名 leader_name = u'销售厅经理' object.input_text('姓名', leader_name) #年龄 age = 18 object.input_text('年龄', age) #手机号码 mobile = object.create_mobile() object.input_text('手机号码', mobile) #身份证号 id_card = object.id_card() object.input_text('身份证号', id_card) #联系地址 address = u'自动化测试地址' object.input_text('联系地址', address) #卡数量 card_number = 10 object.option_text('请输入数量').send_keys(card_number) #收费 card_fee = 100 object.option_text('请输入金额').send_keys(card_fee) #销售游戏 object.get_text_obscure('禁止').click() object.get_text_obscure('禁止').click() #销售时间 object.option_text_list('开始时间') #选择资源类型 object.option_text('请选择资源类型').click() object.get_text_obscure('设备').click() #选择资源名称 object.option_text('请选择资源名称').click() object.get_text_obscure('终端机').click() #选择资源名称 object.option_text('请选择资源名称').click() object.get_text_obscure('终端机').click()
def input_Supplier(self, str): """输入供应商""" self.input_text(u'供应商', str) log_info(u"供应商输入:%s" % str)
def input_partsPrice(self, str): """输入配件单价""" self.input_text(u'配件单价(元)', str) log_info(u"配件单价(元)输入:%s" % str)
def input_terPrice(self, str): """输入设备单价""" self.input_text(u'设备单价(元)', str) log_info(u"设备单价(元)输入:%s" % str)