Beispiel #1
0
def my_guess(driver):
    '''
    我的竞猜获取竞猜内容
    '''
    #点击我的竞猜按钮
    driver.find_elements_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/*'
    )[4].click()
    while True:
        try:
            #随机点击一个我参与的竞猜
            random_click(driver,
                         '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/'
                         )[0].click()
            #向上滑动
            slide_up(driver)
            #选择竞猜一个
            #driver.find_element_by_xpath(
            #    '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[' + str(len(driver.find_elements_by_xpath(
            #        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[*]'))) + ']/UIATextField[1]').click()
            driver.find_element_by_xpath(
                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell['
                + str(
                    len(
                        driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[*]'
                        ))) + ']/UIATextField[1]').send_keys('3')
            #向上滑动取消竞猜
            driver.swipe(100, 145, 100, 120)
            #点击竞猜
            driver.find_element_by_xpath(
                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIAButton[1]'
            ).click()
            #点击确认购买
            driver.find_element_by_name(u'购买').click()
            break
        except:
            driver.find_element_by_xpath(u'返回').click()
            continue
            #等待购买成功
    time.sleep(3)
    share(driver, to=random.choice([u'朋友圈', u'微信', u'微博']))
    driver.find_element_by_name(u'返回').click()
    #返回上一级
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAButton[1]'
    ).click()
Beispiel #2
0
def my_guess(driver):
    '''
    我的竞猜获取竞猜内容
    '''
    #点击我的竞猜按钮
    driver.find_elements_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/*')[4].click()
    while True:
        try:
            #随机点击一个我参与的竞猜
            random_click(driver, '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/')[0].click()
            #向上滑动
            slide_up(driver)
            #选择竞猜一个
            #driver.find_element_by_xpath(
            #    '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[' + str(len(driver.find_elements_by_xpath(
            #        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[*]'))) + ']/UIATextField[1]').click()
            driver.find_element_by_xpath(
                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[' + str(
                    len(driver.find_elements_by_xpath(
                        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[*]'))) + ']/UIATextField[1]').send_keys(
                '3')
            #向上滑动取消竞猜
            driver.swipe(100, 145, 100, 120)
            #点击竞猜
            driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIAButton[1]').click()
            #点击确认购买
            driver.find_element_by_name(u'购买').click()
            break
        except:
            driver.find_element_by_xpath(u'返回').click()
            continue
            #等待购买成功
    time.sleep(3)
    share(driver, to=random.choice([u'朋友圈', u'微信', u'微博']))
    driver.find_element_by_name(u'返回').click()
    #返回上一级
    driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAButton[1]').click()
Beispiel #3
0
def board_paging_display(driver, xpaths, page={}):
    '''
    判断艺人榜上有的几页内容,每页有多少有记录
    返回艺人总数
    '''
    #如果第一次进入先添加第一页有多少个记录
    if not page:
        page[1] = len(driver.find_elements_by_xpath(xpaths))
        board_paging_display(driver, xpaths, page)
    #不是第一次进入且最后一页和倒数第二页的数量是否相同,如果相同就加载了所有的记录,并返回到八卦页面
    else:
        if len(page) > 1 and page[max(page.keys())] == len(
                driver.find_elements_by_xpath(xpaths)):
            log_info("There's " + str(max(page.keys())) + " pages in board!")
            for i in page:
                log_info('page ' + str(i) + ' : ' + str(page[i]))
            driver.find_element_by_name('返回').click()
        #如果没有全加载出来继续翻页并且递归调用
        else:
            slide_up(driver)
            page[max(page.keys()) + 1] = len(
                driver.find_elements_by_xpath(xpaths))
            board_paging_display(driver, xpaths=xpaths, page=page)
    return page[max(page.keys())]
def board_paging_display(driver, xpaths, page={}):
    '''
    判断艺人榜上有的几页内容,每页有多少有记录
    返回艺人总数
    '''
    #如果第一次进入先添加第一页有多少个记录
    if not page:
        page[1] = len(driver.find_elements_by_xpath(xpaths))
        board_paging_display(driver, xpaths, page)
    #不是第一次进入且最后一页和倒数第二页的数量是否相同,如果相同就加载了所有的记录,并返回到八卦页面
    else:
        if len(page) > 1 and page[max(page.keys())] == len(
                driver.find_elements_by_xpath(xpaths)):
            log_info("There's " + str(max(page.keys())) + " pages in board!")
            for i in page:
                log_info('page ' + str(i) + ' : ' + str(page[i]))
            driver.find_element_by_name('返回').click()
        #如果没有全加载出来继续翻页并且递归调用
        else:
            slide_up(driver)
            page[max(page.keys()) + 1] = len(
                driver.find_elements_by_xpath(xpaths))
            board_paging_display(driver, xpaths=xpaths, page=page)
    return page[max(page.keys())]
Beispiel #5
0
def create_guss(driver):
    '''
    创建竞猜

    '''
    #点击发起竞猜按钮
    driver.find_element_by_name(u'发起竞猜').click()
    #点击竞猜标题输入区
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIATextView[1]'
    ).click()
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIATextView[1]'
    ).send_keys(u'自动化测试')
    #点击并输入内容
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[2]/UIATextView[1]'
    ).click()
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[2]/UIATextView[1]'
    ).send_keys(randomCN(10))
    #循环添加两次答案
    for i in range(2):
        #点击添加答案
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableGroup[6]/UIAStaticText[1]'
        ).click()
        #弹出框内输入答案
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[3]/UIAAlert[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[1]/UIATextField[1]'
        ).click()
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[3]/UIAAlert[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[1]/UIATextField[1]'
        ).send_keys(randomCN(3))
        #点击确定
        driver.find_element_by_name(u'确定').click()
    #选择一个答案
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[3]/UIAButton[1]'
    ).click()
    #使用相册
    #driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAButton[2]').click()
    #随机选择一个相册
    #random_click(driver, '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*')[0].click()
    #随机选择一张照片
    #random.choice(driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/*')).click()
    #选取内容
    #driver.find_element_by_name(u'选取').click()
    #拍照方式
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAButton[1]'
    ).click()
    #点击取景按钮拍照
    time.sleep(1)
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIAButton[6]').click()
    #选择照片
    driver.find_element_by_name(u'使用照片').click()
    #向上滑动
    slide_up(driver)
    #选择预计开奖时间
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[6]/UIAStaticText[1]'
    ).click()
    time.sleep(2)
    #点击确定
    driver.swipe(295, 333, 295, 333)
    #点击并发布
    driver.find_element_by_name('支付并发布').click()
    #等待发布成功并回到竞猜主页面
    WebDriverWait(driver, 20).until(lambda x: x.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAStaticText[1]'
    ))
Beispiel #6
0
def board(driver, mount=0, name=''):
    '''
    根据人名点击签到未完成
    在八卦页面进入到艺人榜,并搜索name艺人并关注,如果已经关注了则不作任何操作
    如果name为空,随机选择一个艺人关注
    '''
    if mount == 0:
        mount = board_paging_display(
            driver, '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/./*') * 2
    driver.find_element_by_name("艺人榜").click()
    if name:
        #查找当前页面有没有叫name的艺人
        mount_t = len(
            driver.find_elements_by_xpath(
                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'
            ))
        if filter(
                lambda x: x == name,
                map(
                    lambda x: x.text,
                    driver.find_elements_by_xpath(
                        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'
                    ))):
            #遍历整个页面查找这个艺人的名字
            for i in driver.find_elements_by_xpath(
                    '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'
            ):
                if i.text == name:
                    #判断签到按钮是否可以点击
                    if driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                    )[int(i.id) % mount_t].is_enabled():
                        #如果可以点击,点击
                        print int(
                            driver.find_elements_by_xpath(
                                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                            )[int(i.id) % mount_t].id) % mount_t
                        driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                        )[int(i.id) % mount_t].click()
                        log_info(name + ' Sign in successfully')
                        driver.find_element_by_name('返回').click()
                        break
                    else:
                        #如果不可以点击打印log
                        print driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                        )[int(i.id) % mount_t].id
                        print i.text
                        log_info(name + ' Have already signed in')
                        break
        #如果没有这个人,而且没有加载出全部数据的话滑动加载出下一页
        elif not mount_t == mount:
            slide_up(driver)
            board(driver, mount, name)
        else:
            log_info('The board has not been created!!!')
    else:
        #mount = board_paging_display(driver)
        while True:
            mount_t = len(
                driver.find_elements_by_xpath(
                    '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                ))
            if mount_t == mount:
                break
            else:
                slide_up(driver)
        while True:
            random_element = random.choice(
                driver.find_elements_by_xpath(
                    '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'
                ))
            try:
                if random_element.text == u'签到':
                    random_element.click()
                    log_info(
                        str((int(random_element.id) % mount) / 2) +
                        "'s  signed in successfully")
                    driver.find_element_by_name('返回').click()
                    break
            except:
                continue
def create_guss(driver):
    '''
    创建竞猜

    '''
    #点击发起竞猜按钮
    driver.find_element_by_name(u'发起竞猜').click()
    #点击竞猜标题输入区
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIATextView[1]').click()
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIATextView[1]').send_keys(u'自动化测试')
    #点击并输入内容
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[2]/UIATextView[1]').click()
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[2]/UIATextView[1]').send_keys(randomCN(10))
    #循环添加两次答案
    for i in range(2):
        #点击添加答案
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableGroup[6]/UIAStaticText[1]').click()
        #弹出框内输入答案
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[3]/UIAAlert[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[1]/UIATextField[1]').click()
        driver.find_element_by_xpath(
            '//UIAApplication[1]/UIAWindow[3]/UIAAlert[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[1]/UIATextField[1]').send_keys(
            randomCN(3))
        #点击确定
        driver.find_element_by_name(u'确定').click()
    #选择一个答案
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[3]/UIAButton[1]').click()
    #使用相册
    #driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAButton[2]').click()
    #随机选择一个相册
    #random_click(driver, '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*')[0].click()
    #随机选择一张照片
    #random.choice(driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/*')).click()
    #选取内容
    #driver.find_element_by_name(u'选取').click()
    #拍照方式
    driver.find_element_by_xpath(
        '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]/UIAButton[1]').click()
    #点击取景按钮拍照
    time.sleep(1)
    driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIAButton[6]').click()
    #选择照片
    driver.find_element_by_name(u'使用照片').click()
    #向上滑动
    slide_up(driver)
    #选择预计开奖时间
    driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[6]/UIAStaticText[1]').click()
    time.sleep(2)
    #点击确定
    driver.swipe(295, 333, 295, 333)
    #点击并发布
    driver.find_element_by_name('支付并发布').click()
    #等待发布成功并回到竞猜主页面
    WebDriverWait(driver, 20).until(
        lambda x: x.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAStaticText[1]'))
def board(driver, mount=0, name=''):
    '''
    根据人名点击签到未完成
    在八卦页面进入到艺人榜,并搜索name艺人并关注,如果已经关注了则不作任何操作
    如果name为空,随机选择一个艺人关注
    '''
    if mount == 0:
        mount = board_paging_display(driver, '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/./*') * 2
    driver.find_element_by_name("艺人榜").click()
    if name:
        #查找当前页面有没有叫name的艺人
        mount_t = len(driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'))
        if filter(lambda x: x == name, map(lambda x: x.text, driver.find_elements_by_xpath(
                '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'))):
            #遍历整个页面查找这个艺人的名字
            for i in driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAStaticText'):
                if i.text == name:
                    #判断签到按钮是否可以点击
                    if driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton')[
                                int(i.id) % mount_t].is_enabled():
                    #如果可以点击,点击
                        print int(driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton')[
                            int(i.id) % mount_t].id) % mount_t
                        driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton')[int(i.id) % mount_t].click()
                        log_info(name + ' Sign in successfully')
                        driver.find_element_by_name('返回').click()
                        break
                    else:
                        #如果不可以点击打印log
                        print driver.find_elements_by_xpath(
                            '//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton')[int(i.id) % mount_t].id
                        print i.text
                        log_info(name + ' Have already signed in')
                        break
        #如果没有这个人,而且没有加载出全部数据的话滑动加载出下一页
        elif not mount_t == mount:
            slide_up(driver)
            board(driver, mount, name)
        else:
            log_info('The board has not been created!!!')
    else:
        #mount = board_paging_display(driver)
        while True:
            mount_t = len(driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'))
            if mount_t == mount:
                break
            else:
                slide_up(driver)
        while True:
            random_element = random.choice(
                driver.find_elements_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/*/UIAButton'))
            try:
                if random_element.text == u'签到':
                    random_element.click()
                    log_info(str((int(random_element.id) % mount) / 2) + "'s  signed in successfully")
                    driver.find_element_by_name('返回').click()
                    break
            except:
                continue