def testSponsorSelect(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # MM003 推荐组织-向下查询 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() # 指定元素:会员管理 button = driver.find_element_by_id('left_menu_1210') # 指定元素:菜单 menu = driver.find_element_by_class_name('nav-header') # 鼠标移动到会员管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() # 指定元素:推荐组织查询,并点击操作 driver.find_element_by_xpath( '//li[@id="left_menu_1214"]/a/span').click() # 移开鼠标 chain.move_to_element(menu).perform() time.sleep(1) # 切换至iframe driver.switch_to_frame('contentIframe1214') # 从数据库随机取会员编号 member = Oradao.sqlDiy( Oradao(), 'select * from (select * from mm_member m where m.company_code=\'' + state + '\' order by m.create_date desc) where rownum <=100') num = ranNo(0, member['ID'].__len__() - 1) member_no = member['MEMBER_NO'][num] member_id = member['ID'][num] # 输入会员编号,进行查询 driver.find_element_by_name('memberNo').send_keys(member_no) driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) # 点击展开 # driver.find_element_by_xpath('//tr[@id="'+str(member_id)+'"]/td[1]/span[2]').click() # 从数据库查该推荐人的直接下级会员编号和ID dMember = Oradao.sqlDiy( Oradao(), 'select * from mm_member m where m.sponsor_id=' + str(member_id) + 'order by m.create_date') # 统计直接下级会员数 dNum = dMember['ID'].__len__() # 循环取值进行断言(从页面获取会员编号并截取) for i in range(0, dNum): dMember_no = driver.find_element_by_xpath('//tr[@id="' + str(dMember['ID'][i]) + '"]/td[1]/span[4]').text dMemberNo = dMember_no[0:10] self.assertEquals(dMemberNo, dMember['MEMBER_NO'][i])
def getAreaIdByCode(state): sql = 'select * from sys_area where code = \'' + state + '\'' rs = Oradao.sqlDiy(Oradao(), sql) if rs['ID'].__len__() == 0: return None if 20 in rs['TYPE']: for i in range(rs['ID'].__len__()): if rs['TYPE'][i] == 20: return str(rs['ID']) else: return str(rs['PARENT_ID'][0])
def testTax(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1110') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在商品管理 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath( '//li[@id="left_menu_9214"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe9214') prdsql = 'select * from pm_composite_product' prodoctCom = Oradao.sqlDiy(Oradao(), prdsql) num = ranNo(0, prodoctCom['ID'].__len__() - 1) productNo = prodoctCom['CODE'][num] productName = prodoctCom['NAME'][num] productType = transData('compositeProduct.type').get( prodoctCom['TYPE'][num]) productNum = str(prodoctCom['QUATITY'][num]) productMemo = prodoctCom['MEMO'][num] driver.find_element_by_name('sp_code_EQ').send_keys(productNo) driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) rsName = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[1]').text rsCode = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[2]').text rsType = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[3]').text rsNum = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[4]').text rsMemo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[5]').text self.assertEquals(productName, rsName) self.assertEquals(productNo, rsCode) self.assertEquals(productType, rsType) self.assertEquals(productNum, rsNum) self.assertEquals(productMemo, rsMemo)
def testBoPlacement(self): driver = self.driver conf = self.conf # 切换语言 conf.boLangChange(driver, 'zh_CN') # 声明member对象 member = conf.member time.sleep(5) # 打开我的业务-安置网 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[2]/a').click() driver.find_element_by_id('8077').click() # 当前会员ID member_id = member['ID'] # 从页面获取该会员的各明细信息 member_no = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('memberno') member_status = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('memberstatustext') member_son = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('memberson') member_grade = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('membergradetext') order_date = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('firstorderbonusdate') member_name = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('membername') member_sponsorno = driver.find_element_by_id('memberDetail_'+str(member_id)).get_attribute('membersponsorno') # 断言明细信息 self.assertEqual(member_no, member['MEMBER_NO']) self.assertEqual(member_status, transData('member.status').get(member['STATUS'])) self.assertEqual(member_name, member['NAME'][0:19]) if order_date == '': self.assertEqual(order_date, member['JOIN_DATE']) else: self.assertEqual(order_date, member['JOIN_DATE'].strftime('%Y-%m-%d')) sponsor_no = Oradao.sqlDiy(Oradao(), 'select * from mm_member m where m.id=(select m.sponsor_id from mm_member m where m.member_no=\''+member['MEMBER_NO']+'\')') self.assertEqual(member_sponsorno, sponsor_no['MEMBER_NO'][0]) self.assertEqual(member_grade, transData('member.enrollmentGrade').get(member['ENROLLMENT_GRADE'])) # 判断当前会员是否有安置下线,有则对下线编号进行断言 if member_son > '0': # 数据库取安置下线 son_no = Oradao.sqlDiy(Oradao(), 'select * from mm_member m where m.placement_id=(select m.id from mm_member m where m.member_no=\''+member['MEMBER_NO']+'\') order by m.member_no asc') num = son_no['ID'].__len__() # 循环取下线编号进行断言 for i in range(0, num): member_sonId = son_no['ID'][i] member_sonNo = driver.find_element_by_id('memberDetail_'+str(member_sonId)).get_attribute('memberno') self.assertEqual(member_sonNo, son_no['MEMBER_NO'][i])
def get_last_stage(cur_stage): sql = '''select * from bm_Monthly_Batch where stage_Index = (select stage_Index from bm_Monthly_Batch where working_Stage='%s')-1''' data = Oradao().sqlDiy(sql % cur_stage[:-2]) if data['WORKING_STAGE'].__len__() == 1: return data['WORKING_STAGE'][0] else: raise Exception(u'获取上一个期别异常')
def __init__(self, type=None): member_sql = ''' SELECT mm.* FROM mm_member mm, sys_base_user sbu, sys_user_role sur WHERE mm.company_code = '%s' AND mm.enrollment_grade is not null AND mm.MEMBER_NO = sbu.LOGIN_NAME AND sbu.ID = sur.BASE_USER_ID AND sur.ROLE_ID in (7564,2154842,1658282) ''' # 取能下重消单的会员 if type == 1: member_sql = member_sql + 'and mm.enrollment_grade != 0' member_db = Oradao().sqlDiy(member_sql % self.state) num = 0 self.member = {} if member_db['ID'].__len__() > 0: num = ranNo(0, member_db['ID'].__len__() - 1) for i in member_db.items(): self.member.setdefault(i[0], i[1][num])
def get_cur_monthly(): sql = ''' SELECT * FROM bm_weekly_batch WHERE status = 0 AND date_From <= SYSDATE AND date_To >= SYSDATE ''' data = Oradao().sqlDiy(sql) if data['MONTHLY_WORKING'].__len__() == 1: return data['MONTHLY_WORKING'][0] else: raise Exception(u'获取当前工作月异常')
def transData(code): rs = {} # 奖衔 if code == 'awardsInf.awards': rs = { '0': '无奖衔', '01': '明日之星', '02': '明星', '03': '一星钻石', '04': '二星钻石', '05': '二星钻石精英', '06': '三星钻石', '07': '四星钻石', '08': '五星钻石', '09': '皇冠钻石', '10': '皇冠钻石大使' } else: sql = ''' SELECT slv.VALUE_CODE as code, scv.CHARACTER_VALUE as value FROM sys_character_value scv, sys_list_value slv, sys_list_key slk, sys_Character_key sck WHERE scv.Character_code = 'zh_CN' AND scv.KEY_ID IN ( SELECT id FROM sys_Character_key WHERE Character_key IN ( SELECT value_title FROM sys_list_value WHERE key_id = ( SELECT id FROM sys_list_key WHERE list_code = '%s'))) AND slk.ID = slv.KEY_ID AND slv.VALUE_TITLE = sck.CHARACTER_KEY AND sck.id = scv.KEY_ID ''' data = Oradao().sqlDiy(sql % code) for i in range(0, data['CODE'].__len__()): rs[data['CODE'][i]] = data['VALUE'][i] return rs
def testProductMsgNew(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1110') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在商品管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath( '//li[@id="left_menu_7069"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 获取地区显示名以便最后断言使用 state = conf.getState(driver) # 切换至iframe driver.switch_to_frame('contentIframe7069') # 点击新增 driver.find_element_by_id('btnAdd').click() driver.implicitly_wait(10) # 选择商品编码 driver.find_element_by_id('productNoButton').click() pdctFrame = driver.find_element_by_xpath( '//div[@id="myWindow"]/iframe') driver.switch_to_frame(pdctFrame) # 随机选择商品编码 product = Oradao().sqlDiy( 'SELECT id,product_no,product_name FROM pm_product WHERE id NOT IN (SELECT product_id FROM pm_product_sale where company_code = \'' + conf.state + '\') AND id IN (SELECT product_id FROM pm_composite_product)') productLen = product['ID'].__len__() - 1 ranList = ranNo(0, productLen) ranProductID = product['ID'][ranList] ranProductNo = product['PRODUCT_NO'][ranList] ranProductName = product['PRODUCT_NAME'][ranList] js = 'setParentValue(\'' + str(ranProductID) + '\',\'' + str( ranProductNo) + '\',\'' + str(ranProductName) + '\')' try: driver.execute_script(js) except EOFError: driver.get_screenshot_as_file('a.bmp') # 切回新增商品iframe driver.switch_to_default_content() driver.switch_to_frame('contentIframe7069') # 随机选择订单类型 orderType = driver.find_elements_by_xpath( '//select[@id="orderType"]/option') orderType[ranNo(0, orderType.__len__() - 1)].click() ranOrderType = driver.find_element_by_id('s2id_orderType').text # 输入随机商品销售名 ranSaleName = ranZNS(4) + ranEN(4) driver.find_element_by_id('saleName').send_keys(ranSaleName) # 选择随机税率 taxStrategy = driver.find_elements_by_xpath( '//select[@name="taxStrategy"]/option') taxStrategy[ranNo(0, taxStrategy.__len__() - 1)].click() ranTaxStrategy = driver.find_element_by_xpath( '//div[@id="s2id_autogen2"]/a/span').text # 选择状态 status = driver.find_elements_by_xpath( '//select[@name="delFlag"]/option') status[ranNo(0, status.__len__() - 1)].click() ranStatus = driver.find_element_by_xpath( '//div[@id="s2id_autogen4"]/a/span').text # BV,PV,价格,折扣价 ranBV = str(ranNo(100, 1000)) driver.find_element_by_id('bv').send_keys(ranBV) ranPV = str(ranNo(100, 1000)) driver.find_element_by_id('pv').send_keys(ranPV) ranAgio = str(ranNo(100, 1000)) driver.find_element_by_id('agioPrice').send_keys(ranAgio) ranPrice = ranNo(10, 10000) driver.find_element_by_xpath( '//div[@id="tabs"]/div[2]/div[1]/div/div[10]/div/span/input[1]' ).send_keys(ranPrice) driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) driver.find_element_by_name('sp_product.productNo_LIKE').send_keys( ranProductNo) driver.find_element_by_id('searchForm').submit() driver.implicitly_wait(10) rsNum = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() rsXpath = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(rsNum) + ']/td') # 获取查询结果各个字段值 rsSaleName = rsXpath[1].text rsType = rsXpath[2].text rsCompanyCode = rsXpath[3].text rsProductNo = rsXpath[4].text rsPrice = rsXpath[5].text.replace(",", "") rsBV = rsXpath[6].text.replace(",", "") rsPV = rsXpath[7].text.replace(",", "") rsStatus = rsXpath[8].text.replace(",", "") # 断言 self.assertEquals(rsSaleName, ranSaleName) self.assertEquals(rsType, ranOrderType) self.assertEquals(rsCompanyCode, state) self.assertEquals(rsProductNo, ranProductNo) self.assertEquals(rsPrice, "%.2f" % float(ranPrice)) self.assertEquals(rsBV, "%.2f" % float(ranBV)) self.assertEquals(rsPV, "%.2f" % float(ranPV)) self.assertEquals(rsStatus, ranStatus)
def testProductMsg(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1110') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在商品管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath( '//li[@id="left_menu_7069"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe7069') # 计算数据数量 pageSize = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() pageCount = pageSize # -2:除去上一页和下一页 pageNo = int( driver.find_elements_by_xpath('/html/body/div/div/div/ul/li/a') [-2].text) if pageNo > 1: driver.find_element_by_link_text(str(pageNo)).click() driver.implicitly_wait(10) lastPageSize = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() pageCount = pageSize * (pageNo - 1) + lastPageSize driver.find_element_by_link_text('1').click() # 测试商品信息数量 sqlCount = Oradao().sqlCount( 'select * from pm_product_sale where company_code=\'' + conf.state + '\'') # 断言 self.assertEquals(sqlCount, pageCount) # 测试根据商品编码查询 productMsg = Oradao().sqlDiy( 'select pps.ORDER_TYPE as ORDER_TYPE,pp.PRODUCT_NAME as PRODUCT_NAME,pp.PRODUCT_NO as PRODUCT_NO,pps.DEL_FLAG as DEL_FLAG,pps.SALE_NAME as SALE_NAME,' 'pps.COMPANY_CODE as COMPANY_CODE,pps.PRICE as PRICE,pps.BV as BV,pps.PV as PV from pm_product_sale pps,pm_product pp ' 'where pps.PRODUCT_ID = pp.ID and pps.COMPANY_CODE = \'' + conf.state + '\'') productMsgLen = productMsg['PRODUCT_NO'].__len__() productMsgNo = productMsg['PRODUCT_NO'][ranNo(0, productMsgLen - 1)] driver.find_element_by_name('sp_product.productNo_LIKE').send_keys( productMsgNo) driver.find_element_by_id('btnSubmit').click() rsCount = driver.find_elements_by_xpath( '//table[@id="contentTable1"]/tbody/tr') # 对每一列进行检查 for i in range(1, rsCount.__len__() + 1): rsProductNo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(i) + ']/td[4]/span') self.assertIn(productMsgNo, rsProductNo.text) pageNo = int( driver.find_elements_by_xpath('/html/body/div/div/div/ul/li/a') [-2].text) # 对每一页的每一列进行检查 if pageNo > 1: for i in range(2, pageNo + 1): driver.find_element_by_link_text(str(i)).click() driver.implicitly_wait(10) rsCount = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr') for n in range(1, rsCount.__le__() + 1): rsProductNo = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(n) + ']/td[4]/span') self.assertIn(productMsgNo, rsProductNo[n].text) # 对订单类型检查 driver.find_element_by_name('sp_product.productNo_LIKE').clear() orderTypeSelect = driver.find_elements_by_xpath( '//form[@id="searchForm"]/select[2]/option') # 第一个选项值为空,故从2开始随机 orderType = driver.find_element_by_xpath( '//form[@id="searchForm"]/select[2]/option[' + str(ranNo(2, orderTypeSelect.__len__())) + ']') orderTypeText = orderType.text orderType.click() driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) rsCount = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr') for i in range(1, rsCount.__len__() + 1): rsOrderType = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(i) + ']/td[3]/span') self.assertEquals(orderTypeText, rsOrderType.text) pageNo = int( driver.find_elements_by_xpath('/html/body/div/div/div/ul/li/a') [-2].text) # 对每一页的每一列进行检查 if pageNo > 1: for i in range(2, pageNo + 1): driver.find_element_by_link_text(str(i)).click() driver.implicitly_wait(10) rsCount = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() + 1 for n in range(1, rsCount): rsProductNo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(n) + ']/td[3]/span') self.assertEquals(orderTypeText, rsProductNo.text)
def testBoRegister(self): driver = self.driver conf = self.conf member = conf.member # 切换语言 conf.boLangChange(driver, 'zh_CN') driver.find_element_by_link_text('注册').click() driver.implicitly_wait(10) web_sponsor = driver.find_element_by_class_name('sponsor').text # 1.判断推荐人和当前用户是否一致 self.assertEquals(member['NAME'], web_sponsor) driver.find_element_by_xpath( '//div[@class="modal-footer"]/button[1]').click() time.sleep(2) # 2.选择国家 company = driver.find_element_by_css_selector('a[companycode="' + conf.state + '"]') company.click() time.sleep(2) # 选择语言,排除掉选择不同国家选项 lang = driver.find_elements_by_xpath( '//div[@id="myLangModal-' + company.get_attribute('companyid') + '"]/div/div/div[2]/a') lang_num = ranNo(0, lang.__len__() - 2) lang[lang_num].click() # 点击下一步 driver.implicitly_wait(10) driver.find_element_by_id('next').click() driver.implicitly_wait(10) # 3.下首购单 # 优先选择单品 product_sale_sql = ''' SELECT * FROM ( SELECT pps.* FROM pm_product_sale pps, pm_product pp WHERE pps.PRODUCT_ID = pp.ID AND pps.order_type = '%s' AND pps.company_code = '%s' AND pps.price > 0 AND pps.price < 500 AND pps.del_flag = '20' AND pp.PRODUCT_TYPE = '10' ORDER BY pps.sort_num ) WHERE ROWNUM <= 10 ''' product_sale = Oradao().sqlDiy(product_sale_sql % (10, conf.state)) if product_sale['ID'].__len__() > 0: ran_item = ranNo(0, product_sale['ID'].__len__() - 1) product_sale_id = product_sale['ID'][ran_item] else: raise Exception(u'数据库中无符合要求的单品') productitem = driver.find_element_by_css_selector( 'input[productsaleid="' + str(product_sale_id) + '"]') productitem.send_keys('1') # 点击任意地方获取当前BV driver.find_element_by_id('grade_distributor').click() time.sleep(1) total_bv = int( driver.find_element_by_id( 'showOrderUl').find_element_by_class_name('amount').text) # 判断总BV是否满足50,否则重新设置数量 if total_bv >= 50: driver.find_element_by_id('next').click() else: productitem.clear() time.sleep(1) productitem.send_keys(50 // total_bv + 1) driver.find_element_by_id('grade_distributor').click() driver.find_element_by_id('next').click() # 4.设置自动重消单 product_sale = Oradao().sqlDiy(product_sale_sql % (30, conf.state)) if product_sale['ID'].__len__() > 0: ran_item = ranNo(0, product_sale['ID'].__len__() - 1) product_sale_id = product_sale['ID'][ran_item] else: raise Exception(u'数据库中无符合要求的单品') time.sleep(2) productitem = driver.find_element_by_css_selector( 'input[productsaleid="' + str(product_sale_id) + '"]') productitem.send_keys(ranNo(0, 3)) driver.find_element_by_id('next').click() # 5.填写个人信息 driver.implicitly_wait(10) # 性别 sex_el = driver.find_elements_by_name('sex')[ranNo( 0, driver.find_elements_by_name('sex').__len__() - 1)] web_sex = sex_el.get_attribute('value') sex_el.click() # 姓名 web_name = ranEN(5) driver.find_element_by_id('name').send_keys(web_name) # 生日 web_birthday = '19' + str(ranNo(10, 99)) + '-0' + str(ranNo( 1, 9)) + '-' + str(ranNo(10, 28)) driver.find_element_by_id('birthDay').send_keys(web_birthday) # 选择国籍 web_nation = random_select_by_id(driver, 'nationalityId', 1).get_attribute('value') # 选择语言 web_lang = random_select_by_id(driver, 'languageCode', 1) # 选择注册类型 web_regist = random_select_by_id(driver, 'registrationType', 1) if web_regist.text == u'公司' or web_regist.text == u'company': driver.find_element_by_id('company').send_keys(ranEN(5)) # 日间电话 web_day_phone = str(ranNo(10000000000, 13999999999)) driver.find_element_by_id('daytimePhone').send_keys(web_day_phone) # 晚间电话 web_night_phone = str(ranNo(10000000000, 13999999999)) driver.find_element_by_id('eveningPhone').send_keys(web_night_phone) # 电话 web_phone = str(ranNo(10000000000, 13999999999)) driver.find_element_by_id('mobilePhone').send_keys(web_phone) # 邮箱 web_mail = ranEN(6) + '@' + ranEN(2) + '.com' driver.find_element_by_id('email').send_keys(web_mail) # 国家 web_country = random_select_by_id(driver, 'homeAddress.countryId', 1) # 省份 time.sleep(2) # 有可能选到没有省份的国家,故选择两次 try: web_province = random_select_by_id(driver, 'homeAddress.provinceId', 1) except: web_province = random_select_by_id(driver, 'homeAddress.provinceId', 1) # 城市 web_city = ranEN(4) driver.find_element_by_id('homeAddress.cityName').send_keys(web_city) # 邮编 web_postcode = str(ranNo(100000, 999999)) driver.find_element_by_id('homeAddress.postalCode').send_keys( web_postcode) # 家庭住址 web_adress = web_province.text + '-' + web_city + '-' + ranEN(4) driver.find_element_by_id('homeAddress.address').send_keys(web_adress) # 安置人编号,先判断是否自动安置 Placement = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER_CHANGE c where c.member_id=' + str(member['ID']) + 'and c.operate_type=50 order by c.create_date desc') len = Placement['ID'].__len__() if len == 0: value = 0 else: value = Placement['NEW_VALUE'][0] if value == 0: driver.find_element_by_id('placementNo').send_keys( member['MEMBER_NO']) # SSN社会保险号/税号 web_sin = random_select_by_id(driver, 'sinTaxType', 0) web_sin_no = ranNo(100000000, 999999999) driver.find_element_by_id('sinTaxId').send_keys(web_sin_no) # 账号 web_account = web_name + '-account-' + ranEN(4) driver.find_element_by_id('eAccountNumber').send_keys(web_account) # 银行账号 web_bank_name = 'bank-' + ranEN(4) driver.find_element_by_id('bankName').send_keys(web_bank_name) # 业务中心 # 网页名字 web_website_name = 'web_' + ranEN(2) + '_' + str(ranNo(10, 99)) driver.find_element_by_id('websiteName').send_keys(web_website_name) # 密码及确认密码 driver.find_element_by_id('password').send_keys('123456') driver.find_element_by_id('replatePassword').send_keys('123456') # 发货信息 # 选择家庭住址 driver.find_element_by_id('shipOrderAddressType0').click() # 自动单信息 # 首次付款日期,选择当天日期 driver.find_element_by_id('firstBillDate').click() time.sleep(1) driver.switch_to_frame(driver.find_element_by_tag_name('iframe')) # 选择第一个可选日期 driver.find_element_by_class_name('Wwday').click() # driver.find_element_by_id('dpTodayInput').click() # driver.find_element_by_id('dpOkInput').click() driver.switch_to_default_content() driver.implicitly_wait(10) # 账单/付款 # 支付方式,选择到公司支付 driver.find_element_by_id('registerFeePayType1').click() # 选择账单地址 driver.find_element_by_id('payAddressType0').click() # 接受条款 driver.find_element_by_id('isAcceptTerms').click() # 提交申请 driver.find_element_by_id('next').click() driver.implicitly_wait(10) # 验证注册信息 rs = driver.find_elements_by_xpath( '//div[@class="panel-body"]/div/div/ul/li') if rs.__len__() > 0: # 验证会员编号 # 会员姓名验证 self.assertEqual(rs[0].text, web_name) else: error_msg = '' error = driver.find_elements_by_class_name('formErrorContent') for i in range(error.__len__()): error_msg += error[i].text raise Exception(u'提交注册信息失败,提示为' + error_msg) # 会员ID rs_member_no = rs[1].find_element_by_tag_name('span').text # 推荐人名称 rs_sponsor_name = rs[3].find_element_by_tag_name('span').text member_sql = 'select * from mm_member where member_no = \'%s\'' sponsor_sql = 'select * from mm_member where id = \'%s\'' member_db = Oradao().sqlDiy(member_sql % rs_member_no) if member_db['ID'].__len__() == 1: # 验证推荐人,安置人 rs_sponsor_id = member_db['SPONSOR_ID'][0] rs_placement_id = member_db['PLACEMENT_ID'][0] sponsor_db = Oradao().sqlDiy(sponsor_sql % rs_sponsor_id) placement_db = Oradao().sqlDiy(member_sql % member['MEMBER_NO']) # 验证推荐人,安置人ID是否一致 self.assertEquals(rs_sponsor_name, sponsor_db['NAME'][0]) self.assertEquals(rs_placement_id, placement_db['ID'][0]) # 验证性别 self.assertEquals(member_db['GENDER'][0], web_sex) # 验证国籍 self.assertEquals(str(member_db['NATIONALITY_ID'][0]), web_nation) # 验证生日 self.assertEquals(member_db['BIRTHDAY'][0].strftime('%Y-%m-%d'), web_birthday) # 验证日间电话 self.assertEquals(member_db['TELEPHONE'][0], web_day_phone) # 验证晚间电话 self.assertEquals(member_db['EVENING_PHONE'][0], web_night_phone) # 验证电话 self.assertEquals(member_db['MOBILE_PHONE'][0], web_phone) # 验证邮箱 self.assertEquals(member_db['EMAIL'][0], web_mail) else: raise Exception(u'会员信息验证失败') # 验证登录成功 driver.find_element_by_class_name('ots').find_element_by_tag_name( 'a').click() driver.implicitly_wait(10) driver.find_element_by_id('password').send_keys('123456') driver.find_element_by_id('btnLogin').click() driver.implicitly_wait(10) # 将顶部会员信息分割开,取编码 bo_member_no = driver.find_element_by_class_name( 'username-hide-mobile').text.split('|')[1].strip(' ') # 验证会员编码 self.assertEquals(rs_member_no, bo_member_no)
def testBoAutoOrder(self): driver = self.driver conf = self.conf # 切换语言 conf.boLangChange(driver, 'zh_CN') time.sleep(2) # 打开订单-自动重消单 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[4]/a').click() driver.find_element_by_id('2189909').click() time.sleep(2) # 新增自动重消单 if conf.env == 'sandbox': driver.get( 'https://sandbox-d-v1.jmtop.com/backOffice/autoOrder/autoOrderProductList' ) elif conf.env == 'production': driver.get( 'https://dist.jmtop.com/backOffice/autoOrder/autoOrderProductList' ) # 更新购物车 driver.find_element_by_xpath( '//form[@id="storeForm40"]/div/div/div/a').click() # 数据库随机取商品编码 product = Oradao.sqlDiy( Oradao(), 'select s.id,p.product_no from pm_product_sale s,pm_product p where p.id=s.product_id and s.order_type=30 and s.company_code=\'' + conf.state + '\' and p.product_type=10 and s.del_flag=\'20\'') num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][num] product_no = product['PRODUCT_NO'][num] driver.find_element_by_name('sp_product.productNo_LIKE').send_keys( product_no) # 点击查询 driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) # 结算 if conf.env == 'sandbox': driver.get( 'https://sandbox-d-v1.jmtop.com/backOffice/autoOrder/autoOrderProductList' ) elif conf.env == 'production': driver.get( 'https://dist.jmtop.com/backOffice/autoOrder/autoOrderProductList' ) # 下一步 driver.find_element_by_id('addToCart_40').click() time.sleep(2) # 自提 driver.find_element_by_id('isSelfPickup1').click() time.sleep(2) # 下一步 driver.execute_script('scrollTo(0,1000)') driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 填自动下单信息 driver.find_element_by_id('description').send_keys('test') driver.find_element_by_id('nextRunDate').send_keys('2060-12-01') driver.find_element_by_id('cardHolderName').send_keys('test') driver.find_element_by_id('bankCardNo').send_keys('4444333322221111') Select( driver.find_element_by_name("expirationYear")).select_by_index(10) driver.find_element_by_id('securityCode').send_keys('123') driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 提交订单 driver.execute_script('scrollTo(0,1000)') driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) # 判断返回卡信息错误 message = driver.find_element_by_class_name('toast-message').text[0:8] self.assertEqual(message, u'保存自动订单失败')
def testMemberAdd(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # MM002 添加会员 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() # 指定元素:会员管理 button = driver.find_element_by_id('left_menu_1210') # 指定元素:菜单 menu = driver.find_element_by_class_name('nav-header') # 鼠标移动到会员管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) # 指定元素:会员信息维护,并点击操作 driver.find_element_by_xpath( '//li[@id="left_menu_1211"]/a/span').click() chain.move_to_element(menu).perform() time.sleep(1) # 切换至iframe driver.switch_to_frame('contentIframe1211') # 添加会员 if not driver.find_element_by_id('btnAdd').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_id('btnAdd').click() driver.implicitly_wait(10) # 输入会员名称 member_name = ranEN(8) time.sleep(2) driver.find_element_by_name('name').send_keys(member_name) # 从数据库查推荐人&安置人编号(取最新一条) member = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER m where m.company_code=\'' + state + '\' order by m.create_date desc') member_no = member['MEMBER_NO'][0] member_id = member['ID'][0] driver.find_element_by_name('sponsorMemberNo').send_keys(member_no) # 判断是否自动安置 Placement = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER_CHANGE c where c.member_id=' + str(member_id) + 'and c.operate_type=50 order by c.create_date desc') len = Placement['ID'].__len__() if len == 0: value = 0 else: value = Placement['NEW_VALUE'][0] if value == 0: driver.find_element_by_name('placementMemberNo').send_keys( member_no) # 输入身份证 if state == 'US': identification = str(ranNo(100000000, 999999999)) else: identification = str(ranNo(400000000000000000, 999999999999999999)) driver.find_element_by_id('sinTaxId').send_keys(identification) # 输入移动电话 mobilePhone = str(ranNo(13500000000, 13799999999)) driver.find_element_by_id('mobilePhone').send_keys(mobilePhone) # 保存 driver.switch_to_default_content() driver.execute_script('scrollTo(0,500)') driver.switch_to_frame('contentIframe1211') driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(20) # 依次 点击 2个 返回 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1211') driver.find_element_by_xpath( '//form[@id="inputForm"]/div[1]/div[3]/input[12]').click() driver.switch_to_default_content() driver.execute_script('scrollTo(0,500)') driver.switch_to_frame('contentIframe1211') driver.find_element_by_xpath( '//div[@id="showSaveDiv"]/div/input[5]').click() driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1211') # 新增会员断言 memberNew = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER m where m.company_code=\'' + state + '\' order by m.create_date desc') memberNo = memberNew['MEMBER_NO'][0] if not driver.find_element_by_id('btnAdd').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_memberNo_ILIKE').send_keys(memberNo) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 获取列表会员编号 rsMemberNo = driver.find_elements_by_xpath( '//table[@id="treeTable1"]/tbody/tr/td[2]')[0].text self.assertEquals(rsMemberNo, memberNo)
def testSponsorChange(self): driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 读取配置文件-取state值 conf = Initialize() state = conf.state # MM007 推荐组织调整-添加&审核 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() # 指定元素:会员管理 button = driver.find_element_by_id('left_menu_1210') # 指定元素:菜单 menu = driver.find_element_by_class_name('nav-header') # 鼠标移动到会员管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() # 指定元素:推荐网络调整,并点击操作 driver.find_element_by_xpath( '//li[@id="left_menu_2502"]/a/span').click() # 移开鼠标 chain.move_to_element(menu).perform() time.sleep(1) # 切换至iframe driver.switch_to_frame('contentIframe2502') # 点击添加 driver.find_element_by_id('btnAdd').click() driver.implicitly_wait(10) # 从数据库随机取出可用的会员编号和新推荐人 member = Oradao.sqlDiy( Oradao(), 'select c.member_no as newSponsor_no,b.member_no,b.create_date from mm_member a, mm_member b, mm_member c where a.id = b.placement_id and c.id = a.placement_id and a.placement_id is not null and a.placement_id !=b.sponsor_id and a.company_code=\'' + state + '\' and b.company_code=\'' + state + '\'and c.company_code=\'' + state + '\'and to_char(b.create_date,\'yyyy-mm-dd\')>to_char(sysdate-3,\'yyyy-mm-dd\') order by b.create_date desc' ) num = ranNo(0, member['MEMBER_NO'].__len__() - 1) member_no = member['MEMBER_NO'][num] newSponsor_no = member['NEWSPONSOR_NO'][num] # 在页面输入取到的数据 driver.find_element_by_id('memberNo').send_keys(member_no) driver.find_element_by_name('parentNo').send_keys(newSponsor_no) # 点击保存 driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 按会员编号查询 driver.find_element_by_name('sp_member.memberNo_EQ').send_keys( member_no) driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) # 统计查到多少条记录 count = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() # 从数据库取最新那条数据的创建时间 sponsor_change = Oradao.sqlDiy( Oradao(), 'select s.create_date,m.member_no,s.sponsor_id,s.status from mm_sponsor_ref_change s,mm_member m where s.member_id=m.id and m.member_no=\'' + member_no + '\' order by s.create_date desc') createDate = sponsor_change['CREATE_DATE'][0].strftime( '%Y-%m-%d %H:%M:%S') # 循环取出各记录的创建时间,与数据库最新的对比,得到最新那条记录 for i in range(1, count + 1): asCreateDate = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(i) + ']/td[5]').text # 先把创建时间后的空格过滤 if asCreateDate.strip(' ') == createDate: break # 点击审核 driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[' + str(i) + ']/td[9]/a[1]').click() time.sleep(2) # 选择通过 或 不通过 check_num = ranNo(1, 2) driver.find_element_by_xpath( '//form[@id="inputForm"]/div[6]/div/input[' + str(check_num) + ']').click() time.sleep(2) # 点击保存 driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 审核后核对数据库该审核状态 status = Oradao.sqlDiy( Oradao(), 'select s.create_date,m.member_no,s.sponsor_id,s.status from mm_sponsor_ref_change s,mm_member m where s.member_id=m.id and m.member_no=\'' + member_no + '\' order by s.create_date desc') if check_num == 1: self.assertEqual(int(status['STATUS'][0]), 1) else: self.assertEqual(int(status['STATUS'][0]), 0)
def testOrderView(self): driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # OM001 订单查询 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在销售管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) driver.find_element_by_xpath( '//li[@id="left_menu_1121"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe1121') # 从数据库随机取一个订单编号 order = Oradao.sqlDiy( Oradao(), 'select * from om_orders o,mm_member m where m.id=o.member_id and o.company_code=\'' + conf.state + '\'and o.doc_no like \'M%\'') num = ranNo(0, order['DOC_NO'].__len__() - 1) doc_no = order['DOC_NO'][num] # 把随机取到的订单编号放到页面查询 if not driver.find_element_by_id('btnSubmit').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_docNo_LIKE').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 按订单编号查询到的条数,判断是否1条 rsNum = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() - 1 self.assertEquals(rsNum, 1) # 获取列表各字段数据 rsXpath = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[' + str(rsNum) + ']/td') if conf.env == 'production': rsDocNo = rsXpath[1].text rsOrderType = rsXpath[3].text rsOrderDate = rsXpath[5].text rsOrderBonus = rsXpath[6].text rsOrderMember = rsXpath[7].text rsOrderPV = rsXpath[9].text rsOrderBV = rsXpath[10].text rsOrderPrice = rsXpath[11].text rsOrderStatus = rsXpath[12].text else: rsDocNo = rsXpath[1].text rsOrderType = rsXpath[2].text rsOrderDate = rsXpath[4].text rsOrderBonus = rsXpath[5].text rsOrderMember = rsXpath[6].text rsOrderPV = rsXpath[8].text rsOrderBV = rsXpath[9].text rsOrderPrice = rsXpath[10].text rsOrderStatus = rsXpath[11].text # 断言 self.assertEquals(rsDocNo, doc_no) self.assertEqual( rsOrderType, transData('order.orderType').get(order['ORDER_TYPE'][num])) self.assertEqual( rsOrderDate, order['ORDER_DATE'][num].strftime('%Y-%m-%d %H:%M:%S')) if rsOrderBonus == '': self.assertEqual(rsOrderBonus, order['BONUS_DATE'][num]) else: self.assertEqual(rsOrderBonus, order['BONUS_DATE'][num].strftime('%Y-%m-%d')) self.assertEqual(rsOrderMember, order['MEMBER_NO'][num] + ' / ' + order['NAME'][num]) self.assertEqual(rsOrderPV.replace(',', ''), "%.2f" % float(order['TOTAL_PV'][num])) self.assertEqual(rsOrderBV.replace(',', ''), "%.2f" % float(order['TOTAL_BV'][num])) self.assertEqual(rsOrderPrice.replace(',', ''), "%.2f" % float(order['TOTAL_NET_AMOUNT'][num])) if order['ORDER_STATUS'][num] != '10': self.assertEqual( rsOrderStatus, transData('order.orderStatus').get(order['ORDER_STATUS'][num]))
def testBoPlacementSet(self): driver = self.driver conf = self.conf # 切换语言 conf.boLangChange(driver, 'zh_CN') driver.implicitly_wait(5) num = ranNo(0, 2) if num != 0: # 打开我的账户-设置 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[5]/a').click() time.sleep(2) driver.find_element_by_id('8100').click() driver.implicitly_wait(5) # 修改密码 driver.execute_script('scrollTo(0,1000)') driver.find_element_by_id('emailId').clear() driver.find_element_by_id('emailId').send_keys('*****@*****.**') driver.find_element_by_id('passwordId').send_keys('123456') driver.find_element_by_id('confirmNewPasswordId').send_keys('123456') driver.find_element_by_xpath('//div[@id="tab_1_1"]/div[3]/div/div/button[1]').click() time.sleep(2) # 关闭提示弹框 driver.switch_to_alert().accept() time.sleep(2) # 退出重新登录 # driver.find_element_by_class_name('username-hide-mobile').click() if conf.env == 'sandbox': driver.get('https://sandbox-d-v1.jmtop.com/backOffice/logout') elif conf.env == 'production': driver.get('https://dist.jmtop.com/backOffice/logout') driver.implicitly_wait(10) driver.find_element_by_id('password').send_keys('123456') time.sleep(2) driver.find_element_by_id('btnLogin').click() driver.implicitly_wait(5) # 打开我的业务-安置网系谱 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[2]').click() driver.implicitly_wait(10) driver.find_element_by_id('8078').click() time.sleep(2) # 点击安置设置 driver.find_element_by_id('placementSettingBtn').click() time.sleep(2) # 随机设置 driver.find_elements_by_id('placementSetting')[num].click() time.sleep(2) # 点击保存 driver.find_element_by_id('placementSettingFormBtn').click() driver.implicitly_wait(5) # 输入登录密码 if num != 0: driver.find_element_by_id('first-time-psw').send_keys('123456') driver.find_element_by_id('placementSettingAgreeBtn').click() driver.implicitly_wait(5) driver.find_element_by_id('second-time-psw').send_keys('123456') driver.find_element_by_id('placementSettingRepeatOK').click() driver.implicitly_wait(5) # 当前登录的会员 member = conf.member member_id = member['ID'] # 断言 value = Oradao.sqlDiy(Oradao(), 'select * from MM_MEMBER_CHANGE c where c.member_id=' + str(member_id) + 'and c.operate_type=50 order by c.create_date desc')['NEW_VALUE'][0] self.assertEqual(num, int(value))
def testOrderChangeAdd(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # OM004 换货单管理-添加 # 先构造一条交易完成的订单数据(待发货--》交易完成) driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) time.sleep(2) driver.find_element_by_xpath( '//li[@id="left_menu_1121"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) driver.switch_to_frame('contentIframe1121') orderNo = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.company_code=\'' + state + '\'and o.order_status=20 and o.doc_no like \'M%\'and to_char(o.create_date,\'yyyy-mm-dd\')>=\'2016-01-01\'' ) num = ranNo(0, orderNo['DOC_NO'].__len__() - 1) orderType = orderNo['ORDER_TYPE'][num] status = '20' while status != '50': doc_no = orderNo['DOC_NO'][num] driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_docNo_LIKE').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) driver.find_element_by_xpath('//li[@id="accountmenu"]/a/i').click() driver.find_element_by_xpath( '//li[@id="accountmenu"]/ul/li[1]/a').click() try: driver.find_element_by_xpath( '//div[@id="jbox-state-state0"]/div[2]/button[1]').click() orderStatus = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.doc_no=\'' + doc_no + '\'') status = orderStatus['ORDER_STATUS'][0] except: orderStatus = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.doc_no=\'' + doc_no + '\'') status = orderStatus['ORDER_STATUS'][0] # 进行换货单操作 # 鼠标悬停在销售管理上 driver.switch_to_default_content() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) # 选择换货单管理 driver.find_element_by_xpath( '//li[@id="left_menu_28740"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe28740') # 点击添加 driver.find_element_by_id('btnAdd').click() time.sleep(2) # 点击选择原订单号 driver.find_element_by_id('memberIdButton').click() # 切换至订单选择框的iframe driver.switch_to_frame('jbox-iframe') # 用构造好的交易完成的订单进行换货,放到页面查询,点击选择 driver.find_element_by_name('sp_docNo_EQ').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[1]/a').click() # 获取退回商品的BV、数量与原订单状态 driver.switch_to_default_content() driver.switch_to_frame('contentIframe28740') len = driver.find_elements_by_xpath( '//table[@id="table1"]/tbody/tr').__len__() total_bv = 0 for i in range(1, len + 1): cBv = driver.find_elements_by_xpath( '//table[@id="table1"]/tbody/tr[' + str(i) + ']/td')[3].text cCount = driver.find_elements_by_xpath( '//table[@id="table1"]/tbody/tr[' + str(i) + ']/td[6]/input')[0].get_attribute('value') total_bv = total_bv + int(cBv) * int(cCount) # 选择换货商品 driver.find_element_by_id('productButton').click() # 切换至商品选择框的iframe driver.switch_to_frame('jbox-iframe') # 循环添加退回商品直到bv>=原订单商品(从数据库随机退回商品编号,放到页面查询,点击选择) product = Oradao.sqlDiy( Oradao(), 'select * from pm_product_sale p,pm_product pp where p.product_id=pp.id and p.company_code=\'' + state + '\'and p.order_type=\'' + orderType + '\'and p.del_flag=\'20\' and pp.product_type=10') bv = 0 while bv < total_bv: num = ranNo(0, product['ID'].__len__() - 1) productNo = product['PRODUCT_NO'][num] driver.find_element_by_name('sp_product.productNo_LIKE').send_keys( productNo) driver.find_element_by_id('btnSubmit').click() time.sleep(2) try: driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[1]/a').click() bv = bv + int(product['BV'][num]) driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() except: driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() # 移动最外层滚动条,关闭选择商品框 driver.switch_to_default_content() driver.execute_script('scrollTo(0,300)') driver.switch_to_frame('contentIframe28740') driver.find_element_by_xpath( '//div[@id="jbox-state-state0"]/div[2]/button').click() driver.implicitly_wait(10) # 点击结算 # driver.switch_to_default_content() # driver.execute_script('scrollTo(0,0)') # driver.switch_to_frame('contentIframe28740') driver.find_element_by_id('btnSubmit').click() # 点击保存 driver.switch_to_default_content() driver.execute_script('scrollTo(0,5000)') driver.switch_to_frame('contentIframe28740') price = driver.find_element_by_id('subTotal').text driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 页面滚动到最顶 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe28740') # 但应付金额大于0时,则选择现金进行支付操作 if price > '0.00': driver.find_element_by_xpath( '//form[@id="payForm"]/div[4]/div/p[1]/input[1]').click() driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 支付成功,点击返回 driver.find_element_by_id('btnSubmit').click() driver.implicitly_wait(10) # 断言 # 按原订单号进行查询,获取页面查询到的换货订单号 if not driver.find_element_by_id('btnSubmit').is_displayed(): driver.find_element_by_name('sp_orders.docNo_LIKE').send_keys( doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) rsDocNo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[1]/a[1]').text # 从数据库搜索新增的换货订单编号 change_order = Oradao.sqlDiy( Oradao(), 'select * from om_change_orders co where co.company_code=\'' + state + '\' order by co.doc_no desc') docNo = change_order['DOC_NO'][0] self.assertEquals(rsDocNo, docNo)
def order(self): driver = self.driver conf = self.conf member = conf.member member_no = member['MEMBER_NO'] member_id = member['ID'] # 会员级别 member_grade = Oradao.sqlDiy( Oradao(), 'select * from mm_member m where m.member_no=\'' + member_no + '\'')['ENROLLMENT_GRADE'][0] # 会员电子钱包余额 wm_value = Oradao.sqlDiy( Oradao(), 'select * from wm_finance_info f where f.account=\'' + member_no + '\'and f.ewallet_type=1')['TOTAL_EWALLET_VALUE'][0] # 下单-根据当前会员级别,确定下单类型 if member_grade == '0': # 点击下首购单 order_type = 10 driver.find_element_by_xpath( '//form[@id="storeForm10"]/div/div/div[3]/a').click() elif member_grade == '40': # 点击下重消单 order_type = 30 driver.find_element_by_xpath( '//form[@id="storeForm30"]/div/div/div[3]/a').click() else: num = ranNo(2, 3) # 随机下升级或重消单 driver.find_element_by_xpath('//form[@id="storeForm' + str(num) + '0"]/div/div/div[3]/a').click() if num == 2: order_type = 20 else: order_type = 30 # 购物车商品数量,非0时,先清空 # count = driver.find_element_by_xpath('//div[@id="spc-tooltip"]/span').text shopping = Oradao.sqlDiy( Oradao(), 'select * from BO_SHOPPING_CART s where s.member_id=' + str(member_id) + 'and s.order_type=' + str(order_type)) count = shopping['ID'].__len__() - 1 if count != '0': # 鼠标移动到购物车上 chain = ActionChains(driver) chain.move_to_element( driver.find_element_by_id('spc-tooltip')).perform() driver.implicitly_wait(10) # 清空购物车 for i in range(0, count + 1): driver.find_element_by_xpath('//li[@id="li' + str(shopping['ID'][i]) + '"]/div[3]/a').click() driver.implicitly_wait(10) # 数据库取商品 product = Oradao.sqlDiy( Oradao(), 'select p.id,p.product_id,pm.product_no,p.bv from pm_product_sale p,pm_product pm where pm.id=p.product_id and pm.product_type=\'10\' and p.order_type=' + str(order_type) + ' and p.company_code=\'' + conf.state + '\' and p.del_flag=\'20\'') # 循环把商品加入购物车,直到满足下单的bv数 bv = 0 if order_type == 10: while bv < 50: product_num = ranNo(0, product['ID'].__len__() - 1) product_no = product['PRODUCT_NO'][product_num] product_id = product['ID'][product_num] # 输入商品编码-点击查询 driver.find_element_by_name( 'sp_product.productNo_LIKE').send_keys(product_no) driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) bv = bv + product['BV'][product_num] driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() elif order_type == 20 and member_grade == '10': while bv < 300: product_num = ranNo(0, product['ID'].__len__() - 1) product_no = product['PRODUCT_NO'][product_num] product_id = product['ID'][product_num] # 输入商品编码-点击查询 driver.find_element_by_name( 'sp_product.productNo_LIKE').send_keys(product_no) driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) bv = bv + product['BV'][product_num] driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() elif order_type == 20 and member_grade == '20': while bv < 400: product_num = ranNo(0, product['ID'].__len__() - 1) product_no = product['PRODUCT_NO'][product_num] product_id = product['ID'][product_num] # 输入商品编码-点击查询 driver.find_element_by_name( 'sp_product.productNo_LIKE').send_keys(product_no) driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) bv = bv + product['BV'][product_num] driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() elif order_type == 20 and member_grade == '30': while bv < 500: product_num = ranNo(0, product['ID'].__len__() - 1) product_no = product['PRODUCT_NO'][product_num] product_id = product['ID'][product_num] # 输入商品编码-点击查询 driver.find_element_by_name( 'sp_product.productNo_LIKE').send_keys(product_no) driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) bv = bv + product['BV'][product_num] driver.find_element_by_name( 'sp_product.productNo_LIKE').clear() else: product_num = ranNo(0, product['ID'].__len__() - 1) product_no = product['PRODUCT_NO'][product_num] product_id = product['ID'][product_num] # 输入商品编码-点击查询 driver.find_element_by_name('sp_product.productNo_LIKE').send_keys( product_no) driver.find_element_by_id('btnSearch').click() time.sleep(2) # 加入购物车 driver.find_element_by_id('cart' + str(product_id)).click() time.sleep(2) # 结算 if conf.env == 'sandbox': driver.get( 'https://sandbox-d-v1.jmtop.com/backOffice/order/goToShoppingCart' ) elif conf.env == 'production': driver.get( 'https://dist.jmtop.com/backOffice/order/goToShoppingCart') driver.implicitly_wait(10) driver.find_element_by_id('addToCart_' + str(order_type)).click() time.sleep(2) # 判断是否有收货地址,若有则随机选择一个收货地址,没则选择自提 address = Oradao.sqlDiy( Oradao(), 'select * from mm_member_address ma where ma.member_id in (select m.id from mm_member m where m.member_no=\'' + member_no + '\') and ma.country=' + getAreaIdByCode(conf.state)) address_len = address['ID'].__len__() if address_len > 0: address_num = ranNo(0, address_len - 1) address_id = address['ID'][address_num] driver.find_element_by_xpath('//tr[@id="' + str(address_id) + '_tr"]/td[1]/input').click() else: driver.find_element_by_id('isSelfPickup').click() # 订单金额 order_amount = float( driver.find_element_by_id('subTotal').text.replace(',', '')) # 电子钱包充值 if order_amount > wm_value: self.wm_fund_in() # 点击保存 driver.implicitly_wait(10) driver.execute_script('scrollTo(0,500)') driver.find_element_by_id('btnSubmit').click() # 订单信息页-点击保存 driver.implicitly_wait(10) driver.execute_script('scrollTo(0,500)') driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 支付操作 driver.switch_to_frame('payIframe') self.pay() # 点击我的订单 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[4]/a').click() driver.find_element_by_id('28718').click() time.sleep(2) # 页面按订单号排序 driver.find_element_by_xpath( '//table[@id="contentTable"]/thead/tr/th[1]').click() time.sleep(2) driver.find_element_by_xpath( '//table[@id="contentTable"]/thead/tr/th[1]').click() time.sleep(2) # 页面取新订单号 rs_doc_no = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[1]/a').text # 数据库取新订单号 order = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.member_id =\'' + str(member_id) + '\'order by o.doc_no desc') # 断言 self.assertEqual(rs_doc_no, order['DOC_NO'][0])
def testOrderChange(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # OM003 换货单管理-查询 # 选择运营支撑平台-销售管理 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在销售管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) # 选择换货单管理 driver.find_element_by_xpath( '//li[@id="left_menu_28740"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe28740') # 从数据库随机取一个换货订单编号 changeOrder = Oradao.sqlDiy( Oradao(), 'select co.doc_no as c_doc_no,o.doc_no,m.member_no,m.name,co.order_date,co.total_pv,co.total_bv,co.total_net_amount,co.order_status from om_change_orders co,mm_member m,om_orders o where m.id=co.member_id and co.om_orders_id=o.id and co.order_status!=30 and co.company_code=\'' + state + '\'') num = ranNo(0, changeOrder['C_DOC_NO'].__len__() - 1) c_doc_no = changeOrder['C_DOC_NO'][num] # 把随机取到的订单编号放到页面查询 driver.find_element_by_name('sp_docNo_LIKE').send_keys(c_doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 按订单编号查询到的条数,判断是否1条 rsNum = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() - 1 self.assertEquals(rsNum, 1) # 获取列表各字段数据 rsXpath = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td') rsDocNo = rsXpath[0].text rsOrderDate = rsXpath[1].text rsOrderMember = rsXpath[2].text rsOrderPV = rsXpath[3].text rsOrderBV = rsXpath[4].text rsOrderPrice = rsXpath[5].text rsOrderStatus = rsXpath[6].text # 断言 self.assertEquals( rsDocNo, changeOrder['C_DOC_NO'][num] + ' / ' + changeOrder['DOC_NO'][num]) self.assertEqual( rsOrderDate, changeOrder['ORDER_DATE'][num].strftime('%Y-%m-%d %H:%M:%S')) self.assertEqual( rsOrderMember, changeOrder['MEMBER_NO'][num] + ' / ' + changeOrder['NAME'][num]) self.assertEqual(rsOrderPV.replace(',', ''), "%.2f" % float(changeOrder['TOTAL_PV'][num])) self.assertEqual(rsOrderBV.replace(',', ''), "%.2f" % float(changeOrder['TOTAL_BV'][num])) self.assertEqual(rsOrderPrice.replace(',', ''), "%.2f" % float(changeOrder['TOTAL_NET_AMOUNT'][num])) if changeOrder['ORDER_STATUS'][num] != '10': self.assertEqual( rsOrderStatus, transData('order.orderStatus').get( changeOrder['ORDER_STATUS'][num]))
def testBoOrderSave(self): driver = self.driver conf = self.conf # 切换语言 conf.boLangChange(driver, 'zh_CN') # 声明member对象 member = conf.member time.sleep(2) # 打开订单-我要下单 driver.find_element_by_xpath('//ul[@id="mainmenu"]/li[4]/a').click() time.sleep(2) driver.find_element_by_id('8091').click() driver.implicitly_wait(5) # 当前会员编号/级别 member_no = member['MEMBER_NO'] member_grade = member['ENROLLMENT_GRADE'] # 下单 if member_grade == '0': order_status = driver.find_element_by_xpath( '//form[@id="storeForm10"]/div/div/ul/li').text[-3:] # 当存在首购单待支付,则先支付再下升级或重消单 if order_status == u'待支付': # 订单号 order_no = driver.find_element_by_xpath( '//form[@id="storeForm10"]/div/div/ul/li').text[0:16] # 订单金额 order_amount = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.doc_no=\'' + order_no + '\'')['TOTAL_NET_AMOUNT'][0] # 会员电子钱包余额 wm_value = Oradao.sqlDiy( Oradao(), 'select * from wm_finance_info f where f.account=\'' + member_no + '\'and f.ewallet_type=1')['TOTAL_EWALLET_VALUE'][0] # 电子钱包充值 if order_amount > wm_value: self.wm_fund_in() # 点击我的订单 driver.find_element_by_xpath( '//ul[@id="mainmenu"]/li[4]/a').click() time.sleep(2) driver.find_element_by_id('28718').click() driver.implicitly_wait(5) # 查询待支付订单 driver.find_element_by_name('sp_docNo_LIKE').send_keys( order_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 去支付 driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[8]/a[1]').click() time.sleep(2) # 支付操作 driver.switch_to_frame('payIframe') self.pay() # 首购支付完成,重新进入 我要下单 driver.find_element_by_xpath( '//ul[@id="mainmenu"]/li[4]/a').click() time.sleep(2) driver.find_element_by_id('8091').click() driver.implicitly_wait(5) # 完成首购支付后,进行升级/重消单操作 self.order() # 不存在待支付首购单,直接进行首购单操作 else: self.order() # 下升级/重消单 else: self.order()
def testOrderReturnCheck(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # OM006 退货单管理-审核 # 先构造一条交易完成的订单数据(待发货--》交易完成) driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) driver.find_element_by_xpath('//li[@id="left_menu_1121"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) driver.switch_to_frame('contentIframe1121') orderNo = Oradao.sqlDiy(Oradao(), 'select * from om_orders o where o.company_code=\''+state+'\'and o.order_status=20 and o.doc_no like \'M%\' and o.order_type !=10 and to_char(o.create_date,\'yyyy-mm-dd\')>=\'2016-01-01\'') num = ranNo(0, orderNo['DOC_NO'].__len__() - 1) doc_no = orderNo['DOC_NO'][num] status = '20' while status != '50': if not driver.find_element_by_id('btnSubmit').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_docNo_LIKE').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) driver.find_element_by_xpath('//li[@id="accountmenu"]/a/i').click() driver.find_element_by_xpath('//li[@id="accountmenu"]/ul/li[1]/a').click() try: driver.find_element_by_xpath('//div[@id="jbox-state-state0"]/div[2]/button[1]').click() orderStatus = Oradao.sqlDiy(Oradao(), 'select * from om_orders o where o.doc_no=\'' + doc_no + '\'') status = orderStatus['ORDER_STATUS'][0] except: orderStatus = Oradao.sqlDiy(Oradao(), 'select * from om_orders o where o.doc_no=\'' + doc_no + '\'') status = orderStatus['ORDER_STATUS'][0] # 查询上面构造的那条交易完成的订单数据 if not driver.find_element_by_id('btnSubmit').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_docNo_LIKE').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 点击操作-申请退货 driver.find_element_by_xpath('//li[@id="accountmenu"]/a/i').click() driver.find_element_by_xpath('//li[@id="accountmenu"]/ul/li[1]/a').click() # 订单明细-点击保存 driver.switch_to_default_content() driver.execute_script('scrollTo(0,500)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_id('btnSubmit').click() # 进入退货单管理页面 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1121') # 取出退货单状态,验证是否为待审核 rsCheckStatus = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td')[8].text self.assertEqual(rsCheckStatus, u'待审核') # 审核、入库、退款操作 while rsCheckStatus != u'退货完成' and rsCheckStatus != u'取消退货': # 点击操作 driver.find_element_by_xpath('//li[@id="accountmenu"]/a/i').click() # 审核 if rsCheckStatus == u'待审核': driver.find_element_by_xpath('//li[@id="accountmenu"]/ul/li/a').click() flag = 1 # 入库 elif rsCheckStatus == u'待入库': driver.find_element_by_xpath('//li[@id="accountmenu"]/ul/li[1]/a').click() flag = 2 # 退款 else: driver.find_element_by_xpath('//li[@id="accountmenu"]/ul/li/a').click() driver.find_element_by_xpath('//div[@id="jbox-state-state0"]/div[2]/button[1]').click() flag = 3 # 进入订单明细-随机选择成/入库完成/退款完成或取消退货-保存 driver.switch_to_default_content() driver.execute_script('scrollTo(0,1000)') driver.switch_to_frame('contentIframe1121') checkNum = ranNo(1, 2) driver.find_element_by_xpath('//form[@id="inputForm"]/div/div[2]/div[6]/input['+str(checkNum)+']').click() driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 筛选出审核/入库/退款后的订单,检查状态 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_name('sp_orders.docNo_LIKE').send_keys(doc_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) rsCheckStatus = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td')[8].text if checkNum == 2 and flag != 3: self.assertEqual(rsCheckStatus, u'取消退货') elif checkNum == 1 and flag == 1: self.assertEqual(rsCheckStatus, u'待入库') elif checkNum == 1 and flag == 2: self.assertEqual(rsCheckStatus, u'待退款') else: self.assertEqual(rsCheckStatus, u'退货完成')
def pay(self): driver = self.driver conf = self.conf # 若生产环境,则选在线支付(填不存在的信用卡,使其支付不成功即可) if conf.env == 'production': # 在线支付 driver.find_element_by_xpath( '//form[@id="payForm"]/div[4]/div/p[6]/input[1]').click() time.sleep(1) driver.find_element_by_name('onlineMode').click() time.sleep(1) # 填信用卡号 credit_card = str(ranNo(6000000000000000, 6999999999999999)) driver.find_element_by_id('creditcard_number').send_keys( credit_card) # 选有效期 driver.find_element_by_xpath( '//div[@id="s2id_creditcard_expireMonth"]/a/div/b').click() Select(driver.find_element_by_id( "creditcard_expireMonth")).select_by_index(ranNo(0, 11)) driver.find_element_by_xpath( '//div[@id="s2id_creditcard_expireYear"]/a/div/b').click() Select(driver.find_element_by_id( "creditcard_expireYear")).select_by_index(ranNo(1, 9)) # 输入安全码 driver.find_element_by_id('creditcard_cvv2').send_keys( str(ranNo(100, 999))) # 持卡人姓名 driver.find_element_by_id('creditcard_firstName').send_keys('test') driver.find_element_by_id('creditcard_lastName').send_keys( str(ranNo(1, 99))) # 邮编 driver.find_element_by_id('creditcard_zip').send_keys( str(ranNo(10000, 99999))) # 地址 driver.find_element_by_id('creditcard_address1').send_keys( 'test' + str(ranNo(1, 999))) # 点击支付 driver.switch_to_default_content() driver.execute_script('scrollTo(0,200)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 判断返回卡信息错误 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1121') message = driver.find_element_by_xpath( '//div[@class="form-actions"]/p').text self.assertEqual(message, u'Invalid CARDNUMBER field') # 测试环境(test&sandbox),则选现金支付 else: # 选择现金支付 driver.find_element_by_xpath( '//form[@id="payForm"]/div[4]/div/p[1]/input[1]').click() time.sleep(2) # 点击支付 driver.switch_to_default_content() driver.execute_script('scrollTo(0,200)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_id('btnSubmit').click() # 点击返回 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_id('btnSubmit').click() # 从数据库搜索新增的订单编号 order = Oradao.sqlDiy( Oradao(), 'select * from om_orders o where o.company_code=\'' + conf.state + '\' order by o.doc_no desc') docNo = order['DOC_NO'][0] # 获取页面查询到的订单号 rsDocNo = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[2]')[0].text # 断言 self.assertEquals(rsDocNo, docNo)
def chooseMember(self): conf = self.conf driver = self.driver # 鼠标悬停在销售管理上 button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) driver.find_element_by_xpath( '//li[@id="left_menu_1121"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe1121') # 点击添加 if not driver.find_element_by_id('btnAdd').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_id('btnAdd').click() # 切换至会员选择框的iframe driver.switch_to_frame('product') # 从数据库随机选择一个会员编号,当时生成环境时,则取名字含test的测试会员 if conf.env == 'production': member = Oradao.sqlDiy( Oradao(), 'select * from mm_member m where m.subtype=40 and m.status in (0,10) and m.company_code=\'' + conf.state + '\' and (m.name like \'%test%\' or m.name like \'%Test%\')') else: member = Oradao.sqlDiy( Oradao(), 'select * from mm_member m where m.subtype=40 and m.company_code=\'' + conf.state + '\' and m.status in (0,10)') num = ranNo(0, member['MEMBER_NO'].__len__() - 1) member_no = member['MEMBER_NO'][num] member_grade = member['ENROLLMENT_GRADE'][num] # 取到的会员编号放到页面查询,点击选择 driver.find_element_by_name('sp_memberNo_LIKE').send_keys(member_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) try: driver.find_element_by_xpath( '//table[@id="treeTable1"]/tbody/tr/td[1]/a').click() except: driver.find_element_by_xpath( '//table[@id="treeTable1"]/tbody/tr/td[1]/a').click() # 切换至iframe(先跳到最初始的iframe,再进入) driver.switch_to_default_content() driver.switch_to_frame('contentIframe1121') # 选择单品 # driver.find_element_by_id('s2id_productType').click() # driver.find_element_by_xpath('//select[@id="productType"]/option[2]').click() # 随机选择 订单类型 driver.find_element_by_id('s2id_orderType').click() orderTypeNum = ranNo( 2, driver.find_elements_by_xpath( '//select[@id="orderType"]/option').__len__()) driver.find_element_by_xpath('//select[@id="orderType"]/option[' + str(orderTypeNum) + ']').click() time.sleep(2) orderType = driver.find_element_by_xpath( '//select[@id="orderType"]/option[' + str(orderTypeNum) + ']').get_attribute('value') # 判断是否有收货地址,若有则随机选择一个收货地址,没则选择自提 address = Oradao.sqlDiy( Oradao(), 'select * from mm_member_address ma where ma.member_id in (select m.id from mm_member m where m.member_no=\'' + member_no + '\') and ma.country=' + getAreaIdByCode(conf.state)) addressLen = address['ID'].__len__() if addressLen > 0: addressNum = ranNo(1, addressLen) driver.find_element_by_xpath( '//table[@id="treeTable1"]/tbody/tr[' + str(addressNum) + ']/td[1]/input').click() else: driver.find_element_by_id('isSelfPickup').click() # 根据不同订单类型与会员级别,循环添加商品直到bv>=50bv,>=300,>=400,>=500 product = Oradao.sqlDiy( Oradao(), 'select p.id,p.product_id,p.bv,pm.product_no from pm_product_sale p,pm_product pm where pm.id=p.product_id and pm.product_type=\'10\' and p.order_type=\'' + orderType + '\' and p.company_code=\'' + conf.state + '\' and p.del_flag=\'20\'') bv = 0 if orderType == '10': while bv < 50: product_num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][product_num] product_no = product['PRODUCT_NO'][product_num] # 按商品编码查询 driver.find_element_by_id('productNo').send_keys(product_no) # 点击查询商品 driver.find_element_by_id('btnSearch').click() driver.implicitly_wait(10) driver.find_element_by_id('buy-s-' + str(product_id)).click() bv = bv + product['BV'][product_num] driver.find_element_by_id('productNo').clear() elif orderType == '20' and member_grade == '10': while bv < 300: product_num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][product_num] product_no = product['PRODUCT_NO'][product_num] # 按商品编码查询 driver.find_element_by_id('productNo').send_keys(product_no) # 点击查询商品 driver.find_element_by_id('btnSearch').click() driver.implicitly_wait(10) driver.find_element_by_id('buy-s-' + str(product_id)).click() bv = bv + product['BV'][product_num] driver.find_element_by_id('productNo').clear() elif orderType == '20' and member_grade == '20': while bv < 400: product_num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][product_num] product_no = product['PRODUCT_NO'][product_num] # 按商品编码查询 driver.find_element_by_id('productNo').send_keys(product_no) # 点击查询商品 driver.find_element_by_id('btnSearch').click() driver.implicitly_wait(10) driver.find_element_by_id('buy-s-' + str(product_id)).click() bv = bv + product['BV'][product_num] driver.find_element_by_id('productNo').clear() elif orderType == '20' and member_grade == '30': while bv < 500: product_num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][product_num] product_no = product['PRODUCT_NO'][product_num] # 按商品编码查询 driver.find_element_by_id('productNo').send_keys(product_no) # 点击查询商品 driver.find_element_by_id('btnSearch').click() driver.implicitly_wait(10) driver.find_element_by_id('buy-s-' + str(product_id)).click() bv = bv + product['BV'][product_num] driver.find_element_by_id('productNo').clear() else: product_num = ranNo(0, product['ID'].__len__() - 1) product_id = product['ID'][product_num] product_no = product['PRODUCT_NO'][product_num] # 按商品编码查询 driver.find_element_by_id('productNo').send_keys(product_no) # 点击查询商品 driver.find_element_by_id('btnSearch').click() driver.implicitly_wait(10) driver.find_element_by_id('buy-s-' + str(product_id)).click() # 移动滚动条,避免按钮被遮住,需先切换iframe(滚动条属于最外面那层的) driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') # 再切回里面的iframe driver.switch_to_frame('contentIframe1121') # 点击右侧的购物车,再点击结账 driver.find_element_by_id('shopCart').click() time.sleep(2) driver.find_element_by_id('goShopping').click() time.sleep(2) try: # 如果选择的会员能正常下单,则进入到订单信息页,点击保存按钮 driver.switch_to_default_content() driver.execute_script('scrollTo(0,10000)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_id('btnSubmit').click() time.sleep(2) except: # 如果会员下不了单,页面滚动到最顶 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') # 关闭订单管理页面 driver.find_element_by_xpath( '//div[@id="tt"]/div[1]/div[3]/ul/li[2]/a[2]').click() # 重新下单选择会员 self.chooseMember() # 点击订单明细页的保存按钮 driver.find_element_by_id('btnSubmit').click() time.sleep(5) try: # 能正常下单,则会进入支付页面 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1121') driver.find_element_by_xpath( '//form[@id="payForm"]/div[2]/div').text except: # 如果会员存在待支付的首购单则下不了单,关闭订单管理页面 driver.switch_to_default_content() driver.find_element_by_xpath( '//div[@id="tt"]/div[1]/div[3]/ul/li[2]/a[2]').click() # 重新下单选择会员 self.count += 1 # 当出现10次都下不了单时,抛出异常,排除是否代码问题 if self.count >= 10: raise Exception(u'下单错误') self.chooseMember()
def testTax(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1110') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在商品管理 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath( '//li[@id="left_menu_7264"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe7264') # 查出数据库中的税率数据 taxsql = """SELECT pst.* FROM pm_product_sale_tax pst, sys_area sa WHERE sa.parent_id = ( SELECT id FROM sys_area WHERE code = '""" + conf.state + """' AND TYPE = 20) AND tax_Strategy = 'tax0' AND pst.area_id = sa.id""" saleTax = Oradao.sqlDiy(Oradao(), taxsql) tax = saleTax['TAX'] # 获取税率的个数 totalNum = driver.find_elements_by_class_name('easyui-panel') rsTax = [] for i in range(totalNum.__len__()): rsTax.append( driver.find_element_by_id('tax_panel_' + str(i)).get_attribute('value')) tax = list(set(tax)) for i in range(tax.__len__()): self.assertIn(str(tax[i]), rsTax) # 添加税率 driver.find_element_by_id('addAddress').click() driver.implicitly_wait(10) # 输入0到1随机小数税率 driver.find_element_by_xpath( '//form[@id="inputForm"]/span[2]/input[1]').send_keys( str(ranFloat(0, 1, 1))) # 随机选择一个地区 areas = driver.find_elements_by_class_name('isoffline') if areas.__len__() > 0: rsArea = areas[ranNo(0, areas.__len__() - 1)] rsAreaName = rsArea.text rsArea.click() driver.find_element_by_id('btnSubmits').click() # 检查是否添加成功 driver.implicitly_wait(10) # 把关闭按钮的x和换行符过滤掉 message = driver.find_element_by_id('messageBox').text.replace( u'×', '').strip('\n') self.assertEquals(message, u'保存成功') # 检查新添加的地区是否在列表中,若有则删除 driver.find_element_by_link_text(rsAreaName).click() else: driver.quit()
def testProductSearch(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1110') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在商品管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath('//li[@id="left_menu_1111"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe1111') product = Oradao.sqlDiy(Oradao(), 'select * from pm_product where DEL_FLAG = 0') num = ranNo(0, product['PRODUCT_NO'].__len__() - 1) product_no = product['PRODUCT_NO'][num] product_name = product['PRODUCT_NAME'][num] driver.find_element_by_name('sp_productNo_LIKE').send_keys(product_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) rsNum = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr').__len__() # test = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr') self.assertEquals(rsNum, 1) rsXpath = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr[' + str(rsNum) + ']/td') rsProductNo = rsXpath[0].text rsProductName = rsXpath[1].get_attribute('title') # rsProductKind = rsXpath[2].text # rsProductUnit = rsXpath[3].text # rsSaleKind = rsXpath[4].text # 断言 self.assertEquals(rsProductNo, product['PRODUCT_NO'][num]) self.assertEquals(rsProductName, product['PRODUCT_NAME'][num]) driver.find_element_by_name('sp_productNo_LIKE').clear() driver.find_element_by_name('sp_productName_LIKE').send_keys(product_name) driver.find_element_by_id('btnSubmit').click() time.sleep(2) rsNum = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr').__len__() rs_tolal_num = getNum(driver.find_elements_by_xpath('//ul[@class="pagination"]/li')[-2].text) sqlCount = "select * from pm_product where DEL_FLAG = 0 and PRODUCT_NAME like \'%" + product_name + "%\'" sqlNum = Oradao.sqlCount(Oradao(), str(sqlCount)) rsXpath = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr[' + str(rsNum) + ']/td') rsProductNo = rsXpath[0].text rsProductName = rsXpath[1].get_attribute('title') # rsProductKind = rsXpath[2].text # rsProductUnit = rsXpath[3].text # rsSaleKind = rsXpath[4].text # 断言 self.assertEquals(rs_tolal_num, str(sqlNum)) self.assertEquals(rsProductNo, product['PRODUCT_NO'][num]) self.assertEquals(rsProductName, product['PRODUCT_NAME'][num])
def testFund(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_73') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在电子钱包上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath('//li[@id="left_menu_85"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe85') # 判断有多少条数据,若只有一条xpath的tr长度只有1 driver.implicitly_wait(10) tolalnum = driver.find_elements_by_xpath('//table[@id="contentTable"]/tbody/tr').__len__() # 取出唯一的一条数据,根据钱包账号查询对应的数据进行验证 if tolalnum == 1: rsAccountNo = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[1]').text.strip(' ') rsMemberNo = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[2]').text.strip(' ') rsMemberName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[3]').text.strip(' ') rsEwalletType = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[4]').text.strip(' ') rsEwalletValue = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[5]').text.strip(' ') rsEwalletValueToltal = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr/td[6]').text.strip(' ') rsSubmitName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[7]').text.strip(' ') rsSubmitTime = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[8]').text.strip(' ') rsAuditName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[9]').text.strip(' ') rsAuditTime = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[10]').text.strip(' ') rsAuditStatus = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr/td[11]').text.strip(' ') fundSql = 'select wbd.*, wfi.*, mm.name from wm_balance_detail wbd, wm_finance_info wfi, mm_member mm where ' \ 'wfi.member_id = mm.id and wbd.FINANCE_INFO_ID = wfi.id and wbd.company_code = \'' + conf.state + \ '\' and wbd.origin = 30 and wfi.account = \'' + rsAccountNo + '\'' fundIn = Oradao.sqlDiy(Oradao(), str(fundSql)) memberNo = fundIn['MEMBER_CODE'][0] memberName = fundIn['NAME'][0] ewalletType = fundIn['EWALLET_TYPE'][0] if ewalletType == '1': ewalletType = u'电子货币' elif ewalletType == '2': ewalletType = u'旅游积分' elif ewalletType == '3': ewalletType = u'奖金' ewalletValue = fundIn['EWALLET_VALUE'][0] ewalletValueToltal = fundIn['EWALLET_VALUE_TOTAL'][0] submitName = fundIn['SUBMIT_ID'][0] if fundIn['SUBMIT_TIME'][0] != '': submitTime = fundIn['SUBMIT_TIME'][0].strftime('%Y-%m-%d %H:%M:%S') else: submitTime = '' auditName = fundIn['AUDITOR_ID'][0] if fundIn['AUDIT_TIME'][0] != '': auditTime = fundIn['AUDIT_TIME'][0].strftime('%Y-%m-%d %H:%M:%S') else: auditTime = '' status = fundIn['STATUS'][0] if status == 1: status = u'待审核' elif status == 2: status = u'通过' elif status == 3: status = u'不通过' self.assertEquals(memberNo, rsMemberNo) self.assertEquals(memberName, rsMemberName) self.assertEquals(ewalletType, rsEwalletType) self.assertEquals("%.2f" % float(ewalletValue), "%.2f" % float(rsEwalletValue)) self.assertEquals("%.2f" % float(ewalletValueToltal), "%.2f" % float(rsEwalletValueToltal)) self.assertEquals(submitName, rsSubmitName) self.assertEquals(submitTime, rsSubmitTime) self.assertEquals(auditName, rsAuditName) self.assertEquals(auditTime, rsAuditTime) self.assertEquals(status, rsAuditStatus) # 当数据量大于1时,tr值取第一条 elif tolalnum > 1: rsAccountNo = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[2]').text.strip(' ') rsMemberNo = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[3]').text.strip(' ') rsMemberName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[4]').text.strip(' ') rsEwalletType = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[5]').text.strip( ' ') rsEwalletValue = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[6]').text.strip( ' ') rsEwalletValueToltal = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[7]').text.strip(' ') rsSubmitName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[8]').text.strip(' ') rsSubmitTime = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[9]').text.strip(' ') rsAuditName = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[10]').text.strip(' ') rsAuditTime = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[11]').text.strip(' ') rsAuditStatus = driver.find_element_by_xpath('//table[@id="contentTable"]/tbody/tr[1]/td[12]').text.strip( ' ') fundSql = 'select wbd.*, wfi.*, mm.name from wm_balance_detail wbd, wm_finance_info wfi, mm_member mm where ' \ 'wfi.member_id = mm.id and wbd.FINANCE_INFO_ID = wfi.id and wbd.company_code = \'' + conf.state + \ '\' and wbd.origin = 30 and wfi.account = \'' + rsAccountNo + '\' order by wbd.AUDIT_TIME desc, submit_time desc' fundIn = Oradao.sqlDiy(Oradao(), str(fundSql)) memberNo = fundIn['MEMBER_CODE'][0] memberName = fundIn['NAME'][0] ewalletType = fundIn['EWALLET_TYPE'][0] if ewalletType == '1': ewalletType = u'电子货币' elif ewalletType == '2': ewalletType = u'旅游积分' elif ewalletType == '3': ewalletType = u'奖金' ewalletValue = fundIn['EWALLET_VALUE'][0] ewalletValueToltal = fundIn['EWALLET_VALUE_TOTAL'][0] submitName = fundIn['SUBMIT_ID'][0] if fundIn['SUBMIT_TIME'][0] != '': submitTime = fundIn['SUBMIT_TIME'][0].strftime('%Y-%m-%d %H:%M:%S') else: submitTime = '' auditName = fundIn['AUDITOR_ID'][0] if fundIn['AUDIT_TIME'][0] != '': auditTime = fundIn['AUDIT_TIME'][0].strftime('%Y-%m-%d %H:%M:%S') else: auditTime = '' status = fundIn['STATUS'][0] if status == 1: status = u'待审核' elif status == 2: status = u'通过' elif status == 3: status = u'不通过' self.assertEquals(memberNo, rsMemberNo) self.assertEquals(memberName, rsMemberName) self.assertEquals(ewalletType, rsEwalletType) self.assertEquals("%.2f" % float(ewalletValue), "%.2f" % float(rsEwalletValue)) self.assertEquals("%.2f" % float(ewalletValueToltal), "%.2f" % float(rsEwalletValueToltal)) self.assertEquals(submitName, rsSubmitName) self.assertEquals(submitTime, rsSubmitTime) self.assertEquals(auditName, rsAuditName) self.assertEquals(auditTime, rsAuditTime) self.assertEquals(status, rsAuditStatus) if tolalnum < 1: raise AssertionError(u'未知错误')
def testOrderReturn(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # OM005 退货单管理-查询 # 选择运营支撑平台-销售管理 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_1120') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在销售管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) # 选择退货单管理 driver.find_element_by_xpath( '//li[@id="left_menu_2604"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe2604') # 从数据库随机取一个退货订单编号 returnOrder = Oradao.sqlDiy( Oradao(), 'select r.id,r.return_order_no,m.member_no,r.total_amount,r.actual_refund,r.total_bv,r.total_pv,o.doc_no,o.order_type,r.check_statu from om_return_order r,om_orders o,mm_member m where r.order_id=o.id and r.member_id=m.id and o.company_code=\'' + state + '\'') num = ranNo(0, returnOrder['ID'].__len__() - 1) r_order_no = returnOrder['RETURN_ORDER_NO'][num] # 把随机取到的订单编号放到页面查询 driver.find_element_by_name('sp_returnOrderNo_LIKE').send_keys( r_order_no) driver.find_element_by_id('btnSubmit').click() time.sleep(2) # 按订单编号查询到的条数,判断是否1条 rsNum = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr').__len__() - 1 self.assertEquals(rsNum, 1) # 获取列表各字段数据 rsXpath = driver.find_elements_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td') rsReturnNo = rsXpath[0].text rsMember = rsXpath[1].text rsTotalAmount = rsXpath[2].text rsActualRefund = rsXpath[3].text rsBV = rsXpath[4].text rsPV = rsXpath[5].text rsDocNo = rsXpath[6].text rsOrderType = rsXpath[7].text rsReturnStatus = rsXpath[8].text # 断言 self.assertEquals(rsReturnNo, returnOrder['RETURN_ORDER_NO'][num]) self.assertEqual(rsMember, returnOrder['MEMBER_NO'][num]) self.assertEqual(rsTotalAmount.replace(',', ''), "%.2f" % float(returnOrder['TOTAL_AMOUNT'][num])) self.assertEqual(rsActualRefund.replace(',', ''), "%.2f" % float(returnOrder['ACTUAL_REFUND'][num])) self.assertEqual(rsBV.replace(',', ''), "%.2f" % float(returnOrder['TOTAL_BV'][num])) self.assertEqual(rsPV.replace(',', ''), "%.2f" % float(returnOrder['TOTAL_PV'][num])) self.assertEqual(rsDocNo, returnOrder['DOC_NO'][num]) self.assertEqual( rsOrderType, transData('order.orderType').get(returnOrder['ORDER_TYPE'][num])) if returnOrder['CHECK_STATU'][num] != '21': self.assertEqual( rsReturnStatus, transData('returnOrder.checkStatus').get( str(returnOrder['CHECK_STATU'][num])))
def testMember(self): driver = self.driver conf = self.conf state = conf.state conf.stateChange(driver) driver.implicitly_wait(10) # MM001 会员信息维护-查询 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() # 指定元素:会员管理 button = driver.find_element_by_id('left_menu_1210') # 指定元素:菜单 menu = driver.find_element_by_class_name('nav-header') # 鼠标移动到会员管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.implicitly_wait(10) # 指定元素:会员信息维护,并点击操作 driver.find_element_by_xpath( '//li[@id="left_menu_1211"]/a/span').click() # 移开鼠标 chain.move_to_element(menu).perform() time.sleep(1) # 切换至iframe driver.switch_to_frame('contentIframe1211') # 按会员编码查询 # 从数据库查询会员编号 Member = Oradao.sqlDiy( Oradao(), 'select * from (select * from MM_MEMBER m where m.company_code=\'' + state + '\' order by m.create_date desc) where rownum<=10') # 随机取会员编号 num = ranNo(0, Member['ID'].__len__() - 1) memberNo = Member['MEMBER_NO'][num] sponsorId = Member['SPONSOR_ID'][num] placementId = Member['PLACEMENT_ID'][num] # 页面查询 if not driver.find_element_by_id('btnAdd').is_displayed(): driver.find_element_by_class_name('open-close').click() time.sleep(0.5) driver.find_element_by_name('sp_memberNo_ILIKE').send_keys(memberNo) driver.find_element_by_id('btnSubmit').click() # 页面刷新元素变化了,需要加这个,否则后面元素会获取不到 time.sleep(2) # 获取列表各字段数据 rsXpath = driver.find_elements_by_xpath( '//table[@id="treeTable1"]/tbody/tr/td') rsMemberNo = rsXpath[1].text rsMemberName = rsXpath[2].text rsMemberGrade = rsXpath[3].text rsCreater = rsXpath[4].text rsCreateDate = rsXpath[5].text rsCreateTime = rsXpath[6].text rsSponsor = rsXpath[7].text rsPlacement = rsXpath[8].text rsSubType = rsXpath[9].text # 断言 self.assertEquals(rsMemberNo, memberNo) self.assertEqual(rsMemberName, Member['NAME'][num]) self.assertEqual( rsMemberGrade, transData('member.enrollmentGrade').get( Member['ENROLLMENT_GRADE'][num])) self.assertEqual(rsCreater, Member['CREATE_BY'][num]) self.assertEqual(rsCreateDate, Member['CREATE_DATE'][num].strftime('%Y-%m-%d')) self.assertEqual(rsCreateTime, Member['CREATE_DATE'][num].strftime('%H:%M:%S')) # 推荐人&安置人编号 sponsorNo = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER m where m.id=' + str(sponsorId))['MEMBER_NO'][0] placementNo = Oradao.sqlDiy( Oradao(), 'select * from MM_MEMBER m where m.id=' + str(placementId))['MEMBER_NO'][0] self.assertEqual(rsSponsor, sponsorNo) self.assertEqual(rsPlacement, placementNo) self.assertEqual( rsSubType, transData('member.subtype').get(Member['SUBTYPE'][num]))
def testAccount(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() button = driver.find_element_by_id('left_menu_73') menu = driver.find_element_by_class_name('nav-header') # 鼠标悬停在电子钱包上 chain = ActionChains(driver) chain.move_to_element(button).perform() driver.find_element_by_xpath('//li[@id="left_menu_77"]/a/span').click() chain.move_to_element(menu).perform() driver.implicitly_wait(10) # 切换至iframe driver.switch_to_frame('contentIframe77') # 测试数据总数是否一致 sqlCount = 'select * from wm_account_info where company_code = \'' + conf.state + '\'' sqlNum = Oradao.sqlCount(Oradao(), str(sqlCount)) pageBottom = driver.find_elements_by_xpath('/html/body/div/div/ul/li') accountNum = getNum(str(pageBottom[pageBottom.__len__() - 2].text)) self.assertEquals(str(sqlNum), accountNum) # 获取第一条数据各个字段值 rsNo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[1]/a').text.strip(' ') rsMemberCode = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[2]').text.strip(' ') rsName = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[3]').text.strip(' ') rsPhone = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[4]').text.strip(' ') rsCardType = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[5]').text.strip(' ') rsCardNo = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[6]').text.strip(' ') rsLastVistTime = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[7]').text.strip(' ') rsRemark = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[8]').text.strip(' ') # 根据账号ID从数据库中查出该记录其他信息 accountSql = 'select * from wm_account_info where company_code = \'' \ + conf.state + '\' and account = \'' + rsNo + '\'' accountInfo = Oradao.sqlDiy(Oradao(), str(accountSql)) accountMemberCode = accountInfo['MEMBER_CODE'][0] accountName = accountInfo['NAME'][0] accountPhone = accountInfo['BIND_PHONE'][0] # 证件类型写死,0对应身份证,1对应护照 accountCardType = accountInfo['CARD_TYPE'][0] if accountCardType == 0: accountCardType = u'身份证' elif accountCardType == 1: accountCardType = u'护照' accountCardNo = accountInfo['ID_CARD'][0] accountLastVistTime = accountInfo['LAST_VISIT_TIME'][0] accountRemark = accountInfo['REMARKS'][0] accountId = accountInfo['ID'][0] # 数据库查询结果和页面结果对比断言 self.assertEquals(rsMemberCode, accountMemberCode) self.assert_(rsMemberCode, accountMemberCode) self.assertEquals(rsName, accountName) self.assertEquals(rsPhone, accountPhone) self.assertEquals(rsCardType, accountCardType) self.assertEquals(rsCardNo, accountCardNo) self.assertEquals(rsLastVistTime, accountLastVistTime) self.assertEquals(rsRemark, accountRemark) # 查询余额 driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[9]/a[3]').click() financeSql = 'select * from wm_finance_info where account_info_id = \'' + str( accountId) + '\'' financeInfo = Oradao.sqlDiy(Oradao(), str(financeSql)) financeCash = financeInfo['TOTAL_EWALLET_VALUE'][0] # 电子货币 financePoint = financeInfo['TOTAL_EWALLET_VALUE'][1] # 旅游积分 financeBonus = financeInfo['TOTAL_EWALLET_VALUE'][2] # 奖金 driver.implicitly_wait(10) rsCash = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[1]/td[2]').text rsPoint = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[2]/td[2]').text rsBonus = driver.find_element_by_xpath( '//table[@id="contentTable"]/tbody/tr[3]/td[2]').text # 对比余额断言 self.assertEquals("%.2f" % float(financeCash), "%.2f" % float(rsCash)) self.assertEquals("%.2f" % float(financePoint), "%.2f" % float(rsPoint)) self.assertEquals("%.2f" % float(financeBonus), "%.2f" % float(rsBonus))