class TestAdress(unittest.TestCase):
    def setUp(self):
        self.url = "addressManger_page"
        self.driver = Pyse('chrome')
        self.driver.open(get_url("home_page"))
        #登录
        self.driver.login()
        self.driver.click(get_element("home_page", "member_href_loc"))
        self.driver.click(get_element("member_page",
                                      "addressManager_href_loc"))

    '''
    setUp
    进入首页登录
    再进入地址管理页面
    '''

    def test_1_newGetAdress(self):
        '''新建收货地址'''
        # 清空数据库地址信息
        selectBySql("delete from cenpur_user_address where user_id ='%s'" %
                    user_id)
        aaa = selectBySql(
            "select * from cenpur_user_address where user_id ='%s'" % user_id)
        autolog.info(aaa)

        time.sleep(2)
        #输入地址信息
        self.driver.click(
            get_element("addressManger_page", "newGetAdress_button_loc"))
        autolog.info("点击新增收货地址")
        self.driver.send_keys(
            get_element("addressManger_page", "getPerson_textBox_loc"),
            getPerson_value)
        autolog.info("填写收货人")
        self.driver.send_keys(
            get_element("addressManger_page", "deatilAdress_textBox_loc"),
            deatilAdress_value)
        autolog.info("填写详细地址")
        self.driver.send_keys(
            get_element("addressManger_page", "companyName_textBox_loc"),
            companyName_value)
        autolog.info("填写公司名称")
        self.driver.send_keys(
            get_element("addressManger_page",
                        "contactInformation_textBox_loc"),
            contactInformation_value)
        autolog.info("填写联系方式")
        self.driver.click(get_element("addressManger_page", "keep_button_loc"))
        autolog.info("点击保存")
        try:
            data = self.driver.load_table("addressManger_page",
                                          "data_table_loc", "name_table_loc")
            if data:
                autolog.info(data)
                assert True
            else:
                autolog.info(data)
                assert False, ("数据错误")
        except:
            autolog.error(traceback.format_exc())
            assert False, ("未获取到表格数据")

    '''
    test_1_newGetAdress
    新建收货地址
    数据库清空我的地址
    新建地址后查询页面是否显示
    '''

    def test_2_newPostAdress(self):
        '''新增发货地址'''
        # 清空数据库地址信息
        selectBySql("delete from cenpur_user_address where user_id =%s" %
                    user_id)
        time.sleep(2)
        self.driver.click(
            get_element("addressManger_page", "postAdress_span_loc"))
        time.sleep(1)
        self.driver.click(
            get_element("addressManger_page", "newGetAdress_button_loc"))
        autolog.info("点击新增收货地址")
        self.driver.send_keys(
            get_element("addressManger_page", "getPerson_textBox_loc"),
            getPerson_value)
        autolog.info("填写收货人")
        self.driver.send_keys(
            get_element("addressManger_page", "deatilAdress_textBox_loc"),
            deatilAdress_value)
        autolog.info("填写详细地址")
        self.driver.send_keys(
            get_element("addressManger_page", "companyName_textBox_loc"),
            companyName_value)
        autolog.info("填写公司名称")
        self.driver.send_keys(
            get_element("addressManger_page",
                        "postContactInformation_text_loc"),
            contactInformation_value)
        autolog.info("填写联系方式")
        self.driver.send_keys(
            get_element("addressManger_page", "horbor_textBox_loc"),
            horbor_value)
        autolog.info("填写仓库、港口信息")
        self.driver.click(get_element("addressManger_page", "post_button_loc"))
        autolog.info("点击保存")
        try:
            data = self.driver.load_table("addressManger_page",
                                          "data_table_loc", "name_table_loc")
            if data:
                autolog.info(data)
                assert True
            else:
                autolog.info(data)
                assert False, ("数据错误")
        except:
            autolog.error(traceback.format_exc())
            assert False, ("未获取到表格数据")

    '''
    test_2_newPostAdress
    新建发货地址
    数据库清空我的地址
    新建地址后查询页面是否显示
    '''

    def tearDown(self):
        self.driver.close()
        autolog.info("tearDown")
class TestMyFavourite(unittest.TestCase):
    def setUp(self):
        self.driver = Pyse('firefox')
        self.driver.open(get_url("home_page"))
        self.driver.click(get_element("login_page", "switch_button_loc"))
        current_handle = self.driver.switch_window()
        self.driver.send_keys(get_element("login_page", "username_input_loc"),
                              "15881122294")
        self.driver.send_keys(get_element("login_page", "password_input_loc"),
                              "Xian1016")
        self.driver.send_keys(
            get_element("login_page", "verifyCode_input_loc"), "8888")
        self.driver.click(get_element("login_page", "login_button_loc"))
        time.sleep(2)
        result_handle = self.driver.all_window_handles()
        self.assertNotIn(current_handle, result_handle, "登录失败,登录窗口未关闭!")
        self.driver.switch_to_single_window()
        self.driver.find_element(get_element("home_page",
                                             "product_href_loc")).click()
        time.sleep(2)

    '''
    case:加入收藏夹-商品收藏-商品详情页面
    expected:
    成功收藏商品
    '''

    def test_1_addFavorite_1_addGoods_1_goodsDetail(self):
        goods_name = self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).text
        self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page", "addFavorite_button_loc")).click()
        time.sleep(2)
        goods_favorite_status = self.driver.find_element(
            get_element("myFavorite_page", "addFavorite_status_text_loc")).text
        self.assertEqual("已收藏产品", goods_favorite_status, "商品收藏状态错误")
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        favorite_goods_name = self.driver.find_element(
            get_element("myFavorite_page",
                        "myFavorite_goodsName_text_loc")).text
        self.assertIn(goods_name, favorite_goods_name, "商品详情页面-添加收藏夹失败")
        delete_sql = "DELETE FROM cenpur_mall_favorites where user_id = '26878e6d32df4e1c95b579af43990da4'"
        connect_sql(delete_sql)

    '''
    case:加入收藏夹-商品收藏-店铺详情页面
    expected:
    成功收藏商品
    '''

    def test_1_addFavorite_1_addGoods_2_shopDetail(self):
        self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("cart_page", "enterShop_button_loc")).click()
        time.sleep(2)
        shop_goods_list = self.driver.load_table(
            "cart_page", "shopDetail_goodsList_table_data_loc",
            "shopDetail_goodsList_table_name_loc")
        shop_goods_name_list = shop_goods_list["商品品名"]
        self.driver.find_element(
            get_element("cart_page",
                        "shopDetail_addFavorite_button_loc")).click()
        self.driver.find_element(
            get_element("home_page", "shopDetail_member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        favorite_goods_name = self.driver.find_element(
            get_element("myFavorite_page",
                        "myFavorite_goodsName_text_loc")).text
        self.assertIn(shop_goods_name_list[0], favorite_goods_name,
                      "店铺详情页面-添加收藏夹失败")

    '''
    case:加入收藏夹-店铺收藏
    expected:
    成功收藏店铺
    '''

    def test_1_addFavorite_2_addShop_1_addFavorite(self):
        self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page", "addShop_button_loc")).click()
        time.sleep(2)
        shop_favorite_status = self.driver.find_element(
            get_element("myFavorite_page", "addShop_button_loc")).text
        self.assertEqual("已收藏", shop_favorite_status, "店铺收藏状态错误")
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        self.driver.find_element(
            get_element("myFavorite_page", "favoriteShop_tab_loc")).click()
        self.assertTrue(
            self.driver.is_element_exist(
                get_element("myFavorite_page",
                            "favoriteShop_delete_button_loc")), "店铺收藏失败")

    '''
    case:加入收藏夹-店铺收藏-进入店铺详情页面
    expected:
    通过收藏店铺页面进入店铺详情页面
    '''

    def test_1_addFavorite_2_addShop_2_enterShopDetail(self):
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        self.driver.find_element(
            get_element("myFavorite_page", "favoriteShop_tab_loc")).click()
        self.driver.find_element(
            get_element("myFavorite_page",
                        "favoriteShop_enterShopDetail_button_loc")).click()
        self.assertTrue(
            self.driver.is_element_exist(
                get_element("myFavorite_page",
                            "shopDetail_goodsName_text_loc")),
            "收藏店铺-跳转店铺详情页面失败")

    '''
    case:加入收藏夹-删除-商品
    expected:
    收藏商品从收藏夹中移除
    '''

    def test_1_addFavorite_3_deleteFavorite_1_goods(self):
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page",
                        "favoriteGoods_delete_button_loc")).click()
        time.sleep(2)
        self.assertFalse(
            self.driver.is_element_exist(
                get_element("myFavorite_page",
                            "favoriteGoods_delete_button_loc")), "收藏夹商品删除失败")

    '''
    case:加入收藏夹-删除-店铺
    expected:
    收藏店铺从收藏夹中移除
    '''

    def test_1_addFavorite_3_deleteFavorite_2_shop(self):
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page", "favoriteShop_tab_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page",
                        "favoriteShop_delete_button_loc")).click()
        time.sleep(2)
        self.assertFalse(
            self.driver.is_element_exist(
                get_element("myFavorite_page",
                            "favoriteShop_delete_button_loc")), "收藏夹商品删除失败")

    '''
    case:收藏夹-加入购物车
    expected:
    收藏夹商品成功加入购物车
    '''

    def _2_toCart_1_addCart(self):
        goods_name = self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).text
        self.driver.find_element(
            get_element("myFavorite_page",
                        "product_goodsName_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myFavorite_page", "addFavorite_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(get_element("home_page",
                                             "member_href_loc")).click()
        self.driver.find_element(
            get_element("member_page", "favorite_href_loc")).click()
        self.driver.find_element(
            get_element("myFavorite_page",
                        "favoriteGoods_checkAll_checkbox_loc")).click()
        # test = self.driver.is_element_exist(get_element("myFavorite_page", "favoriteGoods_checkAll_checkbox_loc"))
        current_url = self.driver.get_current_url()
        self.driver.find_element(
            get_element("myFavorite_page", "addToCart_button_loc")).click()
        time.sleep(1)
        skip_url = self.driver.get_current_url()
        self.assertNotEqual(current_url, skip_url, "收藏夹页面跳转购物车页面失败")
        cart_goods_name = self.driver.find_element(
            get_element("cart_page", "cartGoods_name_text_loc")).text
        self.assertIn(goods_name, cart_goods_name, "商品详情页面-商品添加购物车失败")
        delete_cart_goods_sql = "DELETE FROM cenpur_mall_cart_goods where cart_id = (select id from " \
                                "cenpur_mall_cart where user_id = '26878e6d32df4e1c95b579af43990da4')"
        connect_sql(delete_cart_goods_sql)
        delete_favorite_goods_sql = "DELETE FROM cenpur_mall_favorites " \
                                    "where user_id = '26878e6d32df4e1c95b579af43990da4'"
        connect_sql(delete_favorite_goods_sql)

    def tearDown(self):
        self.driver.close()
Beispiel #3
0
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 TestMyCart(unittest.TestCase):

    def setUp(self):
        self.driver = Pyse('firefox')
        self.driver.open(get_url("home_page"))
        self.driver.click(get_element("login_page", "switch_button_loc"))
        current_handle = self.driver.switch_window()
        self.driver.send_keys(get_element("login_page", "username_input_loc"), "15881122294")
        self.driver.send_keys(get_element("login_page", "password_input_loc"), "Xian1016")
        self.driver.send_keys(get_element("login_page", "verifyCode_input_loc"), "8888")
        self.driver.click(get_element("login_page", "login_button_loc"))
        time.sleep(2)
        result_handle = self.driver.all_window_handles()
        self.assertNotIn(current_handle, result_handle, "登录失败,登录窗口未关闭!")
        self.driver.switch_to_single_window()
        self.driver.click(get_element("home_page", "product_href_loc"))
        time.sleep(2)
    '''
    case:加入购物车-入口验证-商品详情页面
    expected:
    成功将商品加入购物车
    '''
    def test_1_addCart_1_entry_1_goodsDetail(self):
        # 获取加入购物车商品名称
        all_goods_list = self.driver.load_table(
            "cart_page", "goodsList_table_data_loc", "goodsList_table_name_loc")
        all_goods_name_list = all_goods_list["商品名称"]
        # 跳转商品详情页面
        self.driver.find_element(get_element("cart_page", "goodsList_goodsName_text_loc")).click()
        self.assertTrue(self.driver.is_element_exist(
            get_element("cart_page", "goodsDetail_addCart_button_loc")), "跳转商品详情页面失败")
        # 获取购物车商品显示计数
        if self.driver.is_element_exist(get_element("cart_page", "goodsDetail_cartAccount_span_loc")):
            cart_goods_account_before = self.driver.find_element(
                get_element("cart_page", "goodsDetail_cartAccount_span_loc")).text
        else:
            cart_goods_account_before = 0
        # 加入购物车
        self.driver.find_element(get_element("cart_page", "goodsDetail_addCart_button_loc")).click()
        self.assertTrue(self.driver.is_element_exist(
            get_element("cart_page", "addCart_info_skipToCart_button_loc")), "加入购物车确认弹窗未弹出")
        # 继续购物
        self.driver.find_element(get_element("cart_page", "addCart_info_keepShopping_button_loc")).click()
        self.assertFalse(self.driver.is_element_exist(
            get_element("cart_page", "addCart_info_skipToCart_button_loc")), "加入购物车确认弹窗未关闭")
        if self.driver.is_element_exist(get_element("cart_page", "goodsDetail_cartAccount_span_loc")):
            cart_goods_account_after = self.driver.find_element(
                get_element("cart_page", "goodsDetail_cartAccount_span_loc")).text
        else:
            cart_goods_account_after = 0
        self.assertEqual(cart_goods_account_before+1, int(cart_goods_account_after), "购物车商品显示计数错误")
        # 再次加入购物车
        self.driver.find_element(get_element("cart_page", "goodsDetail_addCart_button_loc")).click()
        self.assertTrue(self.driver.is_element_exist(
            get_element("cart_page", "addCart_info_skipToCart_button_loc")), "加入购物车确认弹窗未弹出")
        # 去看看,跳转购物车页面
        current_url = self.driver.get_current_url()
        self.driver.find_element(get_element("cart_page", "addCart_info_skipToCart_button_loc")).click()
        cart_goods_account_again = self.driver.find_element(
            get_element("cart_page", "goodsCart_cartAccount_span_loc")).text
        self.assertEqual(int(cart_goods_account_after), int(cart_goods_account_again), "添加相同商品到购物车,显示计数错误")
        skip_url = self.driver.get_current_url()
        self.assertNotEqual(current_url, skip_url, "跳转购物车页面失败")
        # 获取购物车商品名称
        cart_goods_name = self.driver.find_element(get_element("cart_page", "cartGoods_name_text_loc")).text
        self.assertIn(all_goods_name_list[0], cart_goods_name, "商品详情页面-商品添加购物车失败")
        delete_sql = "DELETE FROM cenpur_mall_cart_goods where " \
                     "cart_id = (select id from cenpur_mall_cart where user_id = '26878e6d32df4e1c95b579af43990da4')"
        connect_sql(delete_sql)
    '''
    case:加入购物车-入口验证-店铺详情页面
    expected:
    成功将商品加入购物车
    '''
    def test_1_addCart_1_entry_2_shopDetail(self):
        self.driver.find_element(get_element("cart_page", "goodsList_goodsName_text_loc")).click()
        time.sleep(1)
        self.driver.find_element(get_element("cart_page", "enterShop_button_loc")).click()
        time.sleep(2)
        shop_goods_list = self.driver.load_table(
            "cart_page", "shopDetail_goodsList_table_data_loc", "shopDetail_goodsList_table_name_loc")
        shop_goods_name_list = shop_goods_list["商品品名"]
        if self.driver.is_element_exist(get_element("cart_page", "goodsCart_cartAccount_span_loc")):
            cart_goods_account_before = self.driver.find_element(
                get_element("cart_page", "goodsCart_cartAccount_span_loc")).text
        else:
            cart_goods_account_before = 0
        # 加入购物车
        self.driver.find_element(get_element("cart_page", "shopDetail_addCart_button_loc")).click()
        self.assertTrue(self.driver.is_element_exist(
            get_element("cart_page", "addCart_info_skipToCart_button_loc")), "加入购物车确认弹窗未弹出")
        # 继续购物
        self.driver.find_element(get_element("cart_page", "addCart_info_keepShopping_button_loc")).click()
        self.assertFalse(self.driver.is_element_exist(
            get_element("cart_page", "addCart_info_skipToCart_button_loc")), "加入购物车确认弹窗未关闭")
        if self.driver.is_element_exist(get_element("cart_page", "goodsCart_cartAccount_span_loc")):
            cart_goods_account_after = self.driver.find_element(
                get_element("cart_page", "goodsCart_cartAccount_span_loc")).text
        else:
            cart_goods_account_after = 0
        self.assertEqual(cart_goods_account_before + 1, int(cart_goods_account_after), "购物车商品显示计数错误")
        self.driver.find_element(get_element("cart_page", "shopDetail_addCart_button_loc")).click()
        self.driver.find_element(get_element("cart_page", "addCart_info_skipToCart_button_loc")).click()
        cart_goods_name = self.driver.find_element(get_element("cart_page", "cartGoods_name_text_loc")).text
        self.assertIn(shop_goods_name_list[0], cart_goods_name, "商品详情页面-商品添加购物车失败")
        delete_sql = "DELETE FROM cenpur_mall_cart_goods where " \
                     "cart_id = (select id from cenpur_mall_cart where user_id = '26878e6d32df4e1c95b579af43990da4')"
        connect_sql(delete_sql)
    '''
    case:加入购物车-商品采购量
    expected:
    修改默认商品采购量,购物车商品采购量正确显示
    '''
    def test_1_addCart_2_purchaseNum(self):
        self.driver.find_element(get_element("cart_page", "goodsList_goodsName_text_loc")).click()
        time.sleep(2)
        mini_order = self.driver.find_element(
            get_element("cart_page", "purchaseAccount_input_loc")).get_attribute("value")
        self.driver.find_element(get_element("cart_page", "purchaseAccount_input_loc")).clear()
        custom_order = int(mini_order) + 10
        self.driver.find_element(get_element("cart_page", "purchaseAccount_input_loc")).send_keys(custom_order)
        self.driver.find_element(get_element("cart_page", "goodsDetail_addCart_button_loc")).click()
        self.driver.find_element(get_element("cart_page", "addCart_info_skipToCart_button_loc")).click()
        goods_cart_purchase_account = self.driver.find_element(
            get_element("cart_page", "goodsCart_purchaseAccount_input_loc")).get_attribute("value")
        self.assertEqual(custom_order, int(goods_cart_purchase_account), "自定义商品采购量错误")
    '''
    case:加入购物车-购物车总价计算
    expected:
    总价 = 单价*采购量
    '''
    def test_2_cart_1_total(self):
        self.driver.find_element(get_element("cart_page", "myCart_button_loc")).click()
        goods_cart_purchase_account = self.driver.find_element(
            get_element("cart_page", "goodsCart_purchaseAccount_input_loc")).get_attribute("value")
        unit_price = re.sub("\D", "", self.driver.find_element(
            get_element("cart_page", "goodsCart_unitPrice_text_loc")).text)
        total = re.sub("\D", "", self.driver.find_element(get_element("cart_page", "goodsCart_total_text_loc")).text)
        self.assertEqual(int(total), int(goods_cart_purchase_account)*int(unit_price), "购物车商品总价错误")
    '''
    case:加入购物车-删除购物车商品
    expected:
    商品从购物车中移除
    '''
    def test_2_cart_2_deleteGoods(self):
        self.driver.find_element(get_element("cart_page", "myCart_button_loc")).click()
        time.sleep(2)
        self.assertTrue(self.driver.is_element_exist
                        (get_element("cart_page", "deleteGoods_button_loc")), "跳转购物车页面失败")
        self.driver.find_element(get_element("cart_page", "deleteGoods_button_loc")).click()
        time.sleep(2)
        self.assertFalse(self.driver.is_element_exist(
            get_element("cart_page", "cartGoods_name_text_loc")), "商品删除失败")
        self.driver.find_element(get_element("home_page", "shopDetail_member_href_loc")).click()
        self.driver.find_element(get_element("member_page", "favorite_href_loc")).click()
        time.sleep(2)
        self.assertTrue(get_element("myFavorite_page", "myFavorite_goodsName_text_loc"), "购物车商品移入收藏夹失败")
        delete_sql = "DELETE FROM cenpur_mall_favorites where user_id = '26878e6d32df4e1c95b579af43990da4'"
        connect_sql(delete_sql)
    '''
    case:购物车-购物车商品加入收藏夹
    expected:
    购物车商品成功加入收藏夹
    '''
    def test_3_toFavorite_1_addToFavorite(self):
        self.driver.find_element(get_element("cart_page", "goodsList_goodsName_text_loc")).click()
        time.sleep(2)
        self.driver.find_element(get_element("cart_page", "goodsDetail_addCart_button_loc")).click()
        self.driver.find_element(get_element("cart_page", "addCart_info_skipToCart_button_loc")).click()
        time.sleep(2)
        goods_name = self.driver.find_element(get_element("cart_page", "cartGoods_name_text_loc")).text
        self.driver.find_element(get_element("cart_page", "cart_addFavourite_button_loc")).click()
        self.driver.find_element(get_element("cart_page", "cart_member_href_loc")).click()
        self.driver.find_element(get_element("member_page", "favorite_href_loc")).click()
        favorite_goods_name = self.driver.find_element(
            get_element("myFavorite_page", "myFavorite_goodsName_text_loc")).text
        self.assertEqual(goods_name, favorite_goods_name, "购物车商品加入收藏夹失败")
        delete_sql = "DELETE FROM cenpur_mall_favorites where user_id = '26878e6d32df4e1c95b579af43990da4'"
        connect_sql(delete_sql)
    '''
    case:购物车-购物车商品移入收藏夹
    expected:
    购物车商品成功加入收藏夹
    '''
    def test_3_toFavorite_2_shiftInFavorite(self):
        self.driver.find_element(get_element("cart_page", "myCart_button_loc")).click()
        time.sleep(2)
        goods_name = self.driver.find_element(get_element("cart_page", "cartGoods_name_text_loc")).text
        self.driver.find_element(get_element("cart_page", "cart_shiftInFavourite_button_loc")).click()
        time.sleep(1)
        self.assertFalse(self.driver.is_element_exist(
            get_element("cart_page", "cart_shiftInFavourite_button_loc")), "移入收藏夹,购物车列表删除失败")
        self.driver.find_element(get_element("cart_page", "cart_member_href_loc")).click()
        self.driver.find_element(get_element("member_page", "favorite_href_loc")).click()
        time.sleep(2)
        favorite_goods_name = self.driver.find_element(
            get_element("myFavorite_page", "myFavorite_goodsName_text_loc")).text
        self.assertEqual(goods_name, favorite_goods_name, "购物车商品移入收藏夹失败")
        delete_sql = "DELETE FROM cenpur_mall_favorites where user_id = '26878e6d32df4e1c95b579af43990da4'"
        connect_sql(delete_sql)

    def tearDown(self):
        self.driver.close()