def step_impl(context, user): products = json.loads(context.text) url2uploaded_url = {} for product in products: product_list_page = ProductListPage(context.driver) product_list_page.load() edit_product_page = product_list_page.click_add_product_button() edit_product_page.submit_product(product, url2uploaded_url)
def step_impl(context, user): product_list_page = ProductListPage(context.driver) product_list_page.load() actual = product_list_page.get_products() if hasattr(context, 'caller_step_text'): expected = json.loads(context.caller_step_text) delattr(context, 'caller_step_text') else: expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user, product_name): product_list_page = ProductListPage(context.driver) product_list_page.load() edit_product_page = product_list_page.enter_edit_product_page(product_name) actual = edit_product_page.get_product_content() expected = json.loads(context.text) bdd_util.assert_dict(expected, actual) if 'model' in expected: context.tc.assertEquals(len(expected['model']['models']), len(actual['model']['models']))
def not_test_04_product(self): login_page = LoginPage(self.driver) login_page.login('test1', 'test1') url2uploaded_url = {} product_list_page = ProductListPage(self.driver) product_list_page.load() #验证:商品列表为空 products = product_list_page.get_products() self.assertEquals(0, len(products)) #期望商品 expected_products = [{ 'name': u'东坡肘子', 'category': u'新分类1', 'physical_unit': u'包', 'price': '11.0', 'weight': '5', 'thumbnails_url': './test/imgs/hangzhou1.jpg', 'pic_url': './test/imgs/hangzhou1.jpg', 'introduction': u'东坡肘子的简介', 'detail': u'东坡肘子的详情' }, { 'name': u'叫花鸡', 'category': u'新分类1', 'physical_unit': u'盘', 'price': '12.0', 'weight': '5', 'thumbnails_url': './test/imgs/hangzhou2.jpg', 'pic_url': './test/imgs/hangzhou2.jpg', 'introduction': u'叫花鸡的简介', 'detail': u'叫花鸡的详情' }, { 'name': u'黄桥烧饼', 'category': u'分类3', 'physical_unit': u'个', 'price': '3.0', 'weight': '5', 'thumbnails_url': './test/imgs/mian1.jpg', 'pic_url': './test/imgs/mian1.jpg', 'introduction': u'黄桥烧饼的简介', 'detail': u'黄桥烧饼的详情' }, { 'name': u'武昌鱼', 'category': u'', 'physical_unit': u'条', 'price': '23.0', 'weight': '5', 'thumbnails_url': './test/imgs/yu1.jpg', 'pic_url': './test/imgs/yu1.jpg', 'introduction': u'武昌鱼的简介', 'detail': u'武昌鱼的详情' }, { 'name': u'西湖醋鱼', 'category': u'', 'physical_unit': u'条', 'price': '24.0', 'weight': '5', 'thumbnails_url': './test/imgs/yu2.jpg', 'pic_url': './test/imgs/yu2.jpg', 'introduction': u'西湖醋鱼的简介', 'detail': u'西湖醋鱼的详情' }] ''' 添加商品: ''' #验证:提交时的默认错误提示 edit_product_page = product_list_page.click_add_product_button() edit_product_page.submit_product({}, url2uploaded_url) error_hints = edit_product_page.get_error_hints() self.assertEquals(7, len(error_hints)) self.assertEquals(u'内容不能为空', error_hints[0]) self.assertEquals(u'内容不能为空', error_hints[1]) self.assertEquals(u"价格不正确,请输入0-99999之间的价格", error_hints[2]) self.assertEquals(u'内容不能为空', error_hints[3]) self.assertEquals(u"格式不正确,请输入'3.14'或'5'这样的数字", error_hints[4]) self.assertEquals(u"请选择一张图片", error_hints[5]) self.assertEquals(u"请选择一张图片", error_hints[6]) #添加5个商品 edit_product_page.submit_product(expected_products[0], url2uploaded_url) for product in expected_products[1:]: edit_product_page = product_list_page.click_add_product_button() edit_product_page.submit_product(product, url2uploaded_url) #验证:商品列表为[东坡肘子, 叫花鸡,黄桥烧饼,武昌鱼,西湖醋鱼] products = product_list_page.get_products() self.assertEquals(5, len(products)) for i in range(5): #验证倒序排列 self.__assert_product(expected_products[4 - i], products[i], url2uploaded_url) ''' 更新商品“叫花鸡”为“龙井虾仁” ''' expected_products[1] = { 'name': u'龙井虾仁', 'category': u'分类3', 'physical_unit': u'盘', 'price': '9.0', 'weight': '5', 'thumbnails_url': './test/imgs/hangzhou3.jpg', 'pic_url': './test/imgs/hangzhou3.jpg', 'introduction': u'龙井虾仁的简介', 'detail': u'龙井虾仁的详情' } edit_product_page = product_list_page.enter_edit_product_page(u'叫花鸡') edit_product_page.update_product(expected_products[1], url2uploaded_url) #验证:商品列表为[东坡肘子, 龙井虾仁,黄桥烧饼,武昌鱼,西湖醋鱼] products = product_list_page.get_products() self.assertEquals(5, len(products)) for i in range(5): #验证倒序排列 self.__assert_product(expected_products[4 - i], products[i], url2uploaded_url) time.sleep(1) ''' 分类浏览 ''' #验证:新分类1 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') category_products = edit_category_page.get_category_products() self.assertEquals(3, len(category_products)) self.assert_dict({ 'name': u'东坡肘子', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': False }, category_products[1]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[2]) #验证:分类3 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') category_products = edit_category_page.get_category_products() self.assertEquals(4, len(category_products)) self.assert_dict({ 'name': u'龙井虾仁', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'黄桥烧饼', 'is_selected': True }, category_products[1]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': False }, category_products[2]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[3]) #分类1中,选中“武昌鱼” category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') edit_category_page.select_products([u'武昌鱼']) edit_category_page.submit() #验证:新分类1 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') category_products = edit_category_page.get_category_products() self.assertEquals(3, len(category_products)) self.assert_dict({ 'name': u'东坡肘子', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': True }, category_products[1]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[2]) #验证:分类3 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') category_products = edit_category_page.get_category_products() self.assertEquals(3, len(category_products)) self.assert_dict({ 'name': u'龙井虾仁', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'黄桥烧饼', 'is_selected': True }, category_products[1]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[2]) #分类3中,选中“西湖醋鱼” category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') edit_category_page.select_products([u'西湖醋鱼']) edit_category_page.submit() #验证:新分类1 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') category_products = edit_category_page.get_category_products() self.assertEquals(2, len(category_products)) self.assert_dict({ 'name': u'东坡肘子', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': True }, category_products[1]) #验证:分类3 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') category_products = edit_category_page.get_category_products() self.assertEquals(3, len(category_products)) self.assert_dict({ 'name': u'龙井虾仁', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'黄桥烧饼', 'is_selected': True }, category_products[1]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': True }, category_products[2]) #新分类1中,取消选中“武昌鱼”;分类3中,取消选中“西湖醋鱼” category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') edit_category_page.unselect_products([u'武昌鱼']) edit_category_page.submit() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') edit_category_page.unselect_products([u'西湖醋鱼']) edit_category_page.submit() #验证:新分类1 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') category_products = edit_category_page.get_category_products() self.assertEquals(3, len(category_products)) self.assert_dict({ 'name': u'东坡肘子', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': False }, category_products[1]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[2]) #验证:分类3 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') category_products = edit_category_page.get_category_products() self.assertEquals(4, len(category_products)) self.assert_dict({ 'name': u'龙井虾仁', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'黄桥烧饼', 'is_selected': True }, category_products[1]) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': False }, category_products[2]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': False }, category_products[3]) #添加“分类4” category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.click_add_category_button() edit_category_page.add_category(u'分类4', [u'武昌鱼', u'西湖醋鱼']) edit_category_page.submit() #验证:新分类1 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'新分类1') category_products = edit_category_page.get_category_products() self.assertEquals(1, len(category_products)) self.assert_dict({ 'name': u'东坡肘子', 'is_selected': True }, category_products[0]) #验证:分类3 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类3') category_products = edit_category_page.get_category_products() self.assertEquals(2, len(category_products)) self.assert_dict({ 'name': u'龙井虾仁', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'黄桥烧饼', 'is_selected': True }, category_products[1]) #验证:分类4 category_list_page = CategoryListPage(self.driver) category_list_page.load() edit_category_page = category_list_page.enter_category_edit_page( u'分类4') category_products = edit_category_page.get_category_products() self.assertEquals(2, len(category_products)) self.assert_dict({ 'name': u'武昌鱼', 'is_selected': True }, category_products[0]) self.assert_dict({ 'name': u'西湖醋鱼', 'is_selected': True }, category_products[1]) ''' 删除商品 ''' product_list_page = ProductListPage(self.driver) product_list_page.load() edit_product_page = product_list_page.enter_edit_product_page(u'龙井虾仁') edit_product_page.delete() expected_products[3]['category'] = u'分类4' #更新'武昌鱼'的分类 expected_products[4]['category'] = u'分类4' #更新'西湖醋鱼'的分类 expected_products.remove(expected_products[1]) #删除"龙井虾仁" #验证:商品列表为[东坡肘子, 黄桥烧饼,武昌鱼,西湖醋鱼] product_list_page = ProductListPage(self.driver) product_list_page.load() products = product_list_page.get_products() self.assertEquals(4, len(products)) for i in range(4): #验证倒序排列 self.__assert_product(expected_products[3 - i], products[i], url2uploaded_url)
def step_impl(context, user, product_name): product_list_page = ProductListPage(context.driver) product_list_page.load() edit_product_page = product_list_page.enter_edit_product_page(product_name) edit_product_page.delete()
def step_impl(context, user, product_name): product = json.loads(context.text) product_list_page = ProductListPage(context.driver) product_list_page.load() edit_product_page = product_list_page.enter_edit_product_page(product_name) edit_product_page.update_product(product)
def step_impl(context, user, product_name): product_list_page = ProductListPage(context.driver) product_list_page.load() product_list_page.set_product_to_top(product_name) context.driver.refresh()
def step_impl(context, user, direction, product_name): product_list_page = ProductListPage(context.driver) product_list_page.load() product_list_page.sort_product(product_name, direction) context.driver.refresh()