class TestAdress(unittest.TestCase): def setUp(self): self.url = "addressManger_page" self.driver = Pyse('chrome') self.driver.open(get_url("home_page")) #登录 self.driver.login() self.driver.click(get_element("home_page", "member_href_loc")) self.driver.click(get_element("member_page", "addressManager_href_loc")) ''' setUp 进入首页登录 再进入地址管理页面 ''' def test_1_newGetAdress(self): '''新建收货地址''' # 清空数据库地址信息 selectBySql("delete from cenpur_user_address where user_id ='%s'" % user_id) aaa = selectBySql( "select * from cenpur_user_address where user_id ='%s'" % user_id) autolog.info(aaa) time.sleep(2) #输入地址信息 self.driver.click( get_element("addressManger_page", "newGetAdress_button_loc")) autolog.info("点击新增收货地址") self.driver.send_keys( get_element("addressManger_page", "getPerson_textBox_loc"), getPerson_value) autolog.info("填写收货人") self.driver.send_keys( get_element("addressManger_page", "deatilAdress_textBox_loc"), deatilAdress_value) autolog.info("填写详细地址") self.driver.send_keys( get_element("addressManger_page", "companyName_textBox_loc"), companyName_value) autolog.info("填写公司名称") self.driver.send_keys( get_element("addressManger_page", "contactInformation_textBox_loc"), contactInformation_value) autolog.info("填写联系方式") self.driver.click(get_element("addressManger_page", "keep_button_loc")) autolog.info("点击保存") try: data = self.driver.load_table("addressManger_page", "data_table_loc", "name_table_loc") if data: autolog.info(data) assert True else: autolog.info(data) assert False, ("数据错误") except: autolog.error(traceback.format_exc()) assert False, ("未获取到表格数据") ''' test_1_newGetAdress 新建收货地址 数据库清空我的地址 新建地址后查询页面是否显示 ''' def test_2_newPostAdress(self): '''新增发货地址''' # 清空数据库地址信息 selectBySql("delete from cenpur_user_address where user_id =%s" % user_id) time.sleep(2) self.driver.click( get_element("addressManger_page", "postAdress_span_loc")) time.sleep(1) self.driver.click( get_element("addressManger_page", "newGetAdress_button_loc")) autolog.info("点击新增收货地址") self.driver.send_keys( get_element("addressManger_page", "getPerson_textBox_loc"), getPerson_value) autolog.info("填写收货人") self.driver.send_keys( get_element("addressManger_page", "deatilAdress_textBox_loc"), deatilAdress_value) autolog.info("填写详细地址") self.driver.send_keys( get_element("addressManger_page", "companyName_textBox_loc"), companyName_value) autolog.info("填写公司名称") self.driver.send_keys( get_element("addressManger_page", "postContactInformation_text_loc"), contactInformation_value) autolog.info("填写联系方式") self.driver.send_keys( get_element("addressManger_page", "horbor_textBox_loc"), horbor_value) autolog.info("填写仓库、港口信息") self.driver.click(get_element("addressManger_page", "post_button_loc")) autolog.info("点击保存") try: data = self.driver.load_table("addressManger_page", "data_table_loc", "name_table_loc") if data: autolog.info(data) assert True else: autolog.info(data) assert False, ("数据错误") except: autolog.error(traceback.format_exc()) assert False, ("未获取到表格数据") ''' test_2_newPostAdress 新建发货地址 数据库清空我的地址 新建地址后查询页面是否显示 ''' def tearDown(self): self.driver.close() autolog.info("tearDown")
class 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 ProductDetail(unittest.TestCase): def setUp(self): self.driver = Pyse('chrome') self.driver.open(get_url("home_page")) # 登录点击第一个商品 self.driver.login() self.driver.click(get_element("productDetail_page", "firstLineName")) time.sleep(1) ''' setUP 登录 ''' def test_1_MBXProductLink(self): '''面包屑导航链接-大宗交易''' self.driver.click( get_element("productDetail_page", "MBXProductPage_link_loc")) time.sleep(1) url = self.driver.get_current_url() autolog.info(url) assert url == "http://10.82.12.25/centralize-purchase/#/product", ( "链接未跳转成功") autolog.info("导航链接大宗交易页面正确") ''' test_1_MBXProductLink 面包屑导航-大宗交易-链接 点击后跳转大宗交易页面 比对页面url ''' def test_2_MBXHomeLink(self): '''面包屑导航链接-首页''' self.driver.click( get_element("productDetail_page", "MBXHomePage_link_loc")) time.sleep(1) url = self.driver.get_current_url() autolog.info(url) assert url == "http://10.82.12.25/centralize-purchase/#/", ("链接未跳转成功") autolog.info("导航链接首页正确") ''' test_2_MBXHomeLink 面包屑导航-首页-链接 点击后跳转首页 比对页面url ''' def test_3_goodImg(self): '''商品图片展示''' src = self.driver.get_attribute( get_element("productDetail_page", "good_img_loc"), "src") if src: self.driver.open(str(src)) assert self.driver.get_title() != "404 Not Found" autolog.info(src) autolog.info("商品图片展示正常") else: autolog.info("无法获取src") assert False, ("获取src失败") self.assertTrue(src, "无法获取src") ''' test_3_goodImg 商品图片的展示,看是否可以访问图片地址 ''' def test_4_mainGoodType(self): '''主要信息:商品类型:期货/现货''' eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #通过商品编号查询出商品类型 type = getDicSql("type", "type", code) # type = selectBySql("SELECT label_value from cenpur_user_dict where en_name ='type' and value=(select type from cenpur_mall_goods where code ='%s')"%code) autolog.info(type) text = self.driver.text_in_element( get_element("productDetail_page", "goodType_text_loc"), type[0]) autolog.info(text) if text: autolog.info("商品类型显示正确") assert True else: autolog.info("商品类型显示错误") assert False, ("商品类型显示错误") ''' test_4_mainType 主要信息的商品类型展示:现货/期货 通过页面获取商品编号 通过商品编号获取数据库中的商品类型显示信息 比对商品类型是否显示 ''' def test_5_mainGoodPrice(self): '''主要信息-商品价格''' #获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) price = selectBySql( "SELECT price from cenpur_mall_goods where code ='%s'" % code) autolog.info(price) autolog.info(price_unit) #获取价格 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodPrice_text_loc")) text = eletext1.text autolog.info(text) #判断 re1 = text.find("¥") re2 = text.find(getNum(price[0])) re3 = text.find(str(price_unit[0])) re4 = str(price_unit[0]).find("美元") if re2 != -1 and re3 != -1: autolog.info("单位、价格验证正确") if re4 == 0 and re1 == -1: autolog.info("单位美元$") assert True elif re4 == -1 and re1 == 0: autolog.info("单位元¥") assert True else: autolog.info("单位¥/$显示错误") assert False, ("单位¥/$显示错误") else: autolog.info("单位、价格错误") assert False, ("单位、价格错误") ''' test_5_mainGoodPrice 主要信息中价格的显示 通过页面获取商品编号 通过商品编号获取数据库中的价格和单位 通过判断价格、单位、单位符号是否正确 ''' def test_6_mainName(self): '''主要信息-商品名称''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 name = selectBySql( "SELECT name from cenpur_mall_goods where code ='%s'" % code) autolog.info(name) #获取名称 text = self.driver.text_in_element( get_element("productDetail_page", "goodName_text_loc"), name[0]) autolog.info(text) if text: autolog.info("商品名称显示正确") assert True else: autolog.info("商品名称显示正确") assert False, ("商品名称显示正确") ''' test_6_mainName 主要信息:商品名 获取商品编号 查询数据库中商品名 与页面商品名做对比 ''' def test_7_mainPriceType(self): '''主要信息-计价方式''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 goods_type = connect_sql( "select type from cenpur_mall_goods where code = '%s'" % code) print('2') if goods_type[0][0] == 1: price_type = getDicSql("price_type", "price_type", code) autolog.info(price_type) # 获取计价方式 text = self.driver.text_in_element( get_element("productDetail_page", "goodPriceType_text_loc"), price_type[0]) autolog.info(text) if text: autolog.info("计价方式显示正确") assert True else: autolog.info("计价方式显示错误") assert False, ("计价方式显示错误") else: terms_price = getDicSql("terms_price", "terms_price", code) autolog.info(terms_price) # 获取价格术语 text = self.driver.text_in_element( get_element("productDetail_page", "goodPriceType_text_loc"), terms_price[0]) autolog.info(text) if text: autolog.info("价格术语显示正确") assert True else: autolog.info("价格术语显示错误") assert False, ("价格术语显示错误") ''' test_7_priceType 主要信息:计价方式 获取商品编号 查询数据库中计价方式信息 与页面获取的计价方式作对比 ''' def test_8_mainTagoutNum(self): '''主要信息-发盘量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) tagout_num = selectBySql( "SELECT tagout_num from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(tagout_num) autolog.info(price_unit) autolog.info(unit) # 获取发盘量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodTagoutNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(tagout_num[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、发盘量验证正确") else: autolog.info("单位、发盘量错误") assert False, ("单位、发盘量错误") ''' test_8_mainTagoutNum 获取商品编号 查询数据库中发盘量、单位信息 与页面获取的发盘量作对比 ''' def test_9_1_mainStartNum(self): '''主要信息-起订量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) start_num = selectBySql( "SELECT start_num from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(start_num) autolog.info(price_unit) autolog.info(unit) # 获取起订量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodStartNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(start_num[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、起订量验证正确") else: autolog.info("单位、起订量错误") assert False, ("单位、起订量错误") ''' test_9_mainStartNum 获取商品编号 查询数据库中起订量、单位信息 与页面获取的起订量作对比 ''' def test_9_2_mainsurrplus(self): '''主要信息:剩余量''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 price_unit = getDicSql("price_unit", "price_unit", code) surrplus = selectBySql( "SELECT surplus from cenpur_mall_goods where code ='%s'" % code) unit = getUnit(price_unit[0]) autolog.info(surrplus) autolog.info(price_unit) autolog.info(unit) # 获取剩余量 eletext1 = self.driver.find_element( get_element("productDetail_page", "goodSurplusNum_text_loc")) text = eletext1.text autolog.info(text) # 判断 re1 = text.find(getNum(surrplus[0])) re2 = text.find(str(unit)) if re1 != -1 and re2 != -1: autolog.info("单位、剩余量验证正确") else: autolog.info("单位、剩余量错误") assert False, ("单位、剩余量错误") ''' test_10_mainsurrplus 获取商品编号 查询数据库中剩余量、单位信息 与页面获取的剩余量作对比 ''' def test_9_3_mainNumText(self): '''采购量输入框''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) # 查询数据库 start_num = selectBySql( "SELECT start_num from cenpur_mall_goods where code ='%s'" % code) surplus = selectBySql( "SELECT surplus from cenpur_mall_goods where code ='%s'" % code) autolog.info(start_num) autolog.info(surplus) #操作 #小于起订量 self.driver.send_keys( get_element("productDetail_page", "goodNum_textBox_loc"), str(int(getNum(start_num[0])) - 1)) self.driver.click( get_element("productDetail_page", "goodType_text_loc")) #点击失去焦点 eleStart = self.driver.find_element( get_element("productDetail_page", "goodNum_textBox_loc")) eleStart_num = int(eleStart.get_attribute("value")) #大于剩余量 self.driver.send_keys( get_element("productDetail_page", "goodNum_textBox_loc"), str(int(getNum(surplus[0])) + 1)) self.driver.click( get_element("productDetail_page", "goodType_text_loc")) # 点击失去焦点 eleSurplus = self.driver.find_element( get_element("productDetail_page", "goodNum_textBox_loc")) eleSurplus_num = int(eleSurplus.get_attribute("value")) assert eleStart_num >= int(start_num[0]) and eleSurplus_num <= int( surplus[0]), ("小于起订量或者大于剩余量") autolog.info("输入框验证正确") ''' test_11_mainBuyDown 通过商品编号,查询数据库中的起订量和剩余量 输入小于起订量和大于剩余量的数字 ''' def test_9_4_mainCollection(self): '''收藏商品''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #删除我的收藏 selectBySql("delete from cenpur_mall_favorites where user_id ='%s'" % userId) #获取class class1 = self.driver.get_attribute( get_element("productDetail_page", "goodCollection_button_loc"), "class") self.driver.click( get_element("productDetail_page", "goodCollection_button_loc")) class2 = self.driver.get_attribute( get_element("productDetail_page", "goodCollection_button_loc"), "class") #去我的收藏页验证 self.driver.open(get_url("favorite_page")) self.driver.refresh() eletext1 = self.driver.find_element( get_element("productDetail_page", "favoriteCode_text_loc")) autolog.info("我的收藏页%s" % eletext1.text) code1 = getCode(eletext1.text) autolog.info(code1) assert class1 == class2 and code == code1, ("商品未成功收藏") autolog.info("商品成功收藏") ''' test_12_mainCollection 点击收藏后,验证收藏标签的class是否变化 然后进入我的收藏页面,找到商品编号,看是否相同 ''' def test_9_5_shopImg(self): '''店铺图片''' src = self.driver.get_attribute( get_element("productDetail_page", "shop_img_loc"), "src") if src: self.driver.open(str(src)) assert self.driver.get_title() != "404 Not Found" autolog.info(src) autolog.info("店铺页面图片展示正常") else: autolog.info("无法获取src") assert False, ("获取src失败") ''' test_13_shopImg 商品图片的展示,看是否可以访问图片地址 ''' def test_9_6_shopPhone(self): '''店铺-电话展示''' # 获取商品编号 eletext = self.driver.find_element( get_element("productDetail_page", "goodCode_text_loc")) autolog.info("获取到:%s" % eletext.text) code = getCode(eletext.text) autolog.info(code) #获取联系方式 phone = selectBySql( "select phone from cenpur_mall_shop where id=(SELECT shop_id from cenpur_mall_goods where code='%s')" % code) autolog.info(phone) #获取页面信息判断 text = self.driver.text_in_element( get_element("productDetail_page", "shopPhone_text_loc"), str(phone[0])) if text: autolog.info("店铺电话号码正确") assert True else: autolog.info("店铺电话号码错误") assert False, ("店铺电话号码错误") ''' test_14_shopPhone 店铺号码展示 通过商品编号,查询对应的店铺信息 通过获取联系方式 与页面做对比 ''' def test_9_7_GOshop(self): '''进入店铺''' self.driver.click( get_element("productDetail_page", "goShop_button_loc")) time.sleep(2) url = self.driver.get_current_url() autolog.info("点击进入店铺后跳转页面为:%s" % url) self.assertIn("storeDetail", url, "未成功跳转店铺详情页面") ''' test_15_GOshop 进入店铺详情,对比url ''' def test_9_8_shopCollection(self): '''收藏店铺''' # 删除我的收藏 selectBySql("delete from cenpur_mall_favorites where user_id ='%s'" % userId) autolog.info("收藏店铺已删除") #收藏后进入我的收藏 self.driver.click( get_element("productDetail_page", "shopCollection_button_loc")) autolog.info("点击收藏店铺") self.driver.open(get_url("favorite_page")) time.sleep(2) self.driver.click( get_element("productDetail_page", "faveritePageShop_link_loc")) time.sleep(1) ele_displayed = self.driver.find_element( get_element("productDetail_page", "favoritePageShopName_text_loc")).is_displayed() autolog.info(ele_displayed) assert ele_displayed == True, ("收藏的店铺元素不存在") autolog.info("店铺收藏成功") ''' test_16_shopCollection 清空我的收藏 点击收藏店铺 进入我的收藏页面查找是否有收藏的店铺 ''' def tearDown(self): self.driver.close() autolog.info("tearDown")
class 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 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 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()
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 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()