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 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 create_guss(driver, title='autotest_android', text=randomStr(10)): ''' 创建竞猜 ''' #点击发起竞猜按钮 driver.find_element_by_id('com.android.ooch:id/title_img1').click() #点击竞猜标题输入区 driver.find_element_by_id('com.android.ooch:id/publish_lottery_title').send_keys(title) #输入竞猜内容 driver.find_element_by_id('com.android.ooch:id/publish_lottery_instr').send_keys(text) #循环添加两次答案 for i in range(2): #点击添加答案 driver.find_element_by_id('com.android.ooch:id/publish_lottery_add_answer').click() #弹出框内输入答案 driver.find_element_by_id('android:id/custom').send_keys(randomStr(6)) #点击确定 driver.find_element_by_id('android:id/button1').click() #选择一个答案 random.choice(driver.find_elements_by_id('com.android.ooch:id/icon')).click() #隐藏键盘 driver.back() #driver.hide_keyboard() #点击添加照片 driver.find_element_by_id('com.android.ooch:id/publish_lottery_upload').click() #选择添加图片 driver.find_element_by_id('com.android.ooch:id/item_popupwindows_Photo').click() #随机选择一个相册 random.choice(driver.find_elements_by_xpath( '//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ListView[1]/android.widget.RelativeLayout[*]')).click() #随机选择一张照片 random.choice(driver.find_elements_by_id('com.android.ooch:id/image')).click() #选取内容 driver.find_element_by_id('com.android.ooch:id/finish_btn').click() #隐藏键盘 #driver.back() #随机选择一个答案 #random.choice(driver.find_elements_by_id('com.android.ooch:id/icon')).click() #选择预计开奖时间 driver.find_element_by_id('com.android.ooch:id/publish_lottery_time').click() #driver.find_elements_by_id('android:id/numberpicker_input')[0].clear() ##随机输入一个年 #driver.find_elements_by_id('android:id/numberpicker_input')[0].send_keys(random.choice(range(2015, 2020))) #if driver.find_elements_by_id('android:id/numberpicker_input')[0].text == '2015': # pass #else: # #选择月份 # driver.find_elements_by_id('android:id/numberpicker_input')[1].clear() # driver.find_elements_by_id('android:id/numberpicker_input')[1].send_keys(random.choice(range(1, 13))) # #选择日 # driver.find_elements_by_id('android:id/numberpicker_input')[2].clear() # driver.find_elements_by_id('android:id/numberpicker_input')[2].send_keys(range(1, 31)) #确定时间 driver.find_element_by_id('android:id/button1').click() #向上滑动 middle_slipe(driver) #点击并发布 driver.find_element_by_id('com.android.ooch:id/publish_btn').click() time.sleep(2) #到web页面点击发布 subimt_guess = submit_guess(title, 'http://123.57.239.192/admin') subimt_guess.modify_guess()