class RecommendTest(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone = [] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps[ 'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard'] = 'True' desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.extend = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def User_test1(self): """关注推荐用户""" #点击发现 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/home_pic') self.ElementCheck.check_assertTrue(result, msg='发现按钮Fail') #点击关注 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/focus_tv') self.ElementCheck.check_assertTrue(result, msg='关注集合页面Fail') #点击用户推荐 result = self.ElementCheck.click_change('name', '用户推荐') self.ElementCheck.check_assertTrue(result, msg='用户推荐页面Fail') #获取第一个腿甲用户的名字 user_name = self.ElementCheck.attribute_name( 'xpath', '//android.support.v7.widget.RecyclerView/\ android.widget.LinearLayout[2]/\ android.widget.LinearLayout[1]/\ android.widget.LinearLayout[1]/\ android.widget.TextView[1]') self.ElementCheck.click_change('ides', 'com.bugua.fight:id/followBtn[0]') #检查关注 self.d.back() result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/my_pic') self.ElementCheck.check_assertTrue(result, msg='进入我的页面失败') result = self.ElementCheck.click_jump('name', '关注') self.ElementCheck.check_assertTrue(result, msg='进入关注页面失败') result = self.ElementCheck.existence('name', user_name) self.ElementCheck.check_assertTrue(result, msg='未发现关注的推荐用户') result = self.ElementCheck.click_jump('name', '已关注', 'name', '关注') self.ElementCheck.check_assertTrue(result, msg='已关注按钮失败') self.d.back() time.sleep(2) self.d.find_element_by_name('关注').click() result = self.ElementCheck.existence('name', user_name) self.assertFalse(result, msg='发现关注的推荐用户')
class New_pictureTest(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone=[] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps['appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard']='True' desired_caps['unicodeKeyboard']='True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.extend = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def Picture1(self): """新图浏览框隐藏""" #点击发现 result = self.ElementCheck.click_change('id','com.bugua.fight:id/home_pic') self.ElementCheck.check_assertTrue(result,msg='发现按钮Fail') #点击新图 self.d.find_element_by_id('com.bugua.fight:id/new_pic_tv').click() #随机滑屏 self.ElementCheck.random_click('id','com.bugua.fight:id/jgznewpic_content') #单击后内容检查 result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_send') self.ElementCheck.check_assertTrue(result,msg='直接发送按钮Fail') result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_save') self.ElementCheck.check_assertTrue(result,msg='添加收藏按钮Fail') result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_hide_preview') self.ElementCheck.check_assertTrue(result,msg='隐藏按钮Fail') #点击隐藏按钮 result = self.ElementCheck.click_change('id','com.bugua.fight:id/btn_hide_preview','hide') self.ElementCheck.check_assertTrue(result,msg='隐藏按钮失败') #滑动后隐藏 self.ElementCheck.random_click('id','com.bugua.fight:id/jgznewpic_content') result = self.ElementCheck.swipe_existence('id','com.bugua.fight:id/btn_hide_preview') self.ElementCheck.check_assertTrue(result, msg='隐藏失败') #点击收藏 self.ElementCheck.random_click('id','com.bugua.fight:id/jgznewpic_content') result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/btn_save') self.ElementCheck.check_assertTrue(result, msg='收藏按钮未变化') def Picture2(self): """新图浏览框收藏""" #点击发现 self.d.find_element_by_id('com.bugua.fight:id/home_pic').click() #点击新图 self.d.find_element_by_id('com.bugua.fight:id/new_pic_tv').click() #随机滑屏 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content', 'long_press') #单击后内容检查 result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_send') self.ElementCheck.check_assertTrue(result,msg='直接发送按钮Fail') result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_star') self.ElementCheck.check_assertTrue(result,msg='添加收藏按钮Fail') result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_download') self.ElementCheck.check_assertTrue(result,msg='保存到本地按钮Fail') result = self.ElementCheck.existence('id','com.bugua.fight:id/btn_edit') self.ElementCheck.check_assertTrue(result,msg='改图按钮Fail') #点击收藏 result = self.ElementCheck.click_change('id','com.bugua.fight:id/icon_star') self.ElementCheck.check_assertTrue(result,msg='收藏按钮未变化') def Top(self): """新图置顶按钮""" #点击发现 result = self.ElementCheck.click_change('id','com.bugua.fight:id/home_pic') self.ElementCheck.check_assertTrue(result,msg='发现按钮Fail') #点击新图 self.d.find_element_by_id('com.bugua.fight:id/new_pic_tv').click() #随机滑屏 a = random.choice(range(1, 4)) print(a) size = self.d.get_window_size() width = size['width'] height = size['height'] print(width, height) i = 0 for i in range(a): self.d.swipe(width*280/1080, height*1600/1776, width*280/1080, height*432/1776) i = i+1 time.sleep(2) self.d.swipe(width*280/1080, height*500/1800, width*280/1080, height*900/1800) time.sleep(2) self.ElementCheck.click('id','com.bugua.fight:id/to_top') time.sleep(5) result=self.ElementCheck.existence('name','大家正在发') self.assertTrue(result, msg='没有回到顶部')
class ThemeTest(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone = [] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps[ 'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard'] = 'True' desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.extend = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def Follow_Theme_Test1(self): #点击主题 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/theme_tv') self.ElementCheck.check_assertTrue(result, msg='进入主题失败') #点击发现更多主题 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/more_normal_theme', 'name', '关注列表') self.ElementCheck.check_assertTrue(result, msg='未进入关注列表') #选择关注一个主题 time.sleep(2) theme = self.ElementCheck.random_click_get_name( 'id', 'com.bugua.fight:id/theme_title') result = self.ElementCheck.click_jump('name', '关注', 'name', '已关注') self.ElementCheck.check_assertTrue(result, msg='关注按钮未改变') #返回首页主题 self.d.back() self.d.back() time.sleep(4) result = self.ElementCheck.existence('name', theme) self.ElementCheck.check_assertTrue(result, msg='关注主题未成功') #取消关注了的主题 self.d.find_element_by_name(theme).click() result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/is_follow') self.ElementCheck.check_assertTrue(result, msg='已关注按钮未改变') #检查是否已取消关注 self.d.back() time.sleep(2) result = self.ElementCheck.existence('name', theme) self.ElementCheck.check_assertFalse(result, msg='关注主题未成功') def Follow_Theme_Test2(self): #点击主题 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/theme_tv') self.ElementCheck.check_assertTrue(result, msg='进入主题失败') #点击发现更多主题 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/more_normal_theme', 'name', '关注列表') self.ElementCheck.check_assertTrue(result, msg='未进入关注列表') #选择关注一个主题 theme = self.ElementCheck.random_click_get_other_name( 'id', 'com.bugua.fight:id/theme_support', 'id', 'com.bugua.fight:id/theme_title') result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/is_follow') self.ElementCheck.check_assertTrue(result, msg='关注按钮未改变') #返回首页主题 self.d.back() self.d.back() time.sleep(4) result = self.ElementCheck.existence('name', theme) self.ElementCheck.check_assertTrue(result, msg='关注主题未成功') #取消关注了的主题 self.d.find_element_by_name(theme).click() result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/is_follow') self.ElementCheck.check_assertTrue(result, msg='已关注按钮未改变') #检查是否已取消关注 self.d.back() time.sleep(1) result = self.ElementCheck.existence('name', theme) self.ElementCheck.check_assertFalse(result, msg='关注主题未成功') def Theme_picture1(self): #点击主题 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/theme_tv') self.ElementCheck.check_assertTrue(result, msg='进入主题失败') #点击发现更多主题 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/more_normal_theme', 'name', '关注列表') self.ElementCheck.check_assertTrue(result, msg='未进入关注列表') #选择一个主题 self.ElementCheck.random_click('id', 'com.bugua.fight:id/click_area') #点击图片墙 self.d.find_element_by_name('图片墙').click() #点击图片 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content') #单击后内容检查 result = self.ElementCheck.existence('id', 'com.bugua.fight:id/btn_send') self.ElementCheck.check_assertTrue(result, msg='直接发送按钮Fail') result = self.ElementCheck.existence('id', 'com.bugua.fight:id/btn_save') self.ElementCheck.check_assertTrue(result, msg='添加收藏按钮Fail') result = self.ElementCheck.existence( 'id', 'com.bugua.fight:id/btn_hide_preview') self.ElementCheck.check_assertTrue(result, msg='隐藏按钮Fail') #点击收藏 self.d.find_element_by_id('com.bugua.fight:id/btn_save').click() test = self.d.find_elements_by_name('添加收藏') self.assertEqual(len(test), 0, msg='收藏按钮未变化') def Theme_picture2(self): #点击主题 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/theme_tv') self.ElementCheck.check_assertTrue(result, msg='进入主题失败') #点击发现更多主题 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/more_normal_theme', 'name', '关注列表') self.ElementCheck.check_assertTrue(result, msg='未进入关注列表') #选择一个主题 self.ElementCheck.random_click('id', 'com.bugua.fight:id/click_area') #点击图片墙 self.d.find_element_by_name('图片墙').click() time.sleep(5) #长按图片 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content', 'long_press') #点击收藏 self.d.find_element_by_id('com.bugua.fight:id/icon_star').click() test = self.d.find_elements_by_name('添加收藏') self.assertEqual(len(test), 0, msg='收藏按钮未变化') def Theme_picture3(self): #点击主题 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/theme_tv') self.ElementCheck.check_assertTrue(result, msg='进入主题失败') #点击发现更多主题 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/more_normal_theme', 'name', '关注列表') self.ElementCheck.check_assertTrue(result, msg='未进入关注列表') #选择一个主题 self.ElementCheck.random_click('id', 'com.bugua.fight:id/click_area') #点击图片墙 self.d.find_element_by_name('图片墙').click() #点击图片 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content') #点击隐藏按钮 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/btn_hide_preview') self.ElementCheck.check_assertTrue(result, msg='点击隐藏按钮失败') #滑动后隐藏 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content') result = self.ElementCheck.swipe_existence( 'id', 'com.bugua.fight:id/btn_hide_preview') self.ElementCheck.check_assertTrue(result, msg='隐藏失败') #点击收藏 self.ElementCheck.random_click('id', 'com.bugua.fight:id/jgznewpic_content') result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/btn_save') self.ElementCheck.check_assertTrue(result, msg='收藏按钮未变化')
class RepliesTest(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone = [] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps[ 'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard'] = 'True' desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.ElmentCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def EssenceTest(self): """精华区回帖""" #点击精华区 self.d.find_element_by_id('com.bugua.fight:id/essence_area').click() #随机选取帖子 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') #对帖子进行回复 try: self.d.find_element_by_name('我要讨论') #讨论帖 c = random.choice(range(2)) if c == 1: self.d.find_element_by_id( 'com.bugua.fight:id/content_et').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() else: self.d.find_element_by_id( 'com.bugua.fight:id/add_pic_rl').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() except: try: #求图帖 #图片回复 self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() except: #斗图帖 b = random.choice(range(2)) if b == 1: #文字回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg_left').click() self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() else: #图片回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_emot').click() def PleaseTest(self): """求p频道回帖""" self.d.find_element_by_id('com.bugua.fight:id/ask_for_ps_tv').click() #获取当前页面帖子数量 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') try: self.d.find_element_by_name('我要讨论') #讨论帖 c = random.choice(range(2)) if c == 1: self.d.find_element_by_id( 'com.bugua.fight:id/content_et').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() else: self.d.find_element_by_id( 'com.bugua.fight:id/add_pic_rl').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() except: try: #求图帖 #图片回复 self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() except: #斗图帖 b = random.choice(range(2)) if b == 1: #文字回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg_left').click() self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() else: #图片回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_emot').click() def All_areaTest(self): """大杂烩回帖""" #点击大杂烩 self.d.find_element_by_id('com.bugua.fight:id/all_area').click() #随机选取帖子 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') #对帖子进行回复 try: self.d.find_element_by_name('我要讨论') #讨论帖 c = random.choice(range(2)) if c == 1: self.d.find_element_by_id( 'com.bugua.fight:id/content_et').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() else: self.d.find_element_by_id( 'com.bugua.fight:id/add_pic_rl').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() self.d.find_element_by_id( 'com.bugua.fight:id/submit_tv').click() except: try: #求图帖 #图片回复 self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() except: #斗图帖 b = random.choice(range(2)) if b == 1: #文字回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg_left').click() self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_msg').send_keys('6666669') self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_msg').click() else: #图片回复 self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot').click() self.d.find_element_by_id( 'com.bugua.fight:id/drawee_view_0').click() p = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') p[random.choice(range(1, len(p)))].click() self.d.find_element_by_id( 'com.bugua.fight:id/btn_submit').click() time.sleep(2) self.d.find_element_by_id( 'com.bugua.fight:id/btn_send_emot').click() def post_send_box_hide(self): """帖子预览框隐藏""" self.d.find_element_by_id('com.bugua.fight:id/ask_for_ps_tv').click() #获取当前页面帖子数量 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') #点击发送框 try: self.d.find_element_by_name('我要讨论') #点击发送框 self.d.find_element_by_id('com.bugua.fight:id/add_pic').click() except: try: self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() except: self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() #滑动页面 size = self.d.get_window_size() width = size['width'] height = size['height'] print(width, height) self.d.swipe(width * 200 / 1080, height * 720 / 1776, width * 200 / 1080, height * 300 / 1776) a = self.d.find_elements_by_id('com.bugua.fight:id/drawee_view_0') self.assertEqual(len(a), 0, msg='发送框未收起') def all_area_send_box_hide(self): """大杂烩帖子预览框隐藏""" #点击大杂烩 self.d.find_element_by_id('com.bugua.fight:id/all_area').click() #随机选取帖子 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') try: self.d.find_element_by_name('我要讨论') #点击发送框 self.d.find_element_by_id('com.bugua.fight:id/add_pic').click() except: try: self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() except: self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() #滑动页面 size = self.d.get_window_size() width = size['width'] height = size['height'] print(width, height) self.d.swipe(width * 680 / 760, height * 500 / 1776, width * 680 / 760, height * 100 / 1776) a = self.d.find_elements_by_id('com.bugua.fight:id/drawee_view_0') self.assertEqual(len(a), 0, msg='发送框未收起') def one_click1(self): """表情键盘一键生成不带文字""" #点击大杂烩 self.ElmentCheck.click_change('id', 'com.bugua.fight:id/all_area') #随机选取帖子 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') try: self.d.find_element_by_name('我要讨论') #点击发送框 self.d.find_element_by_id('com.bugua.fight:id/add_pic').click() except: try: self.d.find_element_by_name('我要求图') self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() except: self.d.find_element_by_id( 'com.bugua.fight:id/txt_send_emot_container').click() #点击一键生成表情按钮 self.ElmentCheck.click_jump('id', 'com.bugua.fight:id/drawee_view_1', 'name', '一键生成') #输入内容 self.d.find_element_by_id('com.bugua.fight:id/input_et').send_keys( '不要装逼') #点击一键生成 self.d.find_element_by_name('一键生成').click() #time.sleep(2) self.ElmentCheck.wait_element('xpath', '//android.widget.ImageView/..') #计数是否为0 result = self.ElmentCheck.existence('name', '(0)完成') self.ElmentCheck.check_assertTrue(result, msg='计数显示fail') time.sleep(5) #随机选择图片 self.ElmentCheck.random_click('xpath', '//android.widget.ImageView/..') time.sleep(5) #计数是否为1 result = self.ElmentCheck.existence('name', '(1)完成') self.ElmentCheck.check_assertTrue(result, msg='计数显示fail') #点击完成按钮 self.d.find_element_by_id('com.bugua.fight:id/finish_btn').click() time.sleep(1) try: os._exists(r'./Fail_picture') == False os.mkdir(r'./Fail_picture') except: pass self.d.get_screenshot_as_file('./result/one_click1.png') def one_click2(self): """表情键盘一键生成不带文字""" #点击大杂烩 self.ElmentCheck.click_change('id', 'com.bugua.fight:id/all_area') #选取讨论帖子 while True: try: #随机选取帖子 self.ElmentCheck.random_click('id', 'com.bugua.fight:id/bbs_title') self.d.find_element_by_name('我要讨论') #文本框输入内容 self.d.find_element_by_id( 'com.bugua.fight:id/content_et').send_keys('不要装逼了') #点击发送框 self.d.find_element_by_id('com.bugua.fight:id/add_pic').click() break except: self.d.back() continue #点击一键生成表情按钮 self.ElmentCheck.click_jump('id', 'com.bugua.fight:id/drawee_view_1', 'name', '一键生成') #输入内容 result = self.ElmentCheck.attribute_name( 'id', 'com.bugua.fight:id/input_et', '不要装逼了') self.ElmentCheck.check_assertTrue(result, msg='未将文本带入') #点击一键生成 self.d.find_element_by_name('一键生成').click() #time.sleep(2) self.ElmentCheck.wait_element('xpath', '//android.widget.ImageView/..') #计数是否为0 result = self.ElmentCheck.existence('name', '(0)完成') self.ElmentCheck.check_assertTrue(result, msg='计数显示fail') time.sleep(5) #随机选择图片 self.ElmentCheck.random_click('xpath', '//android.widget.ImageView/..') #计数是否为1 result = self.ElmentCheck.existence('name', '(1)完成') self.ElmentCheck.check_assertTrue(result, msg='计数显示fail') #点击完成按钮 self.d.find_element_by_id('com.bugua.fight:id/finish_btn').click() time.sleep(1) try: os._exists(r'./Fail_picture') == False os.mkdir(r'./Fail_picture') except: pass self.d.get_screenshot_as_file('./result/one_click2.png')
class Follow_Test(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone = [] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps[ 'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard'] = 'True' desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.extend = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def Follow_user1(self): """从帖子中关注一个用户""" #点击大杂烩 self.d.find_element_by_id('com.bugua.fight:id/all_area').click() # #向下拉屏幕隐藏帖子以外内容 # size=self.d.get_window_size() # width=size['width'] # height=size['height'] # print(width,height) # self.d.swipe(width*200/1080, height*1500/1776, width*200/1080, height*720/1776) #翻页 user_name = '丑到爆的同桌' while user_name == '丑到爆的同桌': self.ElementCheck.random_click('id', 'com.bugua.fight:id/bbs_title') #在帖子中寻找用户头像 self.ElementCheck.random_click('id', 'com.bugua.fight:id/avatar') #获取名字 user_name = self.d.find_elements_by_class_name( 'android.widget.TextView') user_name = user_name[1].get_attribute('name') print(user_name) if user_name == '丑到爆的同桌': continue #点击添加关注 time.sleep(2) self.d.find_element_by_id('com.bugua.fight:id/btn_follow').click() time.sleep(5) user_data = self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout[1]') self.extend.get_screenshot_by_element(user_data).write_to_file( '.\Temp', 'user_data') #进入我的关注页面 self.d.back() self.d.back() self.d.find_element_by_id('com.bugua.fight:id/my_pic').click() self.d.find_element_by_name('关注').click() a1 = self.d.find_elements_by_name(user_name) self.d.find_element_by_name(user_name).click() self.assertEqual(len(a1), 1, msg='没有发现所关注的用户') #对比用户的个人资料,只对比了资料的部分(头像,用户名,签名) load = self.extend.load_image('.\Temp/user_data.png') user_data = self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout[1]') self.extend.get_screenshot_by_element(user_data).write_to_file( '.\Temp', 'user_data2') result = self.extend.get_screenshot_by_element( self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/android.widget.LinearLayout/android.widget.LinearLayout[1]' )).same_as(load, 0) self.ElementCheck.check_assertTrue(result, msg='用户资料显示有误') #取消关注 self.d.back() self.d.find_element_by_id('com.bugua.fight:id/button').click() button1 = self.d.find_elements_by_name('关注') self.assertEqual(len(button1), 1, msg='取消关注Fail') #关注列表检查 self.d.back() self.d.find_element_by_name('关注').click() button2 = self.d.find_elements_by_name(user_name) self.assertEqual(len(button2), 0, msg='关注列表自动刷新Fail') def Follow_package1(self): """从帖子中关注一个用户的表情包""" #点击大杂烩 self.d.find_element_by_id('com.bugua.fight:id/all_area').click() while True: self.ElementCheck.random_click('id', 'com.bugua.fight:id/bbs_title') #在帖子中寻找用户头像 self.ElementCheck.random_click('id', 'com.bugua.fight:id/avatar') #获取名字 user_name = self.d.find_elements_by_class_name( 'android.widget.TextView') user_name = user_name[1].get_attribute('name') print(user_name) if user_name == '丑到爆的同桌': continue #单击表情包 a = len( self.d.find_elements_by_xpath( '//android.support.v7.widget.RecyclerView/\ android.widget.FrameLayout/\ android.widget.LinearLayout')) print(a) if a > 0: self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/\ android.widget.FrameLayout/\ android.widget.LinearLayout[1]' ).click() else: self.d.back() self.d.back() user_name = '丑到爆的同桌' continue self.d.find_element_by_name(user_name).click() a2 = self.d.find_elements_by_name('个人资料') self.assertEqual(len(a2), 1, msg='进入用户资料失败') self.d.back() #点击收藏表情包 self.ElementCheck.click_change('name', '关注表情包', 'hide') packagename = self.ElementCheck.attribute_name( 'id', 'com.bugua.fight:id/folder_name') # time.sleep(5) # self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).write_to_file('./Temp','packpage') #关注的表情包检查 self.d.back() self.d.back() self.d.back() #点击我的 self.d.find_element_by_id('com.bugua.fight:id/my_pic').click() #进入关注表情包 self.d.find_element_by_name('关注表情包').click() result = self.ElementCheck.existence('name', user_name) self.ElementCheck.check_assertTrue(result, msg='未找到对应用户的表情包') #点击进入用户资料 result = self.ElementCheck.click_jump('name', user_name, 'name', '个人资料') self.ElementCheck.check_assertTrue(result, msg='未进入对应用的个人资料页面') self.d.back() #进入表情包 self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]' ).click() # time.sleep(2) # load = self.extend.load_image('./Temp/packpage.png') # self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).write_to_file('./Temp','packpage2') # result = self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).same_as(load, 0) # self.ElementCheck.check_assertTrue(result, msg='收藏的表情包显示不一致') if self.ElementCheck.attribute_name( 'id', 'com.bugua.fight:id/folder_name') == packagename: result = True else: result = False self.assertTrue(result, msg='所收藏的表情包名称正确') time.sleep(1) #取消关注表情包 test = self.d.find_elements_by_name('取消关注') print(len(test)) self.d.find_element_by_name('取消关注').click() a4 = self.d.find_elements_by_name('关注表情包') self.assertEqual(len(a4), 1, msg='取消关注Fail') #返回关注列表页面检查 self.d.back() a5 = self.d.find_elements_by_name(user_name) self.assertEqual(len(a5), 0, msg='取消关注查看页面Fail') break
class PostTest(unittest.TestCase): def setUp(self): print('Test start') #读取设备名字 try: txt = open('./devices', 'r') phone = [] for i in txt: phone.append(i) system1 = phone[0] device = phone[1] txt.close() except: system1 = '4.4.4' device = 'Android Emulator' desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '%s' % system1 desired_caps['deviceName'] = '%s' % device desired_caps['appPackage'] = 'com.bugua.fight' desired_caps[ 'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity' desired_caps['resetKeyboard'] = 'True' desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.extend = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): self.d.quit() def Tv_theme_name_Test(self): """发帖主题内容检查""" #只能检查收藏主题对应的前两个 #点击主题 self.d.find_element_by_id('com.bugua.fight:id/theme_tv').click() #获取主题 a2 = [] a2.append( self.ElementCheck.attribute_name( 'ides', 'com.bugua.fight:id/tv_theme_name[0]')) a2.append( self.ElementCheck.attribute_name( 'ides', 'com.bugua.fight:id/tv_theme_name[1]')) #print(a2) #点击【发帖】按钮 self.d.find_element_by_id('com.bugua.fight:id/btn_new_topic').click() #点击斗图 self.d.find_element_by_id('com.bugua.fight:id/click_type_find').click() #点击发帖位置选择 self.d.find_element_by_id('com.bugua.fight:id/post_topic_area').click() result = self.ElementCheck.click_jump( 'xpath', '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/' 'android.widget.LinearLayout[1]/' 'android.widget.TextView', 'name', '大杂烩') self.ElementCheck.check_assertTrue( result, msg='关注的主题顺序错误', ) b2 = [] b2.append( self.ElementCheck.attribute_name( 'ides', 'com.bugua.fight:id/theme_name[0]')) b2.append( self.ElementCheck.attribute_name( 'ides', 'com.bugua.fight:id/theme_name[1]')) self.assertEqual(b2[0], a2[0], msg='关注的主题顺序错误') self.assertEqual(b2[1], a2[1], msg='关注的主题顺序错误') def FindPostTest(self): """发求图帖""" #求图 #点击【发帖】按钮 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_new_topic', 'name', '选择发帖类型') self.ElementCheck.check_assertTrue(result, msg='发帖按钮FAil') self.d.find_element_by_id('com.bugua.fight:id/click_type_find').click() #标题输入框输入标题 self.d.find_element_by_id('com.bugua.fight:id/et_bbs_title').send_keys( '都谁有这种图拿出来') #输入内容 text = '有这种图的就不要客气的拿出来吧!' self.d.find_element_by_id( 'com.bugua.fight:id/et_bbs_content').send_keys(text) #选图 self.d.find_element_by_id('com.bugua.fight:id/emotion_thumb').click() checkbox = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') checkbox[0].click() time.sleep(1) result = self.ElementCheck.existence('name', '预览') self.ElementCheck.check_assertTrue(result, msg='选择图片后预览按钮fail') time.sleep(1) result = self.ElementCheck.existence('name', '完成(1/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) # pic_select=self.d.find_elements_by_id('com.bugua.fight:id/pic_select') # pic_select[random.choice(range(1,len(checkbox)))].click() self.ElementCheck.random_click('id', 'com.bugua.fight:id/pic_select') time.sleep(1) self.d.find_element_by_id('com.bugua.fight:id/tv_selector').click() time.sleep(1) result = self.ElementCheck.existence('name', '完成(2/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) #其他相册中进行选图 self.d.back() result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/tv_other', 'name', '所有照片') self.ElementCheck.check_assertTrue(result, msg='其他相册按钮失败') #随机选择相册 self.ElementCheck.random_click('id', 'com.bugua.fight:id/folder_name') time.sleep(1) self.ElementCheck.random_click('id', 'com.bugua.fight:id/check_box_select') result = self.ElementCheck.existence('name', '完成(3/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(1) #删除一张图片 delete = self.d.find_elements_by_id( 'com.bugua.fight:id/delete_emotion') delete[random.choice(range(0, len(delete)))].click() #提交图片 self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(10) self.d.find_element_by_name('H都谁有这种图拿出来').click() time.sleep(2) print('发现所发帖子') self.d.get_screenshot_as_file( 'C:\\Users\\yuelian\\Desktop\\DTtestresult\\tiezi.jpg') validate = self.d.find_elements_by_name(text) self.assertEqual(len(validate), 1, msg='内容输入错误') def FightPostTest(self): """发斗图帖""" #点击【发帖】按钮 self.d.find_element_by_id('com.bugua.fight:id/btn_new_topic').click() self.d.find_element_by_id( 'com.bugua.fight:id/click_type_fight').click() #标题输入框输入标题 self.d.find_element_by_id('com.bugua.fight:id/et_bbs_title').send_keys( '斗啊') #输入内容 text = '有这种图的就不要客气的拿出来吧!' self.d.find_element_by_id( 'com.bugua.fight:id/et_bbs_content').send_keys(text) #选图 self.d.find_element_by_id('com.bugua.fight:id/emotion_thumb').click() checkbox = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') checkbox[0].click() time.sleep(1) result = self.ElementCheck.existence('name', '预览') self.ElementCheck.check_assertTrue(result, msg='选择图片后预览按钮fail') time.sleep(1) result = self.ElementCheck.existence('name', '完成(1/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) # pic_select=self.d.find_elements_by_id('com.bugua.fight:id/pic_select') # pic_select[random.choice(range(1,len(checkbox)))].click() self.ElementCheck.random_click('id', 'com.bugua.fight:id/pic_select') time.sleep(1) self.d.find_element_by_id('com.bugua.fight:id/tv_selector').click() time.sleep(1) result = self.ElementCheck.existence('name', '完成(2/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) #其他相册中进行选图 self.d.back() result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/tv_other', 'name', '所有照片') self.ElementCheck.check_assertTrue(result, msg='其他相册按钮失败') #随机选择相册 self.ElementCheck.random_click('id', 'com.bugua.fight:id/folder_name') time.sleep(1) self.ElementCheck.random_click('id', 'com.bugua.fight:id/check_box_select') result = self.ElementCheck.existence('name', '完成(3/8)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(1) #删除一张图片 delete = self.d.find_elements_by_id( 'com.bugua.fight:id/delete_emotion') delete[random.choice(range(0, len(delete)))].click() time.sleep(1) self.d.get_screenshot_as_file('.\\picture\\fatiezi.jpg') self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(10) self.d.find_element_by_name('H斗啊').click() time.sleep(2) print('发现所发帖子') self.d.get_screenshot_as_file('.\\picture\\fightpost.jpg') validate = self.d.find_elements_by_name(text) self.assertEqual(len(validate), 1, msg='内容输入错误') def DiscussPostTest(self): """发讨论帖""" #点击【发帖】按钮 self.d.find_element_by_id('com.bugua.fight:id/btn_new_topic').click() self.d.find_element_by_id( 'com.bugua.fight:id/click_type_discuss').click() #标题输入框输入标题 self.d.find_element_by_id('com.bugua.fight:id/et_bbs_title').send_keys( '来看看这些好玩的图片') #输入内容 text = '有这种图的就不要客气的拿出来吧!' self.d.find_element_by_id( 'com.bugua.fight:id/et_bbs_content').send_keys(text) #选图 self.d.find_element_by_id('com.bugua.fight:id/emotion_thumb').click() checkbox = self.d.find_elements_by_id( 'com.bugua.fight:id/check_box_select') checkbox[0].click() time.sleep(1) result = self.ElementCheck.existence('name', '预览') self.ElementCheck.check_assertTrue(result, msg='选择图片后预览按钮fail') time.sleep(1) result = self.ElementCheck.existence('name', '完成(1/20)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) # pic_select=self.d.find_elements_by_id('com.bugua.fight:id/pic_select') # pic_select[random.choice(range(1,len(checkbox)))].click() self.ElementCheck.random_click('id', 'com.bugua.fight:id/pic_select') time.sleep(1) self.d.find_element_by_id('com.bugua.fight:id/tv_selector').click() time.sleep(1) result = self.ElementCheck.existence('name', '完成(2/20)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') time.sleep(1) #其他相册中进行选图 self.d.back() result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/tv_other', 'name', '所有照片') self.ElementCheck.check_assertTrue(result, msg='其他相册按钮失败') #随机选择相册 self.ElementCheck.random_click('id', 'com.bugua.fight:id/folder_name') time.sleep(1) self.ElementCheck.random_click('id', 'com.bugua.fight:id/check_box_select') result = self.ElementCheck.existence('name', '完成(3/20)') self.ElementCheck.check_assertTrue(result, msg='选择图片后计数fail') self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(1) #删除一张图片 delete = self.d.find_elements_by_id( 'com.bugua.fight:id/delete_emotion') delete[random.choice(range(0, len(delete)))].click() time.sleep(1) self.d.get_screenshot_as_file('.\\picture\\discusspost.jpg') self.d.find_element_by_id('com.bugua.fight:id/btn_submit').click() time.sleep(10) self.d.find_element_by_name('H来看看这些好玩的图片').click() time.sleep(2) print('发现所发帖子') self.d.get_screenshot_as_file('.\\picture\\fightpost.jpg') validate = self.d.find_elements_by_name(text) self.assertEqual(len(validate), 1, msg='内容输入错误')