Example #1
0
class SinaPhotoAlbum(object):
    '''
    相册
    '''
    def __init__(self,driver):
        self.gl = GetByLocator(driver)

    def choose_photo_album(self):
        '''
        相册下拉
        :return:
        '''
        return self.gl.get_locator('sina_photo_album','photoAlbum')

    def choose_pic(self):
        '''
        pic相册
        :return:
        '''
        return self.gl.get_locator('sina_photo_album','pic')

    def choose_pics(self):
        '''
        选择多张照片
        :return:
        '''
        return self.gl.get_locators('sina_photo_album','choose_pics')

    def next(self):
        '''
        下一步
        :return:
        '''
        return self.gl.get_locator('sina_photo_album','next')
Example #2
0
class Driver(object):
    def __init__(self):
        self.driver = self.get_driver()

    def get_driver(self):
        capabilities = {
            "platformName": "Android",
            # "resetKeyboard":"true",
            "unicodeKeyboard": 'true',
            "deviceName": "3XU9X17324W10646",
            "noReset": 'true',
            # "platformVersion": "6.0",            # OPPO-a73也可正常运行,所以不需要这个版本号
            "appPackage": "com.haidilao",
            "appActivity":
            "com.haidilao.hailehui.biz.ActivityWelcome"  # appium1.7版本之后就应该不需要改配置了
        }
        # 对应的cmd中需先执行:appium -p 4723 -bp 4724 -U 3XU9X17324W10646
        driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities)
        sleep(8)
        # 登录后进入发布界面
        return driver

    def game_1(self):
        '''
        自动玩捞菜游戏
        :param driver:
        :param title:
        :param content:
        :return:
        '''
        self.gl = GetByLocator(self.driver)  # 注意这里不要放入init,会导致重复执行
        self.gl.get_locator('haidi_home', 'game').click()
        sleep(5)
        self.gl.get_locator(
            'haidi_home',
            'game1').click()  #这里虽是进h5,但是只要等待足够时间,就可以点击成功,不需要切换activity

    def circl_send(self):
        '''
        根据excel中数据行数,循环发帖
        :return:
        '''
        driver = self.get_driver()
        line = self.oe.excel_get_lines()
        j = 0
        for i in range(1, line):
            if j < 10:  # 限制数目
                title = self.oe.excel_get_cell(i, 0)
                conte = self.oe.excel_get_cell(i, 1)
                run = self.oe.excel_get_cell(i, 3)
                if run == 'Y':
                    self.send_new(driver, title, conte)
                    j = +1
Example #3
0
class AlwinKeyWord(object):

    def __init__(self,driver):
        self.gb = GetByLocator(driver)

    def alwin_click(self,*args):
        '''
        重新封装appium中的click为excel中的关键字对应
        示例args[0],args[1]对应:partition,key
        :return:
        '''
        self.gb.get_locator(args[0],args[1]).click()

    def alwin_click_all(self,*args):
        '''
        重新封装sappium中的clicks为excel中的关键字对应
        默认点击所有识别对象
        示例args[0],args[1]对应:partition,key
        :return:
        '''
        elements = self.gb.get_locators(args[0],args[1])
        for i in elements:
            i.click()

    def alwin_input(self,*args):
        '''
        重新封装appium中的click为excel中的关键字对应
        示例args[0],args[1],args[2]对应:partition,key,input_content
        :return:
        '''
        self.gb.get_locator(args[0],args[1]).send_keys(args[2])

    def alwin_sleep(self,time_sleep):
        '''
        重新封装休眠时间
        :return:
        '''
        time.sleep(time_sleep)

    def get_element(self,*args):
        '''
        封装期望关键字
        示例args[0],args[1]对应:partition,key
        :return:
        '''
        return self.gb.get_locator(args[0],args[1])
Example #4
0
class SinaHome(object):
    '''
    新浪首页元素封装
    '''
    def __init__(self, driver):
        self.driver = driver
        self.gl = GetByLocator(self.driver)

    def increate(self):
        '''
        新增元素封装
        :return:
        '''
        return self.gl.get_locator('sina_home', 'increase')

    def chapter(self):
        '''
        文章元素封装
        :return:
        '''
        return self.gl.get_locator('sina_home', 'chapter')

    def chapter(self):
        '''
        文章元素封装
        :return:
        '''
        return self.gl.get_locator('sina_home', 'chapter')

    def get_tost_element(self, message):
        '''
        获取tostelement,
        :param message:
        :return:
        '''
        time.sleep(1)
        tost = ("xpath", "//*[contains(@text," + message + ")]")
        return WebDriverWait(self.driver, 10,
                             0.1).until(EC.presence_of_element_located)

    def driver_close(self):
        '''
        运行结束关闭driver
        :return:
        '''
        self.driver.quit()
Example #5
0
class SinaChapter(object):
    '''
    新增文章页面元素封装
    '''
    def __init__(self, driver):
        self.driver = driver
        self.gl = GetByLocator(self.driver)

    def title(self):
        '''
        文章标题元素封装
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'title')

    def content(self):
        '''
        文章内容元素封装
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'content')

    def next(self):
        '''
        内容编辑完成后,下一步按钮元素封装
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'next')

    def save(self):
        '''
        文章内容保存按钮元素封装
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'save')

    def chapter_send(self):
        '''
        发布文章按钮元素封装
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'titleSave')

    def pic(self):
        '''
        图片按钮
        :return:
        '''
        return self.gl.get_locator('sina_editchapter', 'pic')
Example #6
0
class Driver(object):
    def __init__(self):
        self.oe = OperExcel(self.excel_path())

    def get_driver(self):
        capabilities = {
            "platformName": "Android",
            "unicodeKeyboard": 'true',
            "deviceName": "3XU9X17324W10646",
            "noReset": 'true',
            "platformVersion": "6.0",
            "appPackage": "com.sina.weibo",
            "appActivity":
            "com.sina.weibo.SplashActivity"  # appium1.7版本之后就应该不需要改配置了
        }
        # 对应的cmd中需先执行:appium -p 4723 -bp 4724 -U 3XU9X17324W10646
        driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities)
        sleep(8)
        # 登录后进入发布界面
        return driver

    def send_new(self, driver, title, content):
        tel = '\n李老师电话:19981203720'
        content = content + tel
        self.gl = GetByLocator(driver)  #注意这里不要放入init,会导致重复执行
        self.gl.get_locator('sina_home', 'increase').click()
        self.gl.get_locator('sina_home', 'chapter').click()
        sleep(8)
        self.gl.get_locator('sina_editchapter', 'title').clear()
        self.gl.get_locator('sina_editchapter', 'title').send_keys(title)
        self.gl.get_locator('sina_editchapter', 'content').clear()
        self.gl.get_locator('sina_editchapter', 'content').send_keys(content)
        sleep(8)
        self.gl.get_locator('sina_editchapter', 'next').click()  #这里有问题
        sleep(2)
        self.gl.get_locator('sina_editchapter', 'save').click()
        sleep(2)
        self.gl.get_locator('sina_editchapter', 'titleSave').click()
        sleep(8)

    def excel_path(self):
        '''
        通过相对路径获取目标excel
        通过join来拼接绝对地址
        :return:
        '''
        excel_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '../data/Tiezi.xlsx'))
        return excel_dir

    def circl_send(self):
        '''
        根据excel中数据行数,循环发帖
        :return:
        '''
        driver = self.get_driver()
        line = self.oe.excel_get_lines()
        j = 0
        for i in range(1, line):
            if j < 10:  # 限制数目
                title = self.oe.excel_get_cell(i, 0)
                conte = self.oe.excel_get_cell(i, 1)
                run = self.oe.excel_get_cell(i, 3)
                if run == 'Y':
                    self.send_new(driver, title, conte)
                    j = +1

    def set_input(self):
        '''
        设置输入法为第一个默认输入法
        :return:
        '''
        driver = self.get_driver()
        input_list = driver.available_ime_engines  #注意这里是不用(),源代码:return self.execute(Command.GET_AVAILABLE_IME_ENGINES, {})['value']
        driver.activate_ime_engine(input_list[0])  #设置为第一个输入法