Example #1
0
    def add_customer(self, xpath='//*[@id="home"]/div[3]/div[2]/a[2]'):
        try:
            WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_xpath(xpath))
            self.driver.find_element_by_xpath(xpath).click()    # 进入新增客户页面

            # 填写客户名、联系人、手机号
            types = ['小店', '副食', '酒楼', '批发', '烟酒', '便利店', '小卖部', '超市', '百货']
            customer_name = create_name() + types[random.randint(0,len(types)-1)]
            self.driver.find_element_by_id('customer_name').send_keys(customer_name)
            self.driver.find_element_by_id('contact').send_keys(create_name())
            self.driver.find_element_by_id('mobile').send_keys(create_phone())

            # 选择客户类型
            self.driver.find_element_by_id('default_customer_type').click()
            typelist = ['零售终端', '批发', '餐饮', '其他', '商超']
            types = self.driver.find_elements_by_xpath('/html/body/div[6]/div/div[2]/label')
            while True:
                t = int(random.randint(0, len(types)-1))
                if types[t].text in typelist:
                    # format_print(t, ' ', types[t].text)   # 取到的客户类型
                    types[t].click()
                    break

            # 选择客户等级
            self.driver.find_element_by_id('subType').click()
            self.driver.find_element_by_xpath('/html/body/div[6]/div/div[2]/label[1]').click()

            # 选择配送地址
            self.driver.find_element_by_id('delivery-address').click()
            self.swich_webview(Setup.context)    # 切换到APP视图做swipe操作,滑动选择省市区
            width = self.driver.get_window_size().get('width')  # 获取屏幕宽度
            height = self.driver.get_window_size().get('height')    # 获取屏幕高度
            self.driver.swipe(width*0.25, height*0.9, width*0.25, height*0.1)   # 滑动
            self.driver.swipe(width*0.9, height*0.9, width*0.9, height*0.7)

            self.swich_webview(Setup.h5_context)  # 切换到H5视图继续后面的操作
            self.driver.find_element_by_xpath('//a[text()="完成"]').click()
            self.driver.find_element_by_id('address').send_keys(create_gbk(8))

            # 如果键盘弹出就关闭键盘
            # if self.driver.is_keyboard_shown():
            #     self.driver.hide_keyboard()

            self.driver.find_element_by_id('add').click()
            self.driver.find_element_by_xpath('//a[text()="确定"]').click()

        except Exception as e:
            format_print('新增客户失败 ', e)
            self.take_screenshot('新增客户失败')
            sys.exit(0)
Example #2
0
    def feast_activity(self, flag=True):
        """宴席推广活动"""

        # 进入宴席推广活动
        self.choose_activity_type(2)
        logging.info('========== feast_activity ==========')

        # 如果出现草稿箱已满的提示,点取消
        # self.drafts_box()

        # 选择宴席类型
        WebDriverWait(
            self.driver,
            10).until(lambda x: x.find_element_by_id(self.banquet_type_id))
        self.driver.find_element_by_id(self.banquet_type_id).click()
        sleep(0.5)
        banquets = self.driver.find_elements_by_class_name(
            self.check_label_class)
        # banquets[random.randint(0, len(banquets) - 1)].click()
        random.choice(banquets).click()
        sleep(1)

        # 选择活动
        self.choose_act()

        # 选择费用明细
        self.choose_expense()

        # 联系人
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())

        # 电话
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())

        # 地址
        self.driver.find_element_by_id(self.address_id).send_keys(
            create_gbk(6))

        # 桌数
        self.driver.find_element_by_id(self.people_id).send_keys(
            random.randint(1, 3))

        # 赠送数量
        self.apply_num()

        # 赠送金额
        self.apply_amount()

        # 随机拍1-5张照
        self.take_photo(flag)

        # 提交
        self.submit()

        # 再次确认
        self.reconfirm()
Example #3
0
    def cultivate_activity(self, flag=True):
        """消费培育活动"""

        # 选择消费培育活动
        self.choose_activity_type(0)
        logging.info('========== cultivate_activity ==========')

        # 如果出现草稿箱已满的提示,点取消
        # self.drafts_box()

        # 选择活动
        self.choose_act()

        # 选择费用明细
        self.choose_expense()

        # 培育对象名称
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())

        # 培育对象电话
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())

        # 培育地点
        self.driver.find_element_by_id(self.address_id).send_keys(
            create_gbk(6))

        # 品鉴人数
        self.driver.find_element_by_id(self.people_id).send_keys(
            random.randint(1, 3))

        # 赠送数量
        self.apply_num()

        # 赠送金额
        self.apply_amount()

        # 随机拍1-5张照
        self.take_photo(flag)

        # 提交
        self.submit()

        # 再次确认
        self.reconfirm()
Example #4
0
    def cultivate_activity_supplement(self, flag=True):
        """消费培育活动-补录"""

        # 选择消费培育活动
        self.choose_activity_supplement_type(0)
        logging.info('========== cultivate_activity_supplement ==========')

        # 选择活动
        self.choose_act()

        # 选择费用明细
        self.choose_expense()

        # 培育对象名称
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())

        # 培育对象电话
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())

        # 培育地点
        self.driver.find_element_by_id(self.address_id).send_keys(
            create_gbk(6))

        # 品鉴人数
        self.driver.find_element_by_id(self.people_id).send_keys(
            random.randint(1, 3))

        # 赠送数量
        self.apply_num()

        # 赠送金额
        self.apply_amount()

        # 上传照片
        self.upload_photo(flag)

        # 提交
        self.submit()

        # 再次确认
        self.reconfirm()
        sleep(2)
Example #5
0
    def groupon_activity(self, flag=True):
        """团购直销活动"""

        # 进入团购直销活动
        self.choose_activity_type(1)
        logging.info('========== groupon_activity ==========')

        # 如果出现草稿箱已满的提示,点取消
        # self.drafts_box()

        # 选择活动
        self.choose_act()

        # 选择费用明细
        self.choose_expense()

        # 团购单位名称
        self.driver.find_element_by_id(self.company_name_id).send_keys(
            create_gbk(5))

        # 单位负责人
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())

        # 联系电话
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())

        # 赠送数量
        self.apply_num()

        # 赠送金额
        self.apply_amount()

        # 随机拍1-5张照
        self.take_photo(flag)

        # 提交
        self.submit()

        # 再次确认
        self.reconfirm()
Example #6
0
    def groupon_activity_supplement(self, flag=True):
        """团购直销活动-补录"""

        # 进入团购直销活动
        self.choose_activity_supplement_type(1)
        logging.info('========== groupon_activity_supplement ==========')

        # 选择活动
        self.choose_act()

        # 选择费用明细
        self.choose_expense()

        # 团购单位名称
        self.driver.find_element_by_id(self.company_name_id).send_keys(
            create_gbk(5))

        # 单位负责人
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())

        # 联系电话
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())

        # 赠送数量
        self.apply_num()

        # 赠送金额
        self.apply_amount()

        # 上传照片
        self.upload_photo(flag)

        # 提交
        self.submit()

        # 再次确认
        self.reconfirm()
        sleep(2)
Example #7
0
    def add_customer(self, photo=True):
        """新增客户"""

        logging.info('========== add_customer ==========')

        WebDriverWait(self.driver, 20).until(
            lambda x: x.find_element_by_xpath(self.addcustomer_entrance))
        self.driver.find_element_by_xpath(
            self.addcustomer_entrance).click()  # 进入新增客户页面
        sleep(0.5)

        # 填写客户名、联系人、手机号
        kinds = ['小店', '副食', '酒楼', '批发', '烟酒', '便利店', '小卖部', '超市', '百货']
        customer_name = create_name() + random.choice(kinds)
        self.driver.find_element_by_id(
            self.customer_name_id).send_keys(customer_name)
        sleep(0.5)
        self.driver.find_element_by_id(self.contact_id).send_keys(
            create_name())
        sleep(0.5)
        self.driver.find_element_by_id(self.mobile_id).send_keys(
            create_phone())
        sleep(0.5)

        # 选择客户类型
        self.driver.find_element_by_id(self.customer_type_id).click()
        typelist = ['零售终端', '批发', '餐饮', '其他', '商超']
        types = self.driver.find_elements_by_class_name(self.check_label)
        while True:
            # t = int(random.randint(0, len(types)-1))
            t = random.choice(types)
            if t.text in typelist:
                t.click()
                break
        sleep(0.5)

        # 选择客户等级
        self.driver.find_element_by_id(self.sub_type_id).click()
        sleep(0.5)
        sub_types = self.driver.find_elements_by_class_name(self.check_label)
        # sub_types[random.randint(0, len(sub_types)-1)].click()
        random.choice(sub_types).click()
        sleep(0.5)

        # 选择配送地址
        self.driver.find_element_by_id(self.province_id).click()
        self.swich_webview(self.context)  # 切换到APP视图做swipe操作,滑动选择省市区
        width = self.driver.get_window_size().get('width')  # 获取屏幕宽度
        height = self.driver.get_window_size().get('height')  # 获取屏幕高度
        self.driver.swipe(width * 0.25, height * 0.9, width * 0.25,
                          height * 0.1)  # 滑动
        self.driver.swipe(width * 0.9, height * 0.9, width * 0.9, height * 0.7)

        self.swich_webview(self.h5_context)  # 切换到H5视图继续后面的操作
        self.driver.find_element_by_xpath(self.province_confirm).click()
        self.driver.find_element_by_id(self.address_id).send_keys(
            create_gbk(8))

        if photo:
            for _ in range(random.randint(1, 3)):
                self.driver.find_element_by_id(self.upload_id).click()

                self.swich_webview(self.context)  # 切换到微信视图控制相机拍照
                # self.driver.find_element_by_id(self.shutter_button_id).click() # Meizu MX3
                # self.driver.find_element_by_id(self.done_button_id).click() # Meizu MX3
                self.driver.find_element_by_id(
                    self.shutter_button_id).click()  # Vivo x9 拍照
                self.driver.find_element_by_id(
                    self.done_button_id).click()  # Vivo x9 确定
                sleep(3)  # 等待图片上传完成

                self.driver.switch_to.context(self.h5_context)  # 切换到H5视图继续操作

        # 如果键盘弹出就关闭键盘
        # if self.driver.is_keyboard_shown():
        #     self.driver.hide_keyboard()

        self.driver.find_element_by_id(self.add_id).click()
        sleep(0.5)
        self.driver.find_element_by_xpath(self.addcustomer_confirm).click()
        sleep(3)
Example #8
0
    def take_group_purchase(self):
        try:
            # 进入团购直销活动
            act_kinds = self.driver.find_elements_by_tag_name('input')
            act_kinds[1].click()
            sleep(3)

            # 选择活动
            self.driver.find_element_by_id('activity_title').click()
            acts = self.driver.find_elements_by_tag_name('label')
            acts[random.randint(0, len(acts)-1)].click()
            sleep(1)

            # 选择费用明细
            self.driver.find_element_by_id('expenses_ids').click()
            expenses = self.driver.find_elements_by_tag_name('label')
            expenses[random.randint(0, len(expenses)-1)].click()
            self.driver.find_element_by_xpath('//a[text()="确定"]').click()
            sleep(1)

            # 团购单位名称
            self.driver.find_element_by_id('companyName').send_keys(create_gbk(5))

            # 单位负责人
            self.driver.find_element_by_id('customerNames').send_keys(create_name())

            # 联系电话
            self.driver.find_element_by_id('customerMobile').send_keys(create_phone())

            # 赠送数量
            self.driver.find_element_by_id('apply_num').clear().send_keys(random.randint(1, 3))

            # 赠送金额
            if self.is_element_exist('apply_amount', 'id'):
                if self.driver.find_element_by_id('apply_amount').is_displayed():
                    amount_list = [0, 10, 20, 50, 100]
                    available_amount = self.driver.find_element_by_id('ableMoney').text[1:-1]  # 赠送金额剩余数字
                    while True:
                        amount = random.sample(amount_list, 1)[0]  # 从列表中随机选择一个元素
                        if amount <= int(available_amount):
                            self.driver.find_element_by_id('apply_amount').clear().send_keys(amount)
                            break

            # 随机拍1-5张照
            for i in range(random.randint(1, 5)):
                self.driver.find_element_by_class_name('picture1BtnId').click()
                # self.driver.find_element_by_xpath('//*[@id="form"]/div/section/div[2]/div/div/div/div/div').click()

                self.swich_webview(Setup.context)  # 切换到微信视图控制相机拍照
                self.driver.find_element_by_id('com.android.camera:id/shutter_button').click()  # Vivo x9 拍照
                self.driver.find_element_by_id('com.android.camera:id/done_button').click()  # Vivo x9 确定
                sleep(600)  # 等待图片上传完成

                self.driver.switch_to.context(Setup.h5_context)  # 切换到H5视图继续操作

            WebDriverWait(self.driver, 20).until(
                lambda x: x.find_element_by_xpath('//button[contains(text(),"提交")]'))
            self.driver.find_element_by_xpath('//button[contains(text(),"提交")]').click()

            WebDriverWait(self.driver, 10).until(
                lambda x: x.find_element_by_xpath('//a[contains(text(),"确定")]'))
            self.driver.find_element_by_xpath('//a[contains(text(),"确定")]').click()
            sleep(1)

        except Exception as e:
            format_print('拍照出现异常 ', e)
            self.take_screenshot('拍照异常')