class TestMyGoods(unittest.TestCase):
    def setUp(self):
        self.driver = Pyse('firefox')
        self.driver.open(get_url("home_page"))
        autolog.info("登录")
        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", "member_href_loc"))
        self.driver.click(get_element("member_page", "myGoods_href_loc"))
        time.sleep(2)

    '''
    case:待提交商品-检查数据
    expected:
    正确加载待提交商品列表,商品信息正确显示
    '''

    def test_myGoods_1_draftGoods_1_data(self):
        autolog.info("切换到待提交商品页面")
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        # 数据库获取待提交商品信息
        draft_goods_sql = "select code,name,tagout_num,harbor,store,price_type,price from cenpur_mall_goods " \
                          "where shop_id = 2 and state = 0"
        sql_draft_goods_list = connect_sql(draft_goods_sql)
        # 获取数据库待提交商品编码列表
        sql_goods_num_list = []
        for i in sql_draft_goods_list:
            sql_goods_num_list.append(i[0])
        # 断言商品条数是否一致
        self.assertEqual(len(sql_goods_num_list),
                         len(draft_goods_list["商品编号"]), "待提交商品列表加载失败")
        for i in draft_goods_list["状态"]:
            self.assertEqual("待提交", i, "商品状态错误")

    '''
    case:待提交商品-可用功能列表
    expected:
    待提交商品可用功能:查看,修改,删除,上架,复制挂牌
    '''

    def test_myGoods_1_draftGoods_2_option(self):
        autolog.info("切换到待提交商品页面")
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        print(draft_goods_list["操作"])
        self.assertIn("查看", draft_goods_list["操作"][0], "待提交商品缺少功能-查看")
        self.assertIn("修改", draft_goods_list["操作"][0], "待提交商品缺少功能-修改")
        self.assertIn("删除", draft_goods_list["操作"][0], "待提交商品缺少功能-删除")
        self.assertIn("上架", draft_goods_list["操作"][0], "待提交商品缺少功能-上架")
        self.assertIn("复制挂牌", draft_goods_list["操作"][0], "待提交商品缺少功能-复制挂牌")
        self.assertNotIn("下架", draft_goods_list["操作"][0], "待提交商品错误功能-下架")
        self.assertNotIn("暂停销售", draft_goods_list["操作"][0], "待提交商品错误功能-暂停销售")
        self.assertNotIn("继续销售", draft_goods_list["操作"][0], "待提交商品错误功能-继续销售")

    '''
    case:待提交商品-查看
    expected:
    跳转商品挂盘页面,商品信息无法编辑
    '''

    def test_myGoods_1_draftGoods_3_view(self):
        autolog.info("切换到待提交商品页面")
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        current_url = self.driver.get_current_url()
        autolog.info("查看商品")
        self.driver.find_element(
            get_element("myGoods_page", "goods_button1_loc")).click()
        skip_url = self.driver.get_current_url()
        self.assertNotEqual(current_url, skip_url, "点击查看,页面未跳转")
        goods_name_input = self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_goodsName_input_loc"))
        goods_name_attr = goods_name_input.get_attribute("disabled")
        self.assertTrue(goods_name_attr, "商品查看页面,商品信息可编辑")

    '''
    case:待提交商品-编辑存草稿
    expected:
    跳转商品编辑页面,可以修改商品信息
    '''

    def test_myGoods_1_draftGoods_4_edit_draft(self):
        autolog.info("切换到待提交商品页面")
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        current_url = self.driver.get_current_url()
        autolog.info("修改商品")
        self.driver.find_element(
            get_element("myGoods_page", "goods_button2_loc")).click()
        time.sleep(1)
        skip_url = self.driver.get_current_url()
        self.assertNotEqual(current_url, skip_url, "点击修改,页面未跳转")
        goods_name_input = self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_goodsName_input_loc"))
        goods_name_input.clear()
        autolog.info("修改商品名称:testEdit")
        goods_name_input.send_keys("testEdit")
        self.assertEqual("testEdit", goods_name_input.get_attribute("value"),
                         "编辑商品名称失败")
        autolog.info("存草稿")
        self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_draft_button_loc")).click()
        autolog.info("切换到待提交商品页面")
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        edit_draft_goods_list = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        self.assertIn("testEdit", edit_draft_goods_list["商品名称"], "编辑商品保存失败")

    '''
    case:待提交商品-编辑上架
    expected:
    商品上架
    '''

    def test_myGoods_1_draftGoods_5_edit_sale(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sale_goods_account_before = len(sale_goods_list_before["商品名称"])
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myGoods_page", "goods_button2_loc")).click()
        time.sleep(1)
        goods_name_input = self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_goodsName_input_loc"))
        goods_name_input.clear()
        goods_name_input.send_keys("ForTest")
        self.assertEqual("ForTest", goods_name_input.get_attribute("value"),
                         "编辑商品名称失败")
        self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_sale_button_loc")).click()
        time.sleep(2)
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_after = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sale_goods_account_after = len(sale_goods_list_after["商品名称"])
        self.assertEqual(sale_goods_account_before + 1,
                         sale_goods_account_after, "待提交商品列表加载错误")
        select_sql = "select state from cenpur_mall_goods where shop_id = 2 and name = 'ForTest'"
        goods_status = connect_sql(select_sql)
        self.assertEqual(1, goods_status[0][0], "商品状态错误")
        update_sql = "update cenpur_mall_goods set state = 0 where shop_id = 2 and name = 'ForTest'"
        connect_sql(update_sql)

    '''
    case:待提交商品-删除商品
    expected:
    删除后,商品列表中不显示该商品
    '''

    def test_myGoods_1_draftGoods_6_delete(self):
        all_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        all_goods_account_before = len(all_goods_list_before["商品名称"])
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        delete_goods_name = draft_goods_list_before["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button3_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "删除确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % delete_goods_name
        goods_status = connect_sql(select_sql)
        self.assertEqual(4, goods_status[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "allGoods_button_loc")).click()
        time.sleep(2)
        all_goods_list_after = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        all_goods_account_after = len(all_goods_list_after["商品名称"])
        self.assertEqual(all_goods_account_before - 1, all_goods_account_after,
                         "所有商品列表商品总数有误")
        update_sql = "update cenpur_mall_goods set state = 0 where shop_id=2 and name='%s'" % delete_goods_name
        connect_sql(update_sql)

    '''
    case:待提交商品-复制挂牌
    expected:
    跳转商品编辑页面,存草稿新增一个待提交商品
    '''

    def test_myGoods_1_draftGoods_7_copy(self):
        pass

    '''
    case:待提交商品-上架商品
    expected:
    商品状态改变
    '''

    def test_myGoods_1_draftGoods_8_sale(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sale_goods_accout_before = len(sale_goods_list_before["商品名称"])
        self.driver.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        sale_goods_name = draft_goods_list["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button4_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "上架确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % sale_goods_name
        goods_state = connect_sql(select_sql)
        self.assertEqual(1, goods_state[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_after = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sale_goods_accout_after = len(sale_goods_list_after["商品名称"])
        self.assertEqual(sale_goods_accout_before + 1, sale_goods_accout_after,
                         "商品上架失败")
        update_sql = "update cenpur_mall_goods set state = 0 where shop_id=2 and name='%s'" % sale_goods_name
        connect_sql(update_sql)

    '''
    case:所有商品-检查数据
    expected:
    所有商品正确加载
    '''

    def test_myGoods_2_allGoods_1_data(self):
        all_goods_sql = "select code,name,tagout_num,harbor,store,price_type,price from cenpur_mall_goods " \
                          "where shop_id = 2 and state != 4"
        sql_all_goods_list = connect_sql(all_goods_sql)
        sql_all_goods_code_list = []
        for i in sql_all_goods_list:
            sql_all_goods_code_list.append(i[0])
        all_goods_list = self.driver.load_table("myGoods_page",
                                                "myGoods_table_data_loc",
                                                "myGoods_table_name_loc")
        self.assertEqual(len(sql_all_goods_code_list),
                         len(all_goods_list["商品编号"]), "所有商品列表加载失败")

    '''
    case:已上架商品-检查数据
    expected:
    正确加载已上架商品列表,商品信息正确显示
    '''

    def test_myGoods_3_saleGoods_1_data(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list = self.driver.load_table("myGoods_page",
                                                 "myGoods_table_data_loc",
                                                 "myGoods_table_name_loc")
        # 数据库获取待提交商品信息
        draft_goods_sql = "select code,name,tagout_num,harbor,store,price_type,price from cenpur_mall_goods " \
                          "where shop_id = 2 and state = 1"
        sql_sale_goods_list = connect_sql(draft_goods_sql)
        # 获取数据库待提交商品编码列表
        sql_goods_num_list = []
        for i in sql_sale_goods_list:
            sql_goods_num_list.append(i[0])
        # 断言商品条数是否一致
        self.assertEqual(len(sql_goods_num_list), len(sale_goods_list["商品编号"]),
                         "已上架商品列表加载失败")
        for i in sale_goods_list["状态"]:
            self.assertEqual("已上架", i, "商品状态错误")

    '''
    case:已上架商品-可用功能列表
    expected:
    已上架商品可用功能:查看,下架,暂停销售,复制挂牌
    '''

    def test_myGoods_3_saleGoods_2_option(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        print(draft_goods_list["操作"])
        self.assertIn("查看", draft_goods_list["操作"][0], "待提交商品缺少功能-查看")
        self.assertIn("下架", draft_goods_list["操作"][0], "待提交商品缺少功能-下架")
        self.assertIn("暂停销售", draft_goods_list["操作"][0], "待提交商品缺少功能-暂停销售")
        self.assertIn("复制挂牌", draft_goods_list["操作"][0], "待提交商品缺少功能-复制挂牌")
        self.assertNotIn("上架", draft_goods_list["操作"][0], "待提交商品错误功能-上架")
        self.assertNotIn("删除", draft_goods_list["操作"][0], "待提交商品错误功能-删除")
        self.assertNotIn("继续销售", draft_goods_list["操作"][0], "待提交商品错误功能-继续销售")
        self.assertNotIn("修改", draft_goods_list["操作"][0], "待提交商品错误功能-修改")

    '''
    case:已上架商品-查看
    expected:
    跳转商品挂盘页面,商品信息无法编辑
    '''

    def test_myGoods_3_saleGoods_3_view(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        current_url = self.driver.get_current_url()
        self.driver.find_element(
            get_element("myGoods_page", "goods_button1_loc")).click()
        skip_url = self.driver.get_current_url()
        self.assertNotEqual(current_url, skip_url, "点击查看,页面未跳转")
        goods_name_input = self.driver.find_element(
            get_element("myGoods_page", "goodsInfo_goodsName_input_loc"))
        input_attr = goods_name_input.get_attribute("disabled")
        self.assertTrue(input_attr, "商品查看页面,商品信息可编辑")

    '''
    case:已上架商品-暂停销售
    expected:
    商品状态变为已暂停
    '''

    def test_myGoods_3_saleGoods_4_pause(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        pause_goods_name = sale_goods_list_before["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button3_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "暂停销售确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        sale_goods_list_after = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        goods_name = sale_goods_list_after["商品名称"][0]
        self.assertNotEqual(pause_goods_name, goods_name, "商品暂停销售失败")
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % pause_goods_name
        goods_state = connect_sql(select_sql)
        self.assertEqual(2, goods_state[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "pauseGoods_button_loc")).click()
        time.sleep(2)
        pause_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        pause_goods_name_list = pause_goods_list["商品名称"]
        self.assertIn(pause_goods_name, pause_goods_name_list, "商品加入已暂停商品列表失败")
        update_sql = "update cenpur_mall_goods set state = 1 where shop_id=2 and name='%s'" % pause_goods_name
        connect_sql(update_sql)

    '''
    case:已上架商品-下架
    expected:
    商品状态变为已下架
    '''

    def test_myGoods_3_saleGoods_5_soldOut(self):
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sold_out_goods_name = sale_goods_list_before["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button2_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "商品下架确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % sold_out_goods_name
        goods_state = connect_sql(select_sql)
        self.assertEqual(3, goods_state[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "soldOutGoods_button_loc")).click()
        time.sleep(2)
        sold_out_goods_list = self.driver.load_table("myGoods_page",
                                                     "myGoods_table_data_loc",
                                                     "myGoods_table_name_loc")
        sold_out_goods_name_list = sold_out_goods_list["商品名称"]
        self.assertIn(sold_out_goods_name, sold_out_goods_name_list,
                      "商品加入已下架商品列表失败")
        update_sql = "update cenpur_mall_goods set state = 1 where shop_id=2 and name='%s'" % sold_out_goods_name
        connect_sql(update_sql)

    '''
    case:已暂停商品-检查数据
    expected:
    正确加载已暂停商品列表,商品信息正确显示
    '''

    def test_myGoods_4_pauseGoods_1_data(self):
        self.driver.find_element(
            get_element("myGoods_page", "pauseGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list = self.driver.load_table("myGoods_page",
                                                 "myGoods_table_data_loc",
                                                 "myGoods_table_name_loc")
        # 数据库获取待提交商品信息
        draft_goods_sql = "select code,name,tagout_num,harbor,store,price_type,price from cenpur_mall_goods " \
                          "where shop_id = 2 and state = 2"
        sql_sale_goods_list = connect_sql(draft_goods_sql)
        # 获取数据库待提交商品编码列表
        sql_goods_num_list = []
        for i in sql_sale_goods_list:
            sql_goods_num_list.append(i[0])
        # 断言商品条数是否一致
        self.assertEqual(len(sql_goods_num_list), len(sale_goods_list["商品编号"]),
                         "已上架商品列表加载失败")
        for i in sale_goods_list["状态"]:
            self.assertEqual("已暂停", i, "商品状态错误")

    '''
    case:已暂停商品-可用功能列表
    expected:
    已暂停商品可用功能:查看,下架,继续销售,复制挂牌
    '''

    def test_myGoods_4_pauseGoods_2_option(self):
        self.driver.find_element(
            get_element("myGoods_page", "pauseGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        print(draft_goods_list["操作"])
        self.assertIn("查看", draft_goods_list["操作"][0], "待提交商品缺少功能-查看")
        self.assertIn("下架", draft_goods_list["操作"][0], "待提交商品缺少功能-下架")
        self.assertIn("继续销售", draft_goods_list["操作"][0], "待提交商品缺少功能-继续销售")
        self.assertIn("复制挂牌", draft_goods_list["操作"][0], "待提交商品缺少功能-复制挂牌")
        self.assertNotIn("上架", draft_goods_list["操作"][0], "待提交商品错误功能-上架")
        self.assertNotIn("暂停销售", draft_goods_list["操作"][0], "待提交商品错误功能-暂停销售")
        self.assertNotIn("修改", draft_goods_list["操作"][0], "待提交商品错误功能-修改")
        self.assertNotIn("删除", draft_goods_list["操作"][0], "待提交商品错误功能-删除")

    '''
    case:已暂停商品-下架商品
    expected:
    商品状态改变,加入已下架列表
    '''

    def test_myGoods_4_pauseGoods_3_soldOut(self):
        self.driver.find_element(
            get_element("myGoods_page", "pauseGoods_button_loc")).click()
        time.sleep(2)
        pause_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sold_out_goods_name = pause_goods_list_before["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button2_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "商品下架确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % sold_out_goods_name
        goods_state = connect_sql(select_sql)
        self.assertEqual(3, goods_state[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "soldOutGoods_button_loc")).click()
        time.sleep(2)
        sold_out_goods_list = self.driver.load_table("myGoods_page",
                                                     "myGoods_table_data_loc",
                                                     "myGoods_table_name_loc")
        sold_out_goods_name_list = sold_out_goods_list["商品名称"]
        self.assertIn(sold_out_goods_name, sold_out_goods_name_list,
                      "商品加入已下架商品列表失败")
        update_sql = "update cenpur_mall_goods set state = 2 where shop_id=2 and name='%s'" % sold_out_goods_name
        connect_sql(update_sql)

    '''
    case:已暂停商品-商品继续销售
    expected:
    商品状态改变,加入已上架列表
    '''

    def test_myGoods_4_pauseGoods_4_keepSale(self):
        self.driver.find_element(
            get_element("myGoods_page", "pauseGoods_button_loc")).click()
        time.sleep(2)
        pause_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        sale_goods_name = pause_goods_list_before["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button3_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "商品继续销售确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % sale_goods_name
        goods_state = connect_sql(select_sql)
        self.assertEqual(1, goods_state[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "saleGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list = self.driver.load_table("myGoods_page",
                                                 "myGoods_table_data_loc",
                                                 "myGoods_table_name_loc")
        sale_goods_name_list = sale_goods_list["商品名称"]
        self.assertIn(sale_goods_name, sale_goods_name_list, "商品加入已上架商品列表失败")
        update_sql = "update cenpur_mall_goods set state = 2 where shop_id=2 and name='%s'" % sale_goods_name
        connect_sql(update_sql)

    '''
     case:已下架商品-检查数据
     expected:
     正确加载已下架商品列表,商品信息正确显示
     '''

    def test_myGoods_5_soldOutGoods_1_data(self):
        self.driver.find_element(
            get_element("myGoods_page", "soldOutGoods_button_loc")).click()
        time.sleep(2)
        sale_goods_list = self.driver.load_table("myGoods_page",
                                                 "myGoods_table_data_loc",
                                                 "myGoods_table_name_loc")
        # 数据库获取待提交商品信息
        draft_goods_sql = "select code,name,tagout_num,harbor,store,price_type,price from cenpur_mall_goods " \
                          "where shop_id = 2 and state = 1"
        sql_sale_goods_list = connect_sql(draft_goods_sql)
        # 获取数据库待提交商品编码列表
        sql_goods_num_list = []
        for i in sql_sale_goods_list:
            sql_goods_num_list.append(i[0])
        # 断言商品条数是否一致
        self.assertEqual(len(sql_goods_num_list), len(sale_goods_list["商品编号"]),
                         "已下架商品列表加载失败")
        for i in sale_goods_list["状态"]:
            self.assertEqual("已下架", i, "商品状态错误")

    '''
    case:已下架商品-可用功能列表
    expected:
    已下架商品可用功能:查看,删除,复制挂牌
    '''

    def test_myGoods_5_soldOutGoods_2_option(self):
        self.driver.find_element(
            get_element("myGoods_page", "soldOutGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.driver.load_table("myGoods_page",
                                                  "myGoods_table_data_loc",
                                                  "myGoods_table_name_loc")
        print(draft_goods_list["操作"])
        self.assertIn("查看", draft_goods_list["操作"][0], "待提交商品缺少功能-查看")
        self.assertIn("删除", draft_goods_list["操作"][0], "待提交商品缺少功能-删除")
        self.assertIn("复制挂牌", draft_goods_list["操作"][0], "待提交商品缺少功能-复制挂牌")
        self.assertNotIn("修改", draft_goods_list["操作"][0], "待提交商品错误功能-修改")
        self.assertNotIn("上架", draft_goods_list["操作"][0], "待提交商品错误功能-上架")
        self.assertNotIn("下架", draft_goods_list["操作"][0], "待提交商品错误功能-下架")
        self.assertNotIn("暂停销售", draft_goods_list["操作"][0], "待提交商品错误功能-暂停销售")
        self.assertNotIn("继续销售", draft_goods_list["操作"][0], "待提交商品错误功能-继续销售")

    '''
    case:已下架商品-删除商品
    expected:
    商品删除后,不再在商品列表中显示
    '''

    def test_myGoods_5_soldOutGoods_2_delete(self):
        all_goods_list_before = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        all_goods_account_before = len(all_goods_list_before["商品名称"])
        self.driver.find_element(
            get_element("myGoods_page", "soldOutGoods_button_loc")).click()
        time.sleep(2)
        sold_out_goods_list = self.driver.load_table("myGoods_page",
                                                     "myGoods_table_data_loc",
                                                     "myGoods_table_name_loc")
        delete_goods_name = sold_out_goods_list["商品名称"][0]
        self.driver.find_element(
            get_element("myGoods_page", "goods_button2_loc")).click()
        button_status = self.driver.is_element_exist(
            get_element("myGoods_page", "confirm_button_loc"))
        self.assertTrue(button_status, "删除确认窗口未弹出")
        self.driver.find_element(
            get_element("myGoods_page", "confirm_button_loc")).click()
        time.sleep(2)
        select_sql = "select state from cenpur_mall_goods where shop_id=2 and name='%s'" % delete_goods_name
        goods_status = connect_sql(select_sql)
        self.assertEqual(4, goods_status[0][0], "商品状态错误")
        self.driver.find_element(
            get_element("myGoods_page", "allGoods_button_loc")).click()
        time.sleep(2)
        all_goods_list_after = self.driver.load_table(
            "myGoods_page", "myGoods_table_data_loc", "myGoods_table_name_loc")
        all_goods_account_after = len(all_goods_list_after["商品名称"])
        self.assertEqual(all_goods_account_before - 1, all_goods_account_after,
                         "所有商品列表商品总数有误")
        update_sql = "update cenpur_mall_goods set state = 0 where shop_id=2 and name='%s'" % delete_goods_name
        connect_sql(update_sql)

    '''
    case:其他-搜索商品
    expected:
    根据搜索关键字显示商品列表
    '''

    def test_myGoods_6_other_1_searchByKey(self):
        all_goods_list = self.driver.load_table("myGoods_page",
                                                "myGoods_table_data_loc",
                                                "myGoods_table_name_loc")
        all_goods_name_list = all_goods_list["商品名称"]
        self.driver.find_element(
            get_element("myGoods_page",
                        "selectGoods_input_loc")).send_keys("ForTest")
        self.driver.find_element(
            get_element("myGoods_page", "selectGoods_button_loc")).click()
        time.sleep(2)
        search_goods_list = self.driver.load_table("myGoods_page",
                                                   "myGoods_table_data_loc",
                                                   "myGoods_table_name_loc")
        search_goods_name_list = search_goods_list["商品名称"]
        for i in search_goods_name_list:
            self.assertIn(i, all_goods_name_list, "搜索结果显示错误")

    def tearDown(self):
        self.driver.quit()
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()
class TestAddGoods(unittest.TestCase):
    def setUp(self):
        self.login = Pyse('chrome')
        self.login.open(get_url("home_page"))
        self.login.click(get_element("login_page", "switch_button_loc"))
        current_handle = self.login.switch_window()
        self.login.send_keys(get_element("login_page", "username_input_loc"),
                             "15881122294")
        self.login.send_keys(get_element("login_page", "password_input_loc"),
                             "Xian1016")
        self.login.send_keys(get_element("login_page", "verifyCode_input_loc"),
                             "8888")
        self.login.click(get_element("login_page", "login_button_loc"))
        time.sleep(2)
        result_handle = self.login.all_window_handles()
        self.assertNotIn(current_handle, result_handle, "登录失败,登录窗口未关闭!")
        self.login.switch_to_single_window()
        self.login.click(get_element("home_page", "member_href_loc"))
        self.login.click(get_element("member_page", "addGoods_href_loc"))
        time.sleep(2)

    '''
    case:商品挂盘-入口验证
    我的商品-商品挂盘按钮
    expected:
    成功跳转商品挂盘编辑页面
    '''

    def test_addGoods_1_entry_1_myGoods(self):
        autolog.info("跳转我的商品页面")
        time.sleep(2)
        self.login.click(get_element("member_page", "myGoods_href_loc"))
        time.sleep(2)
        self.assertEqual(get_url("goods_page"), self.login.get_current_url(),
                         "跳转我的商品页面失败!")
        autolog.info("我的商品跳转商品挂盘页面")
        self.login.click(get_element("myGoods_page", "addGoods_button_loc"))
        self.assertEqual(get_url("addGoods_page"),
                         self.login.get_current_url(), "跳转商品挂盘页面失败!")

    '''
    case:商品挂盘-入口验证
    会员中心导航栏-商品挂盘
    expected:
    成功跳转商品挂盘编辑页面
    '''

    def test_addGoods_1_entry_2_addGoods(self):
        autolog.info("跳转我的商品页面")
        time.sleep(2)
        self.login.click(get_element("member_page", "myGoods_href_loc"))
        time.sleep(2)
        autolog.info("会员中心导航栏跳转商品挂盘页面")
        self.login.click(get_element("member_page", "addGoods_href_loc"))
        self.assertEqual(get_url("addGoods_page"),
                         self.login.get_current_url(), "跳转商品挂盘页面失败!")

    '''
    case:商品挂盘-新增-提交表单
    1.挂盘方式
    2.商品类型、船名、商品大类、指标类型、品质指标、产地、币种、商品名、溢短装
    3.截止日期
    4.商品价格、计价方式、发盘量、起订量
    5、支付方式、付款时间、港口或仓库、商品图片上传
    6、后台数据库查询新增商品数据
    expected:
    后台数据库数据新增成功,商品挂盘成功
    '''

    def test_addGoods_1_submit(self):
        ship_name = "珍珠号"
        goods_name = "OnlyTest"
        time.sleep(2)
        self.login.click(get_element("member_page", "addGoods_href_loc"))
        # 选择挂盘方式-普通挂盘
        common_radio = self.login.find_element(
            get_element("addGoods_page", "commonAdd_radio_loc"))
        autolog.info("选择挂盘方式-普通挂盘")
        common_radio.click()
        add_type_is_selected = common_radio.is_selected()
        self.assertTrue(add_type_is_selected, "挂盘方式-普通挂盘选中失败!")
        # 选择商品类型-现货
        actuals_radio = self.login.find_element(
            get_element("addGoods_page", "actuals_radio_loc"))
        autolog.info("选择商品类型-现货")
        actuals_radio.click()
        goodstype_is_selected = actuals_radio.is_selected()
        self.assertTrue(goodstype_is_selected, "商品类型-现货选中失败!")
        # 填写船名:ship_name
        boat_name_text = self.login.find_element(
            get_element("addGoods_page", "shipName_input_loc"))
        autolog.info("填写船名:" + ship_name)
        boat_name_text.send_keys(ship_name)
        self.assertEqual(ship_name, boat_name_text.get_attribute("value"),
                         "船名填写失败!")
        # 选择商品大类-铁矿
        iron_ore_radio = self.login.find_element(
            get_element("addGoods_page", "ironOre_radio_loc"))
        autolog.info("选择商品大类-铁矿")
        iron_ore_radio.click()
        goods_category_is_selected = iron_ore_radio.is_selected()
        self.assertTrue(goods_category_is_selected, "商品大类-铁矿选中失败!")
        # 填写品质指标
        Fe_text = self.login.find_element(
            get_element("addGoods_page", "Fe_input_loc"))
        autolog.info("填写Fe:600")
        Fe_text.send_keys("600")
        self.assertEqual("600", Fe_text.get_attribute("value"), "Fe填写失败!")
        SiO2_text = self.login.find_element(
            get_element("addGoods_page", "SiO2_input_loc"))
        autolog.info("填写SiO2:20")
        SiO2_text.send_keys("20")
        self.assertEqual("20", SiO2_text.get_attribute("value"), "SiO2填写失败!")
        AI2O3_text = self.login.find_element(
            get_element("addGoods_page", "AI2O3_input_loc"))
        autolog.info("填写AI2O3:50")
        AI2O3_text.send_keys("50")
        self.assertEqual("50", AI2O3_text.get_attribute("value"), "AI2O3填写失败!")
        S_text = self.login.find_element(
            get_element("addGoods_page", "S_input_loc"))
        autolog.info("填写S:60")
        S_text.send_keys("60")
        self.assertEqual("60", S_text.get_attribute("value"), "S填写失败!")
        H2O_text = self.login.find_element(
            get_element("addGoods_page", "H2O_input_loc"))
        autolog.info("填写H2O:50")
        H2O_text.send_keys("50")
        self.assertEqual("50", H2O_text.get_attribute("value"), "H2O填写失败!")
        FeO_text = self.login.find_element(
            get_element("addGoods_page", "FeO_input_loc"))
        autolog.info("填写FeO:70")
        FeO_text.send_keys("70")
        self.assertEqual("70", FeO_text.get_attribute("value"), "FeO填写失败!")
        P_text = self.login.find_element(
            get_element("addGoods_page", "P_input_loc"))
        autolog.info("填写P:50")
        P_text.send_keys("50")
        self.assertEqual("50", P_text.get_attribute("value"), "P填写失败!")
        Grade_text = self.login.find_element(
            get_element("addGoods_page", "Grade_input_loc"))
        autolog.info("填写粒度指标:50")
        Grade_text.send_keys("50")
        self.assertEqual("50", Grade_text.get_attribute("value"), "粒度指标填写失败!")
        # 填写商品名:goods_name
        goods_name_text = self.login.find_element(
            get_element("addGoods_page", "goodsName_input_loc"))
        autolog.info("填写商品名:" + goods_name)
        goods_name_text.send_keys(goods_name)
        self.assertEqual(goods_name, goods_name_text.get_attribute("value"),
                         "商品名填写失败!")
        # 填写溢短装比例:10%
        more_or_less_text = self.login.find_element(
            get_element("addGoods_page", "moreOrLess_input_loc"))
        autolog.info("填写溢短装比例:" + "10%")
        more_or_less_text.send_keys("10%")
        self.assertEqual("10%", more_or_less_text.get_attribute("value"),
                         "溢短装比例填写失败!")
        # 填写截止日期:Today
        today_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        end_time_text = self.login.find_element(
            get_element("addGoods_page", "endTime_input_loc"))
        end_time_text.click()
        time.sleep(2)
        autolog.info("填写截止日期:" + today_time)
        self.login.find_element(
            get_element("addGoods_page", "endTime_button_loc")).click()
        self.assertEqual(today_time, end_time_text.get_attribute("value"),
                         "截止时间填写失败!")
        # 填写商品价格:20
        goods_price_text = self.login.find_element(
            get_element("addGoods_page", "goodsPrice_input_loc"))
        autolog.info("填写商品价格:" + "20")
        goods_price_text.send_keys("20")
        self.assertEqual("20", goods_price_text.get_attribute("value"),
                         "商品价格填写失败!")
        # 填写发盘量:5000
        stock_text = self.login.find_element(
            get_element("addGoods_page", "stock_input_loc"))
        autolog.info("填写发盘量:" + "5000")
        stock_text.send_keys("5000")
        self.assertEqual("5000", stock_text.get_attribute("value"), "发盘量填写失败!")
        # 填写起订量:200
        mini_order_text = self.login.find_element(
            get_element("addGoods_page", "miniOrder_input_loc"))
        autolog.info("填写发盘量:" + "200")
        mini_order_text.send_keys("200")
        self.assertEqual("200", mini_order_text.get_attribute("value"),
                         "发盘量填写失败!")
        # 选择支付方式-在线支付
        pay_online_checkbox = self.login.find_element(
            get_element("addGoods_page", "payOnline_checkbox_loc"))
        autolog.info("选择支付方式-在线支付")
        pay_online_checkbox.click()
        pay_online_is_selected = pay_online_checkbox.is_selected()
        self.assertTrue(pay_online_is_selected, "选择支付方式-在线支付选中失败!")
        # 选择付款时间-分期付款
        pay_advance_checkbox = self.login.find_element(
            get_element("addGoods_page", "payAdvance_checkbox_loc"))
        autolog.info("选择付款时间-分期付款")
        pay_advance_checkbox.click()
        pay_advance_is_selected = pay_advance_checkbox.is_selected()
        self.assertTrue(pay_advance_is_selected, "选择付款时间-分期付款选中失败!")
        # 选择港口或仓库-港口
        port_radio = self.login.find_element(
            get_element("addGoods_page", "port_radio_loc"))
        autolog.info("选择港口或仓库-港口")
        port_radio.click()
        port_is_selected = port_radio.is_selected()
        self.assertTrue(port_is_selected, "选择港口或仓库-港口选中失败!")
        # 上传商品图片
        autolog.info("上传商品图片:")
        upload_file = self.login.find_element(
            get_element("addGoods_page", "uploadPic_file_loc"))
        upload_file.send_keys("D:\\3、Work\\bdfintAutoTest\\pic\\1.jpg")
        time.sleep(2)
        status = self.login.is_element_exist(
            get_element("addGoods_page", "uploadPic_review_button_loc"))
        self.assertTrue(status, "图片上传失败")
        autolog.info("预览上传图片")
        self.login.find_element(
            get_element("addGoods_page",
                        "uploadPic_review_button_loc")).click()
        self.login.find_element(
            get_element("addGoods_page",
                        "uploadPic_review_close_button_loc")).click()
        time.sleep(2)
        autolog.info("删除上传图片:")
        self.login.find_element(
            get_element("addGoods_page",
                        "uploadPic_delete_button_loc")).click()
        autolog.info("再次上传商品图片:")
        upload_file = self.login.find_element(
            get_element("addGoods_page", "uploadPic_file_loc"))
        upload_file.send_keys("D:\\3、Work\\bdfintAutoTest\\pic\\1.jpg")
        time.sleep(2)
        status = self.login.is_element_exist(
            get_element("addGoods_page", "uploadPic_review_button_loc"))
        self.assertTrue(status, "图片上传失败")
        # 提交表单
        autolog.info("商品存草稿:")
        self.login.click(get_element("addGoods_page", "draft_button_loc"))
        time.sleep(2)
        # 查询数据库,验证数据插入情况
        sql = "select name,state from cenpur_mall_goods where shop_id = 2 and name = 'OnlyTest'"
        added_goods_status = connect_sql(sql)
        print(added_goods_status)
        self.assertNotEqual(0, len(added_goods_status), "新增商品插入数据库失败")
        # status:0-待提交
        self.assertEqual(0, added_goods_status[0][1], "商品状态错误")
        # 验证前端新增商品显示情况
        autolog.info("切换至待提交商品页面")
        self.login.find_element(
            get_element("myGoods_page", "draftGoods_button_loc")).click()
        time.sleep(2)
        draft_goods_list = self.login.load_table("myGoods_page",
                                                 "myGoods_table_data_loc",
                                                 "myGoods_table_name_loc")
        self.assertIn(goods_name, draft_goods_list['商品名称'], "新增商品存草稿失败")
        delete_sql = "delete from cenpur_mall_goods where shop_id = 2 and name = '%s'" % goods_name
        connect_sql(delete_sql)

    '''
    case:商品挂盘-新增-表单必填项验证-船名
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_1_shipName(self):
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "shipName_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-船名")
        autolog.info("填写船名:小螺号")
        self.login.find_element(
            get_element("addGoods_page",
                        "shipName_input_loc")).send_keys("小螺号")
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "shipName_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-船名")

    '''
    case:商品挂盘-新增-表单必填项验证-商品名
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_2_goodsName(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "goodsName_text_loc"))
        autolog.info("填写商品名称:HelloWorld")
        self.assertEqual(True, result_before, "必填项提示信息未显示-商品名")
        self.login.find_element(
            get_element("addGoods_page",
                        "goodsName_input_loc")).send_keys("HelloWorld")
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "goodsName_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-商品名")

    '''
    case:商品挂盘-新增-表单必填项验证-商品价格
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_3_goodsPrice(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "goodsPrice_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-商品价格")
        autolog.info("填写商品价格:20")
        self.login.find_element(
            get_element("addGoods_page",
                        "goodsPrice_input_loc")).send_keys("20")
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "goodsPrice_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-商品价格")

    '''
    case:商品挂盘-新增-表单必填项验证-发盘量
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_4_stock(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "stock_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-发盘量")
        autolog.info("填写商品发盘量:5000")
        self.login.find_element(get_element(
            "addGoods_page", "stock_input_loc")).send_keys("5000")
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "stock_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-发盘量")

    '''
    case:商品挂盘-新增-表单必填项验证-起订量
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_5_miniOrder(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "miniOrder_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-起订量")
        autolog.info("填写商品起订量:100")
        self.login.find_element(
            get_element("addGoods_page",
                        "miniOrder_input_loc")).send_keys("100")
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "miniOrder_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-起订量")

    '''
    case:商品挂盘-新增-表单必填项验证-支付方式
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_6_payType(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "payType_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-支付方式")
        autolog.info("选择商品支付方式:在线支付")
        self.login.click(get_element("addGoods_page",
                                     "payOnline_checkbox_loc"))
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "payType_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-支付方式")

    '''
    case:商品挂盘-新增-表单必填项验证-支付时间
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_7_payTime(self):
        autolog.info("挂盘商品提交")
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        result_before = self.login.is_element_exist(
            get_element("addGoods_page", "payTime_text_loc"))
        self.assertEqual(True, result_before, "必填项提示信息未显示-支付时间")
        autolog.info("选择支付时间:分期付款")
        self.login.click(
            get_element("addGoods_page", "payAdvance_checkbox_loc"))
        autolog.info("挂盘商品提交")
        self.login.find_element(
            get_element("addGoods_page", "submit_button_loc")).click()
        time.sleep(2)
        result_after = self.login.is_element_exist(
            get_element("addGoods_page", "payTime_text_loc"))
        self.assertEqual(False, result_after, "必填项提示信息显示错误-支付时间")

    '''
    case:商品挂盘-新增-表单必填项验证-截止时间
    expected:
    表单填写不全,提交失败
    '''

    def test_addGoods_2_required_8_endTime(self):
        self.login.find_element(
            get_element("addGoods_page",
                        "shipName_input_loc")).send_keys("TestTime")
        self.login.find_element(
            get_element("addGoods_page", "ironOre_radio_loc")).click()
        self.login.find_element(get_element("addGoods_page",
                                            "Fe_input_loc")).send_keys("30")
        self.login.find_element(get_element("addGoods_page",
                                            "SiO2_input_loc")).send_keys("20")
        self.login.find_element(get_element("addGoods_page",
                                            "AI2O3_input_loc")).send_keys("50")
        self.login.find_element(get_element("addGoods_page",
                                            "S_input_loc")).send_keys("50")
        self.login.find_element(get_element("addGoods_page",
                                            "P_input_loc")).send_keys("50")
        self.login.find_element(get_element("addGoods_page",
                                            "H2O_input_loc")).send_keys("50")
        self.login.find_element(get_element("addGoods_page",
                                            "FeO_input_loc")).send_keys("50")
        self.login.find_element(get_element("addGoods_page",
                                            "Grade_input_loc")).send_keys("50")
        self.login.find_element(
            get_element("addGoods_page",
                        "goodsName_input_loc")).send_keys("HelloWorld")
        self.login.find_element(
            get_element("addGoods_page",
                        "goodsPrice_input_loc")).send_keys("20")
        self.login.find_element(get_element(
            "addGoods_page", "stock_input_loc")).send_keys("5000")
        self.login.find_element(
            get_element("addGoods_page",
                        "miniOrder_input_loc")).send_keys("100")
        self.login.find_element(
            get_element("addGoods_page", "payOnline_checkbox_loc")).click()
        self.login.find_element(
            get_element("addGoods_page", "payAdvance_checkbox_loc")).click()
        submit_before_url = self.login.get_current_url()
        # 提交表单
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        submit_after_url = self.login.get_current_url()
        self.assertEqual(submit_before_url, submit_after_url,
                         "页面跳转,必填项未做限制-截止时间")
        autolog.info("选择截止时间:今天")
        self.login.find_element(
            get_element("addGoods_page", "endTime_input_loc")).click()
        time.sleep(2)
        self.login.find_element(
            get_element("addGoods_page", "endTime_button_loc")).click()
        self.login.click(get_element("addGoods_page", "submit_button_loc"))
        time.sleep(2)
        submit_after_url2 = self.login.get_current_url()
        self.assertNotEqual(submit_after_url, submit_after_url2,
                            "页面未跳转,提交表单失败")
        delete_sql = "delete from cenpur_mall_goods where name = 'TestTime'"
        connect_sql(delete_sql)

    '''
    case:商品挂盘-新增-期货
    expected:
    期货对应的属性正确显示:装船期、预计离港日、预计到港日、提单日
    '''

    def test_addGoods_3_other_1_futures(self):
        autolog.info("选择商品类型:期货")
        self.login.find_element(
            get_element("addGoods_page", "futures_radio_loc")).click()
        start_time_status = self.login.is_element_exist(
            get_element("addGoods_page", "shipment_startTime_input_loc"))
        futures_text_status = self.login.is_element_exist(
            get_element("addGoods_page", "futures_text_loc"))
        self.assertTrue(start_time_status, "装船期开始时间不显示")
        self.assertTrue(futures_text_status, "必填项提示文本未显示")

    '''
    case:商品挂盘-新增-币种与商品价格单位关联
    expected:
    当币种变化时,商品价格单位自动关联变化
    '''

    def test_addGoods_3_other_2_currency(self):
        current_text = self.login.find_element(
            get_element("addGoods_page", "currency_input_loc")).text
        price_num_text_before = self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_input_loc")).text
        autolog.info("选择币种:美元")
        self.login.find_element(
            get_element("addGoods_page", "currency_input_loc")).click()
        self.login.find_element(
            get_element("addGoods_page", "currency_select_loc")).click()
        choose_text = self.login.find_element(
            get_element("addGoods_page", "currency_input_loc")).text
        self.assertNotEqual(current_text, choose_text, "币种选择失败")
        price_num_text_after = self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_input_loc")).text
        self.assertNotEqual(price_num_text_before, price_num_text_after,
                            "商品价格单位与币种关联失败")

    '''
    case:商品挂盘-新增-商品价格单位与发盘量、起订量单位关联
    expected:
    当商品价格单位变化时,发盘量和起订量单位自动关联变化
    '''

    def test_addGoods_3_other_3_priceNum(self):
        price_num_text_before = self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_input_loc")).text
        stock_num_text_before = self.login.find_element(
            get_element("addGoods_page", "stockNum_text_loc")).text
        mini_order_num_text_before = self.login.find_element(
            get_element("addGoods_page", "miniOrderNum_text_loc")).text
        autolog.info("选择商品价格单位:美元/湿吨")
        self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_input_loc")).click()
        self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_select_loc")).click()
        price_num_text_after = self.login.find_element(
            get_element("addGoods_page", "goodsPriceUnit_input_loc")).text
        self.assertNotEqual(price_num_text_before, price_num_text_after,
                            "商品价格单位选择失败")
        stock_num_text_after = self.login.find_element(
            get_element("addGoods_page", "stockNum_text_loc")).text
        mini_order_num_text_after = self.login.find_element(
            get_element("addGoods_page", "miniOrderNum_text_loc")).text
        self.assertNotEqual(stock_num_text_before, stock_num_text_after,
                            "发盘量单位关联失败")
        self.assertNotEqual(mini_order_num_text_before,
                            mini_order_num_text_after, "起订量单位关联失败")

    '''
    case:商品挂盘-新增-无收货地址时新增地址
    expected:
    新增地址按钮,新增地址弹窗
    '''

    def test_addGoods_3_other_4_addAddress(self):
        delete_sql = "delete from cenpur_user_address " \
                     "where user_id='26878e6d32df4e1c95b579af43990da4' and address_type=2"
        connect_sql(delete_sql)
        autolog.info("选择仓库")
        self.login.find_element(get_element("addGoods_page",
                                            "depot_radio_loc")).click()
        add_address_button_status = self.login.is_element_exist(
            get_element("addGoods_page", "depot_addAddress_button_loc"))
        self.assertTrue(add_address_button_status, "添加地址按钮不显示")
        autolog.info("添加发货地址")
        self.login.find_element(
            get_element("addGoods_page",
                        "depot_addAddress_button_loc")).click()
        add_address_window_status = self.login.is_element_exist(
            get_element("addGoods_page", "depot_addAddress_window_loc"))
        self.assertTrue(add_address_window_status, "添加地址窗口未弹出")
        self.login.find_element(
            get_element(
                "addGoods_page",
                "depot_addAddress_consignor_input_loc")).send_keys("测试专用")
        detail_address = "天府广场东侧速8酒店12层"
        self.login.find_element(
            get_element(
                "addGoods_page",
                "depot_addAddress_detail_input_loc")).send_keys(detail_address)
        self.login.find_element(
            get_element(
                "addGoods_page",
                "depot_addAddress_companyName_input_loc")).send_keys("Tencent")
        self.login.find_element(
            get_element("addGoods_page",
                        "depot_addAddress_depot_input_loc")).send_keys("成都港")
        self.login.find_element(
            get_element("addGoods_page",
                        "depot_addAddress_contact_input_loc")).send_keys("110")
        autolog.info("发货地址提交")
        self.login.find_element(
            get_element("addGoods_page",
                        "depot_addAddress_confirm_button_loc")).click()
        time.sleep(2)
        add_address_window_status = self.login.is_element_exist(
            get_element("addGoods_page", "depot_addAddress_window_loc"))
        self.assertFalse(add_address_window_status, "添加地址窗口未关闭")
        address_status = self.login.is_element_exist(
            get_element("addGoods_page", "depot_addressList_first_loc"))
        self.assertTrue(address_status, "加载收货地址失败")
        connect_sql(delete_sql)

    def tearDown(self):
        self.login.quit()
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()