class PersonWeeklyPfm(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass def testPersonWeeklyPfm(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_1220') # 指定元素:菜单 menu = driver.find_element_by_class_name('nav-header') second_button = driver.find_element_by_id('left_menu_7821') # 鼠标移动到会员管理上 chain = ActionChains(driver) chain.move_to_element(button).perform() time.sleep(0.5) # 鼠标移动到业绩查询 chain.move_to_element(second_button).perform() driver.implicitly_wait(10) # 指定元素:会员信息维护,并点击操作 driver.find_element_by_xpath( '//li[@id="left_menu_7822"]/a/span').click() # 移开鼠标 chain.move_to_element(menu).perform() time.sleep(1) # 切换至iframe driver.switch_to_frame('contentIframe7822') # 判断当前页面中是否有当前机构的数据 self.assertIn(conf.state, driver.page_source)
class OrderView(unittest.TestCase): def setUp(self): # 初始化登录 self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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]))
class ProductSaleTax(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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()
class OrderChangeAdd(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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)
class ProductMsgSearch(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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)
class OrderReturn(unittest.TestCase): def setUp(self): # 初始化登录 self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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])))
class SponsorSelect(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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])
class SponsorChange(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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)
class OrderReturnCheck(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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'退货完成')
class ProductNewMSG(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) logging.info(self.driver.page_source) self.driver.quit() pass 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)
class OrderChange(unittest.TestCase): def setUp(self): # 初始化登录 self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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]))
class ProductComposite(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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)
class MemberAdd(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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)
class FundIn(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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'未知错误')
class OrderSave(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass def testOrderSave(self): driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # OM002 下单&支付 # 选择运营支撑平台 driver.find_element_by_id('topMenu_1100').click() # 调用方法chooseMember self.count = 0 self.chooseMember() # 支付 self.pay() # 把如下操作放在方法chooseMember里,当出现条件限制执行不了的时候可调用多次重新选择其他会员编号 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 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)
class ProductNo(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass def testProduct(self): # 初始化登录 driver = self.driver conf = self.conf conf.stateChange(driver) driver.implicitly_wait(10) # 选择运营支撑平台 driver = self.driver 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') # 添加商品 driver.find_element_by_id('btnAdd').click() driver.implicitly_wait(10) # 初始化下拉框element:0:商品类别;1:单位;2:销售类别 # selects = driver.find_elements_by_class_name('select2-choice') # 商品类别下拉框,通过js加载的div下拉菜单 # selects[0].click() # 获取商品类别下拉菜单选项数量,去掉第一个空值,随机选择一项 ranProductOp = ranNo( 1, driver.find_elements_by_xpath( '//select[@name="productType"]/option').__len__()) productOp = driver.find_element_by_xpath( '//select[@name="productType"]/option[' + str(ranProductOp) + ']') productText = productOp.text productOp.click() driver.implicitly_wait(10) # 输入随机商品编码 product_No = str(ranNo(100000, 999999)) driver.find_element_by_id('productNo').send_keys(product_No) # 输入随机商品名称 product_name = ranEN(8) driver.find_element_by_id('productName').send_keys(product_name) # 选择单位 # selects[1].click() ranUnitOp = ranNo( 1, driver.find_elements_by_xpath( '//select[@name="unitNo"]/option').__len__()) unitOp = driver.find_element_by_xpath( '//select[@name="unitNo"]/option[' + str(ranUnitOp) + ']') unitText = unitOp.text unitOp.click() # 选择销售类别 # selects[2].click() ranSaleOp = ranNo( 1, driver.find_elements_by_xpath( '//select[@name="smNo"]/option').__len__()) saleOp = driver.find_element_by_xpath( '//select[@name="smNo"]/option[' + str(ranSaleOp) + ']') saleText = saleOp.text saleOp.click() # 设置体积 ranVolume = str(ranNo(1, 5000)) + '.00' driver.find_element_by_xpath( '//div[@id="tabs"]/div[2]/div[1]/div/div[1]/div/div[6]/div/div/span[1]/input[1]' ).send_keys(ranVolume) # 设置重量 ranWeight = str(ranNo(1, 5000)) + '.00' driver.find_element_by_xpath( '//div[@id="tabs"]/div[2]/div[1]/div/div[1]/div/div[7]/div/div/span[1]/input[1]' ).send_keys(ranWeight) # 编辑备注 remarkText = u'备注' + ranEN(6) driver.find_element_by_id('remark').send_keys(remarkText) # 保存/取消 driver.find_element_by_id('btnSubmit').click() # driver.find_element_by_id('btnCancel').click() driver.implicitly_wait(10) # 搜索新增的商品编码 driver.find_element_by_name('sp_productNo_LIKE').send_keys(product_No) # 保存后页面会稍微往下拉,查询按钮被挡住点击不了,需要切换到父iframe将页面往上拉 driver.switch_to_default_content() driver.execute_script('scrollTo(0,0)') driver.switch_to_frame('contentIframe1111') driver.find_element_by_id('btnSubmit').click() 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') # 获取页面各字段数值-0:商品编码;1:编码名称;2:商品类别;3:体积;4:重量; rsProductNo = rsXpath[0].text rsProductName = rsXpath[1].text rsProductKind = rsXpath[2].text rsProductVolume = rsXpath[3].text rsProductWeight = rsXpath[4].text # 断言 self.assertEquals(rsProductNo, product_No) self.assertEquals(rsProductName, product_name) self.assertEquals(rsProductKind, productText) self.assertEquals(rsProductVolume, ranVolume) self.assertEquals(rsProductWeight, ranWeight)
class ProductSearch(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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])
class MemberInfo(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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]))
class AccountInfo(unittest.TestCase): def setUp(self): self.conf = Initialize() self.driver = self.conf.start() self.verificationErrors = [] pass def tearDown(self): self.conf.getScreenshot(self) self.assertEqual([], self.verificationErrors) self.driver.quit() pass 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))