class ProductDetail(unittest.TestCase): def setUp(self): self.driver = Pyse('chrome') self.driver.open(get_url("home_page")) # 登录点击第一个商品 self.driver.login() self.driver.click(get_element("productDetail_page", "firstLineName")) time.sleep(1) ''' setUP 登录 ''' def test_1_MBXProductLink(self): '''面包屑导航链接-大宗交易''' self.driver.click( get_element("productDetail_page", "MBXProductPage_link_loc")) time.sleep(1) url = self.driver.get_current_url() autolog.info(url) assert url == "http://10.82.12.25/centralize-purchase/#/product", ( "链接未跳转成功") autolog.info("导航链接大宗交易页面正确") ''' test_1_MBXProductLink 面包屑导航-大宗交易-链接 点击后跳转大宗交易页面 比对页面url ''' def test_2_MBXHomeLink(self): '''面包屑导航链接-首页''' self.driver.click( get_element("productDetail_page", "MBXHomePage_link_loc")) time.sleep(1) url = self.driver.get_current_url() autolog.info(url) assert url == "http://10.82.12.25/centralize-purchase/#/", ("链接未跳转成功") autolog.info("导航链接首页正确") ''' test_2_MBXHomeLink 面包屑导航-首页-链接 点击后跳转首页 比对页面url ''' def test_3_goodImg(self): '''商品图片展示''' src = self.driver.get_attribute( get_element("productDetail_page", "good_img_loc"), "src") if src: self.driver.open(str(src)) assert self.driver.get_title() != "404 Not Found" autolog.info(src) autolog.info("商品图片展示正常") else: autolog.info("无法获取src") assert False, ("获取src失败") self.assertTrue(src, "无法获取src") ''' test_3_goodImg 商品图片的展示,看是否可以访问图片地址 ''' def test_4_mainGoodType(self): '''主要信息:商品类型:期货/现货''' eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #通过商品编号查询出商品类型 type = getDicSql("type", "type", code) # type = selectBySql("SELECT label_value from cenpur_user_dict where en_name ='type' and value=(select type from cenpur_mall_goods where code ='%s')"%code) autolog.info(type) text = self.driver.text_in_element( get_element("productDetail_page", "goodType_text_loc"), type[0]) autolog.info(text) if text: autolog.info("商品类型显示正确") assert True else: autolog.info("商品类型显示错误") assert False, ("商品类型显示错误") ''' test_4_mainType 主要信息的商品类型展示:现货/期货 通过页面获取商品编号 通过商品编号获取数据库中的商品类型显示信息 比对商品类型是否显示 ''' def test_5_mainGoodPrice(self): '''主要信息-商品价格''' #获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) price = selectBySql( "SELECT price from cenpur_mall_goods where code ='%s'" % code) autolog.info(price) autolog.info(price_unit) #获取价格 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodPrice_text_loc")) text = eletext1.text autolog.info(text) #判断 re1 = text.find("¥") re2 = text.find(getNum(price[0])) re3 = text.find(str(price_unit[0])) re4 = str(price_unit[0]).find("美元") if re2 != -1 and re3 != -1: autolog.info("单位、价格验证正确") if re4 == 0 and re1 == -1: autolog.info("单位美元$") assert True elif re4 == -1 and re1 == 0: autolog.info("单位元¥") assert True else: autolog.info("单位¥/$显示错误") assert False, ("单位¥/$显示错误") else: autolog.info("单位、价格错误") assert False, ("单位、价格错误") ''' test_5_mainGoodPrice 主要信息中价格的显示 通过页面获取商品编号 通过商品编号获取数据库中的价格和单位 通过判断价格、单位、单位符号是否正确 ''' def test_6_mainName(self): '''主要信息-商品名称''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 name = selectBySql( "SELECT name from cenpur_mall_goods where code ='%s'" % code) autolog.info(name) #获取名称 text = self.driver.text_in_element( get_element("productDetail_page", "goodName_text_loc"), name[0]) autolog.info(text) if text: autolog.info("商品名称显示正确") assert True else: autolog.info("商品名称显示正确") assert False, ("商品名称显示正确") ''' test_6_mainName 主要信息:商品名 获取商品编号 查询数据库中商品名 与页面商品名做对比 ''' def test_7_mainPriceType(self): '''主要信息-计价方式''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 goods_type = connect_sql( "select type from cenpur_mall_goods where code = '%s'" % code) print('2') if goods_type[0][0] == 1: price_type = getDicSql("price_type", "price_type", code) autolog.info(price_type) # 获取计价方式 text = self.driver.text_in_element( get_element("productDetail_page", "goodPriceType_text_loc"), price_type[0]) autolog.info(text) if text: autolog.info("计价方式显示正确") assert True else: autolog.info("计价方式显示错误") assert False, ("计价方式显示错误") else: terms_price = getDicSql("terms_price", "terms_price", code) autolog.info(terms_price) # 获取价格术语 text = self.driver.text_in_element( get_element("productDetail_page", "goodPriceType_text_loc"), terms_price[0]) autolog.info(text) if text: autolog.info("价格术语显示正确") assert True else: autolog.info("价格术语显示错误") assert False, ("价格术语显示错误") ''' test_7_priceType 主要信息:计价方式 获取商品编号 查询数据库中计价方式信息 与页面获取的计价方式作对比 ''' def test_8_mainTagoutNum(self): '''主要信息-发盘量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) tagout_num = selectBySql( "SELECT tagout_num from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(tagout_num) autolog.info(price_unit) autolog.info(unit) # 获取发盘量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodTagoutNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(tagout_num[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、发盘量验证正确") else: autolog.info("单位、发盘量错误") assert False, ("单位、发盘量错误") ''' test_8_mainTagoutNum 获取商品编号 查询数据库中发盘量、单位信息 与页面获取的发盘量作对比 ''' def test_9_1_mainStartNum(self): '''主要信息-起订量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) start_num = selectBySql( "SELECT start_num from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(start_num) autolog.info(price_unit) autolog.info(unit) # 获取起订量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodStartNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(start_num[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、起订量验证正确") else: autolog.info("单位、起订量错误") assert False, ("单位、起订量错误") ''' test_9_mainStartNum 获取商品编号 查询数据库中起订量、单位信息 与页面获取的起订量作对比 ''' def test_9_2_mainsurrplus(self): '''主要信息:剩余量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) surrplus = selectBySql( "SELECT surplus from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(surrplus) autolog.info(price_unit) autolog.info(unit) # 获取剩余量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodSurplusNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(surrplus[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、剩余量验证正确") else: autolog.info("单位、剩余量错误") assert False, ("单位、剩余量错误") ''' test_10_mainsurrplus 获取商品编号 查询数据库中剩余量、单位信息 与页面获取的剩余量作对比 ''' def test_9_3_mainNumText(self): '''采购量输入框''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 start_num = selectBySql( "SELECT start_num from cenpur_mall_goods where code ='%s'" % code) surplus = selectBySql( "SELECT surplus from cenpur_mall_goods where code ='%s'" % code) autolog.info(start_num) autolog.info(surplus) #操作 #小于起订量 self.driver.send_keys( get_element("productDetail_page", "goodNum_textBox_loc"), str(int(getNum(start_num[0])) - 1)) self.driver.click( get_element("productDetail_page", "goodType_text_loc")) #点击失去焦点 eleStart = self.driver.find_element( get_element("productDetail_page", "goodNum_textBox_loc")) eleStart_num = int(eleStart.get_attribute("value")) #大于剩余量 self.driver.send_keys( get_element("productDetail_page", "goodNum_textBox_loc"), str(int(getNum(surplus[0])) + 1)) self.driver.click( get_element("productDetail_page", "goodType_text_loc")) # 点击失去焦点 eleSurplus = self.driver.find_element( get_element("productDetail_page", "goodNum_textBox_loc")) eleSurplus_num = int(eleSurplus.get_attribute("value")) assert eleStart_num >= int(start_num[0]) and eleSurplus_num <= int( surplus[0]), ("小于起订量或者大于剩余量") autolog.info("输入框验证正确") ''' test_11_mainBuyDown 通过商品编号,查询数据库中的起订量和剩余量 输入小于起订量和大于剩余量的数字 ''' def test_9_4_mainCollection(self): '''收藏商品''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #删除我的收藏 selectBySql("delete from cenpur_mall_favorites where user_id ='%s'" % userId) #获取class class1 = self.driver.get_attribute( get_element("productDetail_page", "goodCollection_button_loc"), "class") self.driver.click( get_element("productDetail_page", "goodCollection_button_loc")) class2 = self.driver.get_attribute( get_element("productDetail_page", "goodCollection_button_loc"), "class") #去我的收藏页验证 self.driver.open(get_url("favorite_page")) self.driver.refresh() eletext1 = self.driver.find_element( get_element("productDetail_page", "favoriteCode_text_loc")) autolog.info("我的收藏页%s" % eletext1.text) code1 = getCode(eletext1.text) autolog.info(code1) assert class1 == class2 and code == code1, ("商品未成功收藏") autolog.info("商品成功收藏") ''' test_12_mainCollection 点击收藏后,验证收藏标签的class是否变化 然后进入我的收藏页面,找到商品编号,看是否相同 ''' def test_9_5_shopImg(self): '''店铺图片''' src = self.driver.get_attribute( get_element("productDetail_page", "shop_img_loc"), "src") if src: self.driver.open(str(src)) assert self.driver.get_title() != "404 Not Found" autolog.info(src) autolog.info("店铺页面图片展示正常") else: autolog.info("无法获取src") assert False, ("获取src失败") ''' test_13_shopImg 商品图片的展示,看是否可以访问图片地址 ''' def test_9_6_shopPhone(self): '''店铺-电话展示''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #获取联系方式 phone = selectBySql( "select phone from cenpur_mall_shop where id=(SELECT shop_id from cenpur_mall_goods where code='%s')" % code) autolog.info(phone) #获取页面信息判断 text = self.driver.text_in_element( get_element("productDetail_page", "shopPhone_text_loc"), str(phone[0])) if text: autolog.info("店铺电话号码正确") assert True else: autolog.info("店铺电话号码错误") assert False, ("店铺电话号码错误") ''' test_14_shopPhone 店铺号码展示 通过商品编号,查询对应的店铺信息 通过获取联系方式 与页面做对比 ''' def test_9_7_GOshop(self): '''进入店铺''' self.driver.click( get_element("productDetail_page", "goShop_button_loc")) time.sleep(2) url = self.driver.get_current_url() autolog.info("点击进入店铺后跳转页面为:%s" % url) self.assertIn("storeDetail", url, "未成功跳转店铺详情页面") ''' test_15_GOshop 进入店铺详情,对比url ''' def test_9_8_shopCollection(self): '''收藏店铺''' # 删除我的收藏 selectBySql("delete from cenpur_mall_favorites where user_id ='%s'" % userId) autolog.info("收藏店铺已删除") #收藏后进入我的收藏 self.driver.click( get_element("productDetail_page", "shopCollection_button_loc")) autolog.info("点击收藏店铺") self.driver.open(get_url("favorite_page")) time.sleep(2) self.driver.click( get_element("productDetail_page", "faveritePageShop_link_loc")) time.sleep(1) ele_displayed = self.driver.find_element( get_element("productDetail_page", "favoritePageShopName_text_loc")).is_displayed() autolog.info(ele_displayed) assert ele_displayed == True, ("收藏的店铺元素不存在") autolog.info("店铺收藏成功") ''' test_16_shopCollection 清空我的收藏 点击收藏店铺 进入我的收藏页面查找是否有收藏的店铺 ''' def tearDown(self): self.driver.close() autolog.info("tearDown")
class TestStoreDeatil(unittest.TestCase): def setUp(self): self.driver = Pyse('chrome') self.driver.open(get_url("shopDetail_page")) #登录 self.driver.login() time.sleep(2) ''' 项目开始setUp 登录 ''' def test_1_storeImg(self): pass ''' src = self.driver.get_attribute(get_element("storeDetail_page", "store_img_loc"),"src") if src: self.driver.open(str("http://10.82.12.25/centralize-purchase/"+src)) assert self.driver.get_title()!="404 Not Found" # self.assertEqual(self.driver.get_title(), "404 Not Found", "店铺头像打开失败!") autolog.info("店铺页面图片展示正常") else: autolog.info("无法获取src") assert False,("获取src失败") ''' ''' test_1_storeImg 店铺图片(头像)展示 获取图片src并访问 ''' def test_2_shopName(self): autolog.info("店铺名数据库显示:" + shopName) text = self.driver.text_in_element( get_element("storeDetail_page", "shopName_text_loc"), shopName) autolog.info(text) assert text != 0 # self.assertEqual(text,0,"店铺名与实际不符") autolog.info("店铺名正常") ''' test_2_shopName 店铺名显示,与数据库数据对比 ''' def test_3_majorGoods(self): '''主营商品展示''' autolog.info("主营商品数据库显示:" + majorGoods) text = self.driver.text_in_element( get_element("storeDetail_page", "majorGoods_text_loc"), majorGoods) autolog.info(text) assert text == 1 autolog.info("主营商品信息显示正常") ''' test_3_majorGoods 主营商品展示,与数据库做对比 ''' def test_4_majorType(self): '''主营品牌显示''' text = self.driver.text_in_element( get_element("storeDetail_page", "majorType_text_loc"), majorType) autolog.info(text) assert text == 1 autolog.info("主营品牌显示正常") ''' test_4_majorType 主营品牌显示,与数据库做对比 ''' def test_5_mainHarhour(self): '''常用港口展示''' text = self.driver.text_in_element( get_element("storeDetail_page", "mainHarhour_text_loc"), mainHarhour) autolog.info(text) assert text == 1 autolog.info("主营品牌显示正常") ''' test_5_majorHarhour 常用港口展示,与数据库做对比 ''' def test_6_contacts(self): '''联系人展示''' text = self.driver.text_in_element( get_element("storeDetail_page", "contacts_text_loc"), contacts) autolog.info(text) assert text == 1 autolog.info("联系人显示正常") ''' test_6_contacts 联系人展示,与数据库做对比 ''' def test_7_contactsInformation(self): '''联系方式''' text = self.driver.text_in_element( get_element("storeDetail_page", "contactsInformation_text_loc"), contactsInformation) autolog.info(text) assert text == 1 autolog.info("联系方式显示正常") ''' test_7_contactsInformation 联系方式展示,与数据库做对比 ''' def test_8_qqNumber(self): '''qq号码''' text = self.driver.text_in_element( get_element("storeDetail_page", "qqNumber_text_loc"), qqNumber) autolog.info(text) assert text != 0 autolog.info("qq号码显示正常") ''' test_8_qqNumber QQ号码展示,与数据库做对比 ''' def test_9_1_shopPro(self): '''公司介绍信息''' text = self.driver.text_in_element( get_element("storeDetail_page", "shopPro_text_loc"), shopPro) autolog.info(text) assert text == 1 autolog.info("公司介绍信息显示正常") ''' test_9_shopPro 公司信息展示,与数据库做对比 ''' def test_9_2_carAlert(self): '''加入购物车-弹窗-去看看按钮跳转购物车页面''' try: dic = self.driver.load_table("storeDetail_page", "table_data_loc", "table_name_loc") autolog.info(dic) self.driver.click( get_element("storeDetail_page", "firstLineCar_button_loc")) time.sleep(1) words = self.driver.get_attribute( get_element("storeDetail_page", "alertWords_text_loc"), "text") autolog.info(words) self.driver.click( get_element("storeDetail_page", "alertGoToSee_button_loc")) time.sleep(1) now_url = self.driver.get_current_url() autolog.info(now_url) assert now_url == "http://10.82.12.25/centralize-purchase/#/shoppingCart", ( "未成功跳转页面") autolog.info("成功跳转购物车页") except: error = traceback.format_exc() autolog.error(error) assert False ''' test_10_carAlert 加入购物车弹窗 验证是否能获取到表格信息 点击第一行数据的加入购物车按钮 通过弹窗进入购物车页面 ''' def test_9_3_collection(self): '''加入收藏按钮变色验证''' try: dic = self.driver.load_table("storeDetail_page", "table_data_loc", "table_name_loc") autolog.info(dic) loc = get_element("storeDetail_page", "firstLineCollection_button_loc") #点击前 class1 = self.driver.get_attribute(loc, "class") autolog.info("点击收藏前的class:%s" % class1) self.driver.click(loc) time.sleep(1) #点击后 class2 = self.driver.get_attribute(loc, "class") autolog.info("点击收藏后的class%s" % class2) assert class2 != class1, ("收藏后未变色") autolog.info("成功点击后变色") except: error = traceback.format_exc() autolog.error(error) assert False ''' test_11_collection 点击收藏按钮,验证点击后是否变色(点击前后button的class是否不同) ''' def tearDown(self): self.driver.quit() autolog.info("tearDown")