예제 #1
0
    def test_search(self):
        #实例化分类页
        cp = ClassifyPage(self.driver)
        #点击搜索框
        cp.click(cp.search_locator)
        sleep(1)
        #获取搜索页面的大框框
        sep = SearchPage(self.driver)
        frame = cp.find_element(sep.frame_locator)
        #找到热门搜索
        elements = frame.find_elements(By.CLASS_NAME,
                                       'android.widget.TextView')
        print(elements)
        text = "a"
        for i in range(len(elements)):
            if elements[i].text == "热门搜索":
                #点击热门搜索下的第一个商品
                text = elements[i + 1].text
                elements[i + 1].click()
                sleep(2)
                break

        #断言
        assert1 = sep.text(sep.goods_text_locator1)
        assert2 = sep.text(sep.goods_text_locator2)
        assert3 = sep.text(sep.goods_text_locator3)
        assert4 = sep.text(sep.goods_text_locator4)
        self.assertIn(text, assert1)
        self.assertIn(text, assert2)
        self.assertIn(text, assert3)
        self.assertIn(text, assert4)
예제 #2
0
 def test_sort_case(self):
     # 实例化分类页面
     cp = ClassifyPage(self.driver)
     sleep(1)
     #点击价格排序
     cp.click(cp.sort_by_price_locator)
     sleep(1)
     # 再次点击价格排序
     cp.click(cp.sort_by_price_locator1)
예제 #3
0
 def test_search(self):
     #实例化分类页
     cp = ClassifyPage(self.driver)
     #点击搜索框
     cp.click(cp.search_locator)
     sleep(1)
     #点击热门搜索商品
     sp = SearchPage(self.driver)
     sp.tap(sp.hot_search_locator)
예제 #4
0
 def test_return_to_classify(self):
     cp = ClassifyPage(self.driver)
     sleep(5)
     cp.click(cp.goods_locator)
     sleep(1)
     gp = GoodDetailPage(self.driver)
     gp.click(gp.return_locator)
     sleep(2)
     #断言
     cp = ClassifyPage(self.driver)
     text = cp.find_element(cp.sort_by_price_locator1).text
     self.assertIn('价格', text)
예제 #5
0
 def test_shopping_cart_subtract_case(self):
     """减少购物车商品个数"""
     sleep(5)
     hm = HomePage(self.driver)
     try:
         hm.click(hm.classify_tab_loc)  # 点击分类标签
     except Exception:
         hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     sleep(2)
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     sleep(2)
     cifp.send_keys(cifp.search_view_loc, "特仑苏纯牛奶")  # 输入牛奶
     cifp.click(cifp.tv_search_loc)  # 点击搜索
     sleep(3)
     cifp.click(cifp.milk_terunshu_loc)  # 点击牛奶
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     spcp.click(spcp.add_shopping_loc)  # 点击增加
     number1 = int(spcp.text(spcp.count_shopping_loc))
     spcp.click(spcp.sub_shopping_loc)  #减少
     number2 = int(spcp.text(spcp.count_shopping_loc))
     self.assertTrue(number2 < number1)  # 断言
     spcp.click(spcp.delete_the_goods_loc)  # 点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)
예제 #6
0
 def test_all_select_case(self):
     """购物车全选商品"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     try:
         glsa = guess_like_shop_add(self.driver, 1,
                                    spcp.shopping_cart_recycleview_loc)
         glsa.click()  #选择猜你喜欢的商品
     except Exception:
         spcp.click(spcp.close_btn_new_loc)  # 如果有新人专享关闭新人专享
         glsa = guess_like_shop_add(self.driver, 1,
                                    spcp.shopping_cart_recycleview_loc)
         glsa.click()
     spcp.click(spcp.select_all_loc)  #取消全选
     spcp.click(spcp.select_all_loc)  #全选
     cp = count_price(self.driver,
                      spcp.shopping_cart_recycleview_loc)  #统计价格
     self.assertEqual(cp[0], float(spcp.text(spcp.all_price_loc)))  #断言
     spcp.click(spcp.delete_the_goods_loc)  #删除商品
     spcp.click(spcp.ensure_delete_the_goods_loc)  #确认删除
예제 #7
0
 def test_delete_goods_case(self):
     """购物车删除商品"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     try:
         co[0].click()  # 选择要删除的商品
         spcp.click(spcp.delete_the_goods_loc)  # 点击删除
         spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
         cp = count_price(self.driver,
                          spcp.shopping_cart_recycleview_loc)  #获取商品名列表
     except Exception:
         spcp.click(spcp.close_btn_new_loc)  #如果有新人专享关闭新人专享
         co[0].click()  # 选择要删除的商品
         spcp.click(spcp.delete_the_goods_loc)  # 点击删除
         spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
         cp = count_price(self.driver, spcp.shopping_cart_recycleview_loc)
     self.assertNotIn(co[5].text, cp[1])  #断言
예제 #8
0
 def test_go_order_fill_case(self):
     """跳转到去结算"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     try:
         spcp.click(spcp.check_out_loc)  #点击去结算
     except Exception:
         spcp.click(spcp.close_btn_new_loc)  #如果有新人专享关闭新人专享
         spcp.click(spcp.check_out_loc)  # 点击去结算
     odfp = OrderFillPage(self.driver)  #实例化结算页面
     try:
         text = odfp.text(odfp.order_fill_title_loc)
     except Exception:
         odfp.click(odfp.redemption_give_up_loc)
         text = odfp.text(odfp.order_fill_title_loc)
     self.assertEqual(text.strip(), "订单填写")  #断言
     odfp.click(odfp.go_back_shopping_cart_loc)  #返回购物车
     co[0].click()  #选择要删除的商品
     spcp.click(spcp.delete_the_goods_loc)  #点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
예제 #9
0
 def test_return_shopping_cart_case(self):
     """从去凑单返回"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     try:
         spcp.click(spcp.available_coupons_loc)  # 点击可用优惠券
     except Exception:
         spcp.click(spcp.close_btn_new_loc)  #如果有新人专享关闭新人专享
         spcp.click(spcp.available_coupons_loc)  # 点击可用优惠券
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     spcp.click(spcp.go_coudan_loc)  # 点击去凑单
     gcp = GoCoudanPage(self.driver)  #实例化去凑单页面
     gcp.click(gcp.return_shopping_cart_loc)  # 返回购物车
     self.assertEqual(
         spcp.text(spcp.shopping_cart_title_loc).strip(), "购物车")
     co[2].click()  # 点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
예제 #10
0
 def test_sort_case(self):
     try:
         # 实例化分类页面
         cp = ClassifyPage(self.driver)
         sleep(1)
         # 点击价格排序
         cp.click(cp.sort_by_price_locator)
         sleep(1)
         # 再次点击价格排序
         cp.click(cp.sort_by_price_locator1)
         # 断言
         price1 = cp.find_element(cp.goods_price_locator1).text.strip("¥")
         price2 = cp.find_element(cp.goods_price_locator2).text.strip("¥")
         price3 = cp.find_element(cp.goods_price_locator3).text.strip("¥")
         price4 = cp.find_element(cp.goods_price_locator4).text.strip("¥")
         self.assertGreater(price1, price2)
         self.assertGreater(price2, price3)
         self.assertGreater(price3, price4)
     except:
         self.assertIn('x', 'y')
예제 #11
0
 def test_shopping_add_cart_case(self):
     """商品添加购物车"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  #点击分类标签
     cifp = ClassifyPage(self.driver)  #实例化商品分类页
     cifp.click(cifp.cart_view_loc)  #点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  #输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  #点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  #选择包含特仑苏纯牛奶的商品
     cifp.click(cifp.buy_now_loc, gls)  #点击
     cifp.click(cifp.cart_view_loc)  #跳转购物车页面
     spcp = ShoppingCartPage(self.driver)  #实例化购物车页面
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     self.assertEqual(co[5].text, cifp.text(cifp.buy_now_loc, gls))  #断言
     co[2].click()  #点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)
예제 #12
0
 def test_shopping_cart_subtract_case(self):
     """减少购物车商品个数"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.cart_view_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  #跳转购物车页面
     co[1].click()  # 点击增加
     number1 = co[4].text()
     co[2].click()
     number2 = co[4].text()
     self.assertTrue(number2 < number1)  # 断言
     co[2].click()  # 点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
예제 #13
0
 def test_go_coudan_case(self):
     """跳转到去凑单"""
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.cart_view_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     co = commodity_operating(self.driver,
                              spcp.shopping_cart_recycleview_loc, "特仑苏纯牛奶")
     cifp.click(cifp.buy_now_loc, gls)  # 点击
     cifp.click(cifp.cart_view_loc)  #跳转购物车页面
     spcp.click(spcp.available_coupons_loc)  #点击可用优惠券
     spcp.click(spcp.go_coudan_loc)  #点击去凑单
     gcp = GoCoudanPage(self.driver)
     self.assertEqual(gcp.text(gcp.go_coudan_title_loc).strip(), "凑单有优惠")
     gcp.click(gcp.return_shopping_cart_loc)  #返回购物车
     co[2].click()  # 点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)  # 确认删除
예제 #14
0
 def test_shopping_add_cart_case(self):
     """商品添加购物车"""
     sleep(5)
     hm = HomePage(self.driver)
     try:
         hm.click(hm.classify_tab_loc)  #点击分类标签
     except Exception:
         hm.click(hm.classify_tab_loc)  #点击分类标签
     cifp = ClassifyPage(self.driver)  #实例化商品分类页
     sleep(2)
     cifp.click(cifp.search_text_loc)  #点击搜索框
     sleep(2)
     cifp.send_keys(cifp.search_view_loc, "特仑苏纯牛奶")  #输入牛奶
     cifp.click(cifp.tv_search_loc)  #点击搜索
     sleep(3)
     cifp.click(cifp.milk_terunshu_loc)
     text1 = cifp.text(cifp.milk_terunshu_name_loc).strip("热销")
     cifp.click(cifp.cart_view_loc)  #跳转购物车页面
     spcp = ShoppingCartPage(self.driver)  #实例化购物车页面
     text2 = spcp.text(spcp.milk_name_loc)  #获取加入购物车商品名
     self.assertEqual(text1, text2)  #断言
     spcp.click(spcp.delete_the_goods_loc)  #点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)
예제 #15
0
 def test_add_adress_case(self):
     """添加地址"""
     name = "leo"
     tel = "18227589708"
     city = "成都市"
     address = "锦江区东方广场c座"
     doorplate = "7楼"
     hm = HomePage(self.driver)
     hm.click(hm.classify_tab_loc)  # 点击分类标签
     cifp = ClassifyPage(self.driver)  # 实例化商品分类页
     cifp.click(cifp.search_text_loc)  # 点击搜索框
     cifp.send_keys(cifp.search_view_loc, "牛奶")  # 输入牛奶
     cifp.click(cifp.suggest_contentt_loc)  # 点击特仑苏牛奶
     gls = guess_like_shop(self.driver, "特仑苏纯牛奶",
                           cifp.result_recycler_loc)  # 选择包含特仑苏纯牛奶的商品
     spcp = ShoppingCartPage(self.driver)  # 实例化购物车页面
     cifp.click(cifp.buy_now_loc, gls)  # 点击需要买的商品
     cifp.click(cifp.cart_view_loc)  # 跳转购物车页面
     try:
         spcp.click(spcp.check_out_loc)  # 点击去结算
     except Exception:
         spcp.click(spcp.close_btn_new_loc)  # 如果有新人专享关闭新人专享
         spcp.click(spcp.check_out_loc)  # 点击去结算
     odfp = OrderFillPage(self.driver)  #实例化结算页面
     try:
         odfp.click(odfp.address_lable_loc)  #点击去填写地址
     except Exception:
         odfp.click(odfp.redemption_give_up_loc)  #放弃换购
         odfp.click(odfp.address_lable_loc)  #点击去填写地址
     aap = AdressAddPage(self.driver)  #实例化填写地址页面
     aap.click(aap.edit_address_receiver_loc)
     aap.send_keys(aap.edit_address_receiver_loc, name)  #填写收件人姓名
     aap.click(aap.sex_sir_loc)  #性别选男
     aap.click(aap.edit_address_tel_loc)
     aap.send_keys(aap.edit_address_tel_loc, tel)  #填写电话号码
     aap.click(aap.edit_detail_address_loc)  #点击填写地址
     nadp = NewAddAdressPage(self.driver)  #实例化新加地址页面
     nadp.click(nadp.entrance_choose_city_loc)  #点击搜索框旁边城市
     cocp = ChooseCityPage(self.driver)  #实例化选择城市
     cocp.click(cocp.search_address_input_city_loc)  #点击一下城市输入框
     cocp.send_keys(cocp.search_address_input_city_loc, city)  #输入成都市
     cocp.click(cocp.click_input_city_loc)  #点击输入的城市成都市
     nadp.click(nadp.search_address_input_loc)
     nadp.send_keys(nadp.search_address_input_loc, address)  #输入锦江区东方广场c座
     nadp.click(nadp.choose_input_address_loc)  #点击输入的地址
     aap.click(aap.edit_doorplate_loc)
     aap.send_keys(aap.edit_doorplate_loc, doorplate)  #输入门牌号
     aap.click(aap.home_address_tags_loc)  #选择家标签
     aap.click(aap.save_address_loc)  #保存地址
     self.assertEqual(
         odfp.text(odfp.address_detail_loc).strip(),
         address + doorplate)  #断言
     odfp.click(odfp.go_back_shopping_cart_loc)  #返回购物车
     spcp.click(spcp.delete_the_goods_loc)  #点击删除
     spcp.click(spcp.ensure_delete_the_goods_loc)  #确认删除
     spcp.click(spcp.mine_tab_loc)  #去我的
     mp = MinePage(self.driver)  #实例化我的页面
     mp.to_up()  #向上滑
     mp.click(mp.shipping_address_loc)  #点击收货地址
     esap = EditShippingAddressPage(self.driver)  #实例化编辑地址
     esap.click(esap.edit_shipping_address_loc)  #点击编辑
     esap.click(esap.delete_address_loc)  #点击删除