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()
Example #2
0
class TestStoreDeatil(unittest.TestCase):
    def setUp(self):
        self.driver = Pyse('chrome')
        self.driver.open(get_url("shopDetail_page"))
        #登录
        self.driver.login()
        time.sleep(2)

    '''
    项目开始setUp
    登录
    '''

    def test_1_storeImg(self):
        pass
        '''
        src = self.driver.get_attribute(get_element("storeDetail_page", "store_img_loc"),"src")
        if src:
          self.driver.open(str("http://10.82.12.25/centralize-purchase/"+src))
          assert self.driver.get_title()!="404 Not Found"
          # self.assertEqual(self.driver.get_title(), "404 Not Found", "店铺头像打开失败!")
          autolog.info("店铺页面图片展示正常")
        else:
          autolog.info("无法获取src")
          assert False,("获取src失败")       
        '''

    '''
    test_1_storeImg
    店铺图片(头像)展示
    获取图片src并访问
    '''

    def test_2_shopName(self):
        autolog.info("店铺名数据库显示:" + shopName)
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "shopName_text_loc"), shopName)
        autolog.info(text)
        assert text != 0
        # self.assertEqual(text,0,"店铺名与实际不符")
        autolog.info("店铺名正常")

    '''
    test_2_shopName
    店铺名显示,与数据库数据对比
    '''

    def test_3_majorGoods(self):
        '''主营商品展示'''
        autolog.info("主营商品数据库显示:" + majorGoods)
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "majorGoods_text_loc"), majorGoods)
        autolog.info(text)
        assert text == 1
        autolog.info("主营商品信息显示正常")

    '''
    test_3_majorGoods
    主营商品展示,与数据库做对比
    '''

    def test_4_majorType(self):
        '''主营品牌显示'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "majorType_text_loc"), majorType)
        autolog.info(text)
        assert text == 1
        autolog.info("主营品牌显示正常")

    '''
    test_4_majorType
    主营品牌显示,与数据库做对比
    '''

    def test_5_mainHarhour(self):
        '''常用港口展示'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "mainHarhour_text_loc"),
            mainHarhour)
        autolog.info(text)
        assert text == 1
        autolog.info("主营品牌显示正常")

    '''
    test_5_majorHarhour
    常用港口展示,与数据库做对比
    '''

    def test_6_contacts(self):
        '''联系人展示'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "contacts_text_loc"), contacts)
        autolog.info(text)
        assert text == 1
        autolog.info("联系人显示正常")

    '''
    test_6_contacts
    联系人展示,与数据库做对比
    '''

    def test_7_contactsInformation(self):
        '''联系方式'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "contactsInformation_text_loc"),
            contactsInformation)
        autolog.info(text)
        assert text == 1
        autolog.info("联系方式显示正常")

    '''
    test_7_contactsInformation
    联系方式展示,与数据库做对比
    '''

    def test_8_qqNumber(self):
        '''qq号码'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "qqNumber_text_loc"), qqNumber)
        autolog.info(text)
        assert text != 0
        autolog.info("qq号码显示正常")

    '''
    test_8_qqNumber
    QQ号码展示,与数据库做对比
    '''

    def test_9_1_shopPro(self):
        '''公司介绍信息'''
        text = self.driver.text_in_element(
            get_element("storeDetail_page", "shopPro_text_loc"), shopPro)
        autolog.info(text)
        assert text == 1
        autolog.info("公司介绍信息显示正常")

    '''
    test_9_shopPro
    公司信息展示,与数据库做对比
    '''

    def test_9_2_carAlert(self):
        '''加入购物车-弹窗-去看看按钮跳转购物车页面'''
        try:
            dic = self.driver.load_table("storeDetail_page", "table_data_loc",
                                         "table_name_loc")
            autolog.info(dic)
            self.driver.click(
                get_element("storeDetail_page", "firstLineCar_button_loc"))
            time.sleep(1)
            words = self.driver.get_attribute(
                get_element("storeDetail_page", "alertWords_text_loc"), "text")
            autolog.info(words)
            self.driver.click(
                get_element("storeDetail_page", "alertGoToSee_button_loc"))
            time.sleep(1)
            now_url = self.driver.get_current_url()
            autolog.info(now_url)
            assert now_url == "http://10.82.12.25/centralize-purchase/#/shoppingCart", (
                "未成功跳转页面")
            autolog.info("成功跳转购物车页")
        except:
            error = traceback.format_exc()
            autolog.error(error)
            assert False

    '''
    test_10_carAlert
    加入购物车弹窗
    验证是否能获取到表格信息
    点击第一行数据的加入购物车按钮
    通过弹窗进入购物车页面
    '''

    def test_9_3_collection(self):
        '''加入收藏按钮变色验证'''
        try:
            dic = self.driver.load_table("storeDetail_page", "table_data_loc",
                                         "table_name_loc")
            autolog.info(dic)
            loc = get_element("storeDetail_page",
                              "firstLineCollection_button_loc")
            #点击前
            class1 = self.driver.get_attribute(loc, "class")
            autolog.info("点击收藏前的class:%s" % class1)
            self.driver.click(loc)
            time.sleep(1)
            #点击后
            class2 = self.driver.get_attribute(loc, "class")
            autolog.info("点击收藏后的class%s" % class2)
            assert class2 != class1, ("收藏后未变色")
            autolog.info("成功点击后变色")
        except:
            error = traceback.format_exc()
            autolog.error(error)
            assert False

    '''
    test_11_collection
    点击收藏按钮,验证点击后是否变色(点击前后button的class是否不同)
    '''

    def tearDown(self):
        self.driver.quit()
        autolog.info("tearDown")
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()
Example #4
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.page_name = "login_page"
        self.login = Pyse('chrome')
        self.login.open(get_url("home_page"))

    '''
    case:用户登录-正确登录
    1.正确匹配的用户名、密码
    2.登录跳转
    expected:
    登录成功,跳转首页
    '''

    def test_1_login_1_normal(self):
        self.login.click(get_element("login_page", "switch_button_loc"))
        autolog.info("弹出登录窗口")
        current_handle = self.login.switch_window()
        autolog.info("输入用户名:")
        self.login.send_keys(get_element("login_page", "username_input_loc"),
                             "15881122294")
        autolog.info("输入密码:")
        self.login.send_keys(get_element("login_page", "password_input_loc"),
                             "Xian1016")
        autolog.info("输入验证码:")
        self.login.send_keys(get_element("login_page", "verifyCode_input_loc"),
                             "8888")
        autolog.info("确认登录")
        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()

    '''
    case:用户登录-必填项验证
    1.用户名、密码分别为空
    2.用户名、密码同时为空
    expected:
    登录失败,显示对应提示信息
    '''
    # def test_1_login_2_required(self):
    '''
    case:用户登录-无效用户名或密码
    1、错误用户名
    2.错误密码
    expected:
    登录失败,显示对应提示信息
    '''
    # def test_1_login_3_invalid(self):
    '''
    case:用户登录-自动登录
    1.正确登录
    2.二次登录验证
    expected:
    二次登录时自动登录成功
    '''

    # def test_1_login_4_auto_login(self):

    def tearDown(self):
        self.login.quit()