def Delete_product_classification(self, case): """删除分类""" try: get_class_no = self.get_div_number(product='燃气灶') if case == 1: # 删除一级分类 self.browser.find_element_by_xpath( One_Delete_Button % format(get_class_no)).click() self.browser.find_element_by_xpath(Delete_Ensure).click() Wait_Find(self.browser, (By.XPATH, Prompt_Message)) logger_message.loginfo( self.browser.find_element_by_xpath(Prompt_Message).text) elif case == 2: # 删除二级分类 self.browser.find_element_by_xpath(Unfold_Button).click() Wait_Find(self.browser, (By.XPATH, Two_Delete_Button % format(get_class_no))) self.browser.find_element_by_xpath( Two_Delete_Button % format(get_class_no)).click() self.browser.find_element_by_xpath(Delete_Ensure).click() Wait_Find(self.browser, (By.XPATH, Prompt_Message)) self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '删除成功', msg='删除成功失败!') except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Required_fields_check(self, case): u"""新增商品分类必填项检查""" try: Wait_Find(self.browser, (By.XPATH, Add_Button)) self.browser.find_element_by_xpath(Add_Button).click() if case == 1: # 全部不输点击确定 self.browser.find_element_by_xpath(Ok_Button).click() self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '请输入分类名称', msg='请输入分类名称错误!') elif case == 2: # 输入分类名称不上传照片 self.browser.find_element_by_xpath(Class_Name).send_keys('燃气灶') self.browser.find_element_by_xpath(Ok_Button).click() self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '请上传分类图片', msg='请上传分类图片错误!') elif case == 3: # 上传照片但不输入分类名称 self.browser.find_element_by_xpath(Category_Images).send_keys( Image_Path) Wait_Find(self.browser, (By.XPATH, Prompt_Message)) self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '上传成功', msg='图片上传失败') self.browser.find_element_by_xpath(Ok_Button).click() self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '请输入分类名称', msg='请输入分类名称错误!') elif case == 4: # 输入分类名称字符过长 self.browser.find_element_by_xpath(Class_Name).send_keys( '测试下商品分类问题字符长度问题') self.browser.find_element_by_xpath(Ok_Button).click() self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '分类名称最大长度为4', msg='分类名称最大长度为4错误!') elif case == 5: # 检查图片删除二次上传是否正确 self.browser.find_element_by_xpath(Category_Images).send_keys( Image_Path) Wait_Find(self.browser, (By.XPATH, First_Image)) self.browser.find_element_by_xpath(First_Image).click() self.browser.find_element_by_xpath(Image_Delete).click() self.browser.find_element_by_xpath(Category_Images).send_keys( Image_Path) Wait_Find(self.browser, (By.XPATH, Image_Delete)) self.browser.find_element_by_xpath(Image_Delete).click() except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Add_product_information(self): """添加商品基本信息""" try: Wait_Click(self.browser, Product_Information_path().Add_Product) Wait_Click(self.browser, Add_product_information_path().goods_category) Wait_Click(self.browser, Add_product_information_path().one_category) Wait_Click(self.browser, Add_product_information_path().two_category) Send_Key(self.browser, Add_product_information_path().goods_title, "苏泊尔(SUPOR)QS505燃气灶") Send_Key(self.browser, Add_product_information_path().goods_number, "QS505") Send_Key(self.browser, Add_product_information_path().subhead, "苏泊尔(SUPOR)QS505燃气灶") Wait_Click(self.browser, Add_product_information_path().logistics) Wait_Click( self.browser, Add_product_information_path().logistics_status % format(1)) time.sleep(0.5) Wait_Click(self.browser, Add_product_information_path().product_label) Wait_Click(self.browser, Add_product_information_path().label_no % format(2)) Send_Key(self.browser, Add_product_information_path().remark, "自动创建商品") Send_Picture( self.browser, Add_product_information_path().product_carousel, Add_product_information_path().carousel_product % format(1)) Wait_Find(self.browser, (By.XPATH, Product_Information_path().Prompt_Message)) Send_Picture( self.browser, Add_product_information_path().product_details, Add_product_information_path().carousel_product % format(2)) Wait_Find(self.browser, ( By.XPATH, "/html/body/div[4]/div[2]/div/div/div[2]/div/div[2]/div[1]/form/div/div[12]/div/div/div/div[1]/img" )) self.browser.find_element_by_xpath( Add_product_information_path().save_button).click() time.sleep(3) except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Operation_Center(self, Number=31): u"""云商城菜单""" try: xpath = '//*[@id="app"]/div/div[2]/div/div[1]/div[1]/div[2]/ul/li[1]' # 先选择第一个菜单进行定位,为后续的键盘操作定位元素 Wait_Find(self.browser, (By.XPATH, xpath)) self.browser.find_element_by_xpath(xpath).click() time.sleep(1) ActionChains(self.browser).send_keys(Keys.PAGE_DOWN).perform() # 使用ActionChains未选取元素进行键盘操作 Operation_Center_xpath = '//*[@id="app"]/div/div[2]/div/div[1]/div[1]/div[2]/ul/li[%s]' % Number Wait_Find(self.browser, (By.XPATH, Operation_Center_xpath)) self.browser.find_element_by_xpath(Operation_Center_xpath).click() except Exception as Operation_Center_Error: logger_message.logwarning(u"%s\t方法名:%s\t云商城菜单异常%s" % (send_time, sys._getframe().f_code.co_name, Operation_Center_Error)) raise
def Add_two_product_classification(self): """新增二级商品分类""" try: get_class_no = self.get_div_number(product='燃气灶') self.browser.find_element_by_xpath(subclass_path % format(get_class_no)).click() self.browser.implicitly_wait(5) self.browser.find_element_by_xpath(Class_Name).send_keys('燃气灶') self.browser.find_element_by_xpath(Category_Images).send_keys( Image_Path) # time.sleep(2) Wait_Find(self.browser, (By.XPATH, Prompt_Message)) self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '上传成功', msg='图片上传失败') # time.sleep(2) self.browser.find_element_by_xpath(Ok_Button).click() try: self.browser.find_element_by_xpath(Cancel_Button).click() time.sleep(1) except NoSuchElementException: pass logger_message.loginfo('二级分类创建成功!') except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Add_product_stock(self, sales, cost, market, integral, stock): u"""添加商品库存""" try: Wait_Click(self.browser, Add_product_stock_path().product_stock_menu) Wait_Click(self.browser, Add_product_stock_path().add_stock) Wait_Click(self.browser, Add_product_stock_path().product_specification) Wait_Click( self.browser, Add_product_stock_path().specification_value % format(1)) Send_Key(self.browser, Add_product_stock_path().sales_price, sales) Send_Key(self.browser, Add_product_stock_path().cost_price, cost) Send_Key(self.browser, Add_product_stock_path().market_price, market) Send_Picture(self.browser, Add_product_stock_path().product_images, Add_product_stock_path().carousel_product % format(1)) Wait_Find(self.browser, (By.XPATH, Product_Information_path().Prompt_Message)) Wait_Click(self.browser, Add_product_stock_path().product_status % format(1)) Send_Key(self.browser, Add_product_stock_path().integral, integral) Send_Key(self.browser, Add_product_stock_path().stock, stock) Wait_Click(self.browser, Add_product_stock_path().save_button) Wait_Click(self.browser, Product_Information_path().Quit) except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Add_product_specification(self, name, value1, value2): u"""添加商品规格""" try: Wait_Click( self.browser, Add_product_specification_path().goods_specification_menu) time.sleep(0.5) Wait_Click(self.browser, Add_product_specification_path().add_specification) Send_Key(self.browser, Add_product_specification_path().specification_name, name) Send_Key( self.browser, Add_product_specification_path().specification_value % format(1), value1) Wait_Click( self.browser, Add_product_specification_path().add_specification_value) Send_Key( self.browser, Add_product_specification_path().specification_value % format(2), value2) Wait_Click(self.browser, Add_product_specification_path().ensure_button) Wait_Find(self.browser, (By.XPATH, Add_product_stock_path().product_stock_menu)) except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Add_one_product_classification(self): u"""新增一级商品分类""" try: get_class_no = self.get_div_number(product="燃气灶") if get_class_no >= 1: logger_message.loginfo('分类已存在!') except NoSuchElementException: Wait_Find(self.browser, (By.XPATH, Add_Button)) self.browser.find_element_by_xpath(Add_Button).click() self.browser.find_element_by_xpath(Class_Name).send_keys('燃气灶') self.browser.find_element_by_xpath(Category_Images).send_keys( Image_Path) Wait_Find(self.browser, (By.XPATH, Prompt_Message)) self.assertEqual( self.browser.find_element_by_xpath(Prompt_Message).text, '上传成功', msg='图片上传失败') self.browser.find_element_by_xpath(Ok_Button).click() logger_message.loginfo('分类创建成功!')
def Add_product_parameters(self, name, value): u"""添加商品参数""" try: Wait_Find(self.browser, (By.XPATH, Add_product_parameters_path().parameter_name)) self.browser.find_element_by_xpath( Add_product_parameters_path().parameter_name).send_keys(name) self.browser.find_element_by_xpath( Add_product_parameters_path().parameter_value).send_keys(value) Wait_Click(self.browser, Add_product_parameters_path().save_button) Wait_Find( self.browser, (By.XPATH, Add_product_specification_path().goods_specification_menu)) except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def Fixed_Window(self): u"""窗口固定按钮""" try: Fixed_Window_Xpath = '//*[@id="app"]/div/div[2]/div/div[2]/div[2]/div/div[1]/div[1]/div/h3/p' Wait_Find(self.browser, (By.XPATH, Fixed_Window_Xpath)) self.browser.find_element_by_xpath(Fixed_Window_Xpath).click() except Exception as Fixed_Window_error: logger_message.logwarning( u"%s\t方法名:%s\t窗口固定按钮-异常:%s" % (send_time, sys._getframe().f_code.co_name, Fixed_Window_error)) raise
def Selection_Menu(self, Menu_path): u"""选择菜单""" try: Wait_Find(self.browser, (By.XPATH, Menu_path)) self.browser.find_element_by_xpath(Menu_path).click() time.sleep(0.5) except Exception as Error: logger_message.logwarning( u"%s\t方法名:%s\t菜单异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise
def get_div_number(self, product): Wait_Find(self.browser, (By.XPATH, Add_Button)) for i in range(10): number = i + 1 class_number = '//*[@id="userManage"]/div/div/div/div[2]/div[2]/div[%s]/div[1]/span[1]' % number self.browser.implicitly_wait(5) number_text = self.browser.find_element_by_xpath(class_number).text if number_text == '分类名称:%s' % product: return int(number) else: # print('未找到元素') continue time.sleep(0.5)
def add_home_tag(self, name, sort, status, tag_type, image): u"""添加首页标签""" try: Wait_Click(self.browser, Home_Tag_Path().add_tag_button) Send_Key(self.browser, Home_Tag_Path().tag_name, name) Wait_Click(self.browser, Home_Tag_Path().tag_sort) Send_Key(self.browser, Home_Tag_Path().tag_sort, sort) Wait_Click(self.browser, Home_Tag_Path().tag_status) Wait_Click(self.browser, Home_Tag_Path().status % status) Wait_Click(self.browser, Home_Tag_Path().tag_type) Wait_Click(self.browser, Home_Tag_Path().type % tag_type) Send_Picture(self.browser, Home_Tag_Path().tag_photo, Add_product_information_path().carousel_product % format(image)) Wait_Find(self.browser, (By.XPATH, Home_Tag_Path().update_photo)) Wait_Click(self.browser, Home_Tag_Path().save_button) except Exception as Error: logger_message.logwarning(u"%s\t方法名:%s\t异常%s" % (send_time, sys._getframe().f_code.co_name, Error)) raise