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 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 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 DraftingTest(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.extnd = Appium_Extend(self.d) self.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() #def Fight_souch_Test(self): def Fight_most_Test(self): """制图使用最多页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击使用最多 result = self.ElementCheck.click_jump('name', '使用最多', 'name', '使用最多') self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败') def Fight_new_Test(self): """制图最近模板页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击最新模板 result = self.ElementCheck.click_jump('name', '最新模板', 'name', '最新模板') self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败') def Fight_gif_Test(self): """制图动态模板页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击动态模板 result = self.ElementCheck.click_jump('name', '动态模板', 'name', '动态模板') self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败') #点击最热 #获取最热和最新两个tab切换按钮 result = self.ElementCheck.click_change( 'classes', 'android.support.v7.app.ActionBar$Tab[1]') self.ElementCheck.check_assertTrue(result, msg='最热点击后无反应') #点击最新 #获取最热和最新两个tab切换按钮 result = self.ElementCheck.click_change( 'classes', 'android.support.v7.app.ActionBar$Tab[0]') self.ElementCheck.check_assertTrue(result, msg='最新点击后无反应') def Fight_popular_Test(self): """制图当前流行页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击当前流行 result = self.ElementCheck.click_jump('name', '当前流行') self.ElementCheck.check_assertTrue(result, msg='当前流行点击后无反应') def Classification_Test(self): """分类页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击分类 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/category_tv', 'id', 'com.bugua.fight:id/module_classify_name') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #随机点击一个分类 result = self.ElementCheck.random_click( 'id', 'com.bugua.fight:id/module_classify_card_view', 'name', '全部') self.ElementCheck.check_assertTrue(result, msg='分类失败') #点击最新 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/new_order_detail') self.ElementCheck.check_assertTrue(result, msg='最新点击后无反应') #点击热门 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/hot_order_detail') self.ElementCheck.check_assertTrue(result, msg='点击热门失败') def Page_swipe_Test(self): """制图页面滑动查看""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #向左滑动到装b区 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/show_off_tv', 'left') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #向左滑动到分类 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/category_tv') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #向左滑动到更多 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #更多向左滑动 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/more_tv', 'left', 'same') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #向右滑动到分类 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/category_tv', 'right') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #向右滑动到装b区 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/show_off_tv', 'right') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #向右滑动到斗图区 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/fight_tv', 'right') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') #斗图区向右滑动 result = self.ElementCheck.swipe_page_left_right( 'id', 'com.bugua.fight:id/fight_tv', 'right', 'same') self.ElementCheck.check_assertTrue(result, msg='滑动页面失败') def MyProductionTest(self): """制图我的制作页面""" #点击制图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/zhitu_pic', 'id', 'com.bugua.fight:id/fight_tv') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击更多 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='点击更多失败') #点击我的制作 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/make_folder', 'name', '表情包详情') self.ElementCheck.check_assertTrue(result, msg='进入我的制作页面失败') def ChangePlanTest(self): """制图改图页面""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击更多 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='点击更多失败') #点击改图 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/edit_pic', 'name', '图片') self.ElementCheck.check_assertTrue(result, msg='进入改图选图页面失败') #随机选择图片 self.ElementCheck.random_click('id', 'com.bugua.fight:id/pic_select') #对文字输入框内输入内容 time.sleep(1) self.d.find_element_by_class_name('android.widget.EditText').clear() self.d.find_element_by_class_name('android.widget.EditText').send_keys( '我们是斗图神器') #修改背景颜色 try: os._exists(r'./result') == False os.mkdir(r'./result') except: pass #点击文字背景色 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_change_bg_color', 'id', 'com.bugua.fight:id/background_options') self.ElementCheck.check_assertTrue(result, msg='文字背景选择框失灵') self.d.get_screenshot_as_file('./result/background_options.jpg') #选择透明背景 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_bg_color_2', 'id', 'com.bugua.fight:id/icon_bg_color_2') self.d.get_screenshot_as_file('./result/color2.jpg') self.ElementCheck.check_assertTrue(result, msg='透明背景失败') #选择白色背景 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_bg_color_1', 'id', 'com.bugua.fight:id/icon_bg_color_1') self.d.get_screenshot_as_file('./result/color1.jpg') self.ElementCheck.check_assertTrue(result, msg='白色背景失败') #选择吸取背景 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_bg_color_3', 'id', 'com.bugua.fight:id/btn_bg_color_3') self.d.get_screenshot_as_file('./result/color3.jpg') self.ElementCheck.check_assertTrue(result, msg='白色背景失败') #self.d.get_screenshot_as_file('./result/color3.jpg') #点击坐标位置为500,300的点 self.d.tap([(500, 300)]) self.d.get_screenshot_as_file('./result/color4.jpg') #点击字体颜色 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/btn_change_txt_color', 'id', 'com.bugua.fight:id/color_pick_area') self.ElementCheck.check_assertTrue(result, msg='字体颜色选择框失灵') #点击白色 self.d.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]' ).click() self.d.get_screenshot_as_file('./result/white.jpg') #描边 self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() self.d.get_screenshot_as_file('./result/whiteStroke.jpg') self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() #点击黑色 self.d.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[2]' ).click() self.d.get_screenshot_as_file('./result/black.jpg') #描边 self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() self.d.get_screenshot_as_file('./result/blackStroke.jpg') self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() #点击绿色 self.d.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[3]' ).click() self.d.get_screenshot_as_file('./result/green.jpg') #描边 self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() self.d.get_screenshot_as_file('./result/greenStroke.jpg') self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() #点击橘黄 self.d.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[4]' ).click() self.d.get_screenshot_as_file('./result/orange.jpg') #描边 self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() self.d.get_screenshot_as_file('./result/orangeStroke.jpg') self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() #点击红色 self.d.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[5]' ).click() self.d.get_screenshot_as_file('./result/red.jpg') #描边 self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() self.d.get_screenshot_as_file('./result/redStroke.jpg') self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click() #移动文字输入框 size = self.d.get_window_size() width = size['width'] height = size['height'] print(width, height) text1 = self.d.find_elements_by_class_name("android.widget.EditText") print(len(text1)) TouchAction(self.d).press(text1[1]).move_to(x=width * 76 / 768, y=height * 150 / 1184).release().perform() time.sleep(5) self.d.find_element_by_xpath('//android.widget.EditText[1]').click() #关闭文字框 #选取所有的android.widget.ImageView元素 text = self.d.find_elements_by_xpath("//android.widget.ImageView") #点击第三个android.widget.ImageView元素对应为开始的文字框的关闭按钮 text[2].click() self.d.get_screenshot_as_file('./result/closetext.jpg') #新建文字框 self.d.find_element_by_id('com.bugua.fight:id/btn_new').click() self.d.get_screenshot_as_file('./result/newtext.jpg') #将新建的文字框输入内容 self.d.find_element_by_xpath('//android.widget.EditText[1]').clear() self.d.find_element_by_xpath('//android.widget.EditText[1]').send_keys( '我们是斗图神器') #扩大文字框 T = self.d.find_elements_by_xpath("//android.widget.ImageView") #print(len(T)) TouchAction(self.d).long_press(T[3]).move_to(x=width * 900 / 1080, y=height * 900 / 1920).release().perform() self.d.get_screenshot_as_file('./result/bigtext.jpg') #保存 self.d.find_element_by_id('com.bugua.fight:id/btn_next').click() time.sleep(2) self.d.get_screenshot_as_file('./result/change_finsh.jpg') #点击完成按钮 self.d.find_element_by_name('完成').click() def TemplateTest(self): """制图斗图制图""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #在制图页面下选择一个模板 self.ElementCheck.random_click( 'xpath', '//android.support.v7.widget.RecyclerView/android.widget.FrameLayout' ) #选择热门配文 #第一次选择配文 content = self.ElementCheck.random_click_get_name( 'xpath', '//android.widget.ListView/android.widget.TextView') time.sleep(2) #检查所选择的配文显示的是否正确 result = self.ElementCheck.attribute_name( 'classes', 'android.widget.TextView[2]', content) self.ElementCheck.check_assertTrue(result, msg='显示错误') self.d.get_screenshot_as_file('./result/Template_text1.jpg') #下拉配文内容(至最低端) self.d.swipe(500 / 1080, 1800 / 1920, 500 / 1080, 1200 / 1920) content = self.ElementCheck.random_click_get_name( 'xpath', '//android.widget.ListView/android.widget.TextView') result = self.ElementCheck.attribute_name( 'classes', 'android.widget.TextView[2]', content) self.ElementCheck.check_assertTrue(result, msg='显示错误') #文字输入框 self.d.find_element_by_id('com.bugua.fight:id/et_text').click() time.sleep(2) self.d.get_screenshot_as_file('./result/Template_edittext.jpg') #点击清空按钮 self.d.find_element_by_id('com.bugua.fight:id/btn_clean').click() self.d.get_screenshot_as_file('./result/Template_clear.jpg') #输入内容(利用adb命令输入) os.system('adb shell input text bugua') #检查输入的配文显示的是否正确 self.d.find_element_by_xpath('//android.widget.TextView[3]').get_attribute('name')\ == 'bugua' self.d.get_screenshot_as_file('./result/Template_over.jpg') #保存 self.d.find_element_by_id('com.bugua.fight:id/btn_next').click() time.sleep(2) self.d.get_screenshot_as_file('./result/Template_finsh.jpg') def zhuangbi_test(self): """制图装逼模板""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击装b区 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/show_off_tv') self.ElementCheck.check_assertTrue(result, msg='进入装b区Fail') time.sleep(3) #点击一个分区 a = {'1': '表白', '2': '恶搞', '3': '红包', '4': '证书', '5': '游戏', '6': '炫富'} no = str(random.choice(range(1, 5))) location = str('//android.widget.TextView[@text="%s"]/..' % a[no]) print(location) self.ElementCheck.click('xpath', location) #选择模板 time.sleep(2) self.ElementCheck.random_click('xpath', '//android.widget.ImageView') time.sleep(5) #选择模板 # #随机点击今日新上中的图 # temlpe = 'com.bugua.fight:id/template'+'%d'% (random.choice(range(0,2))) # self.d.find_element_by_id(temlpe).click() #下拉屏幕到低端 time.sleep(3) size = self.d.get_window_size() w = size['width'] h = size['height'] self.d.swipe(w * 500 / 1080, h * 1800 / 1920, w * 500 / 1080, h * 100 / 1920) #寻找图片添加按钮 try: view = self.d.find_elements_by_id( 'com.bugua.fight:id/pic_add_view') for i in range(len(view)): view[i].click() time.sleep(0.5) self.ElementCheck.random_click( 'id', 'com.android.documentsui:id/icon_thumb') time.sleep(0.5) self.d.find_element_by_id('com.bugua.fight:id/cut_btn').click() except: pass try: text = self.d.find_elements_by_id('com.bugua.fight:id/input_et') print(len(text)) for i in range(len(text)): text[i].send_keys('bugua') except: pass time.sleep(0.5) self.ElementCheck.click_jump('id', 'com.bugua.fight:id/make', 'id', 'com.bugua.fight:id/btn_finish') #结果文件夹 try: os._exists(r'./result') == False os.mkdir(r'./result') except: pass self.extnd.get_screenshot_by_element( self.d.find_element_by_id( 'com.bugua.fight:id/image_preview')).write_to_file( './result', 'zhuangbi') def losts_pic_one_click1(self): """制图海量生成模板页面单击""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击更多 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='点击更多失败') #点击海量生成模板 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/lots_pic_one_click', 'name', '一键生成') self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败') #输入文字内容 self.d.find_element_by_id('com.bugua.fight:id/et_content').send_keys( 'bugua') #点击一键生成 self.d.find_element_by_id('com.bugua.fight:id/one_key_btn').click() time.sleep(5) #截取生成内容图片 try: os._exists(r'./Temp') == False os.mkdir(r'./Temp') except: pass picture = self.d.find_element_by_id('com.bugua.fight:id/recyclerView') self.extnd.get_screenshot_by_element(picture).write_to_file( './Temp', 'lost_pic') load = self.extnd.load_image('./Temp/lost_pic.png') #点击换一批 self.d.find_element_by_name('换一批').click() time.sleep(5) #对比内容 result = self.extnd.get_screenshot_by_element(picture).same_as(load, 0) self.assertFalse(result, msg='换一批失败') #选择图片分享出去 self.ElementCheck.random_click('xpath', '//android.widget.ImageView/..') #点击收藏 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/btn_save') self.ElementCheck.check_assertTrue(result, msg='收藏按钮失败') #分享到微信 self.ElementCheck.share_picture_weixin() def losts_pic_one_click2(self): """制图海量生成模板页面单击""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击更多 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='点击更多失败') #点击海量生成模板 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/lots_pic_one_click', 'name', '一键生成') self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败') #输入文字内容 self.d.find_element_by_id('com.bugua.fight:id/et_content').send_keys( 'bugua') #点击一键生成 self.d.find_element_by_id('com.bugua.fight:id/one_key_btn').click() time.sleep(5) #截取生成内容图片 try: os._exists(r'./Temp') == False os.mkdir(r'./Temp') except: pass picture = self.d.find_element_by_id('com.bugua.fight:id/recyclerView') self.extnd.get_screenshot_by_element(picture).write_to_file( './Temp', 'lost_pic') load = self.extnd.load_image('./Temp/lost_pic.png') #点击换一批 self.d.find_element_by_name('换一批').click() time.sleep(5) #对比内容 result = self.extnd.get_screenshot_by_element(picture).same_as(load, 0) self.assertFalse(result, msg='换一批失败') #选择图片分享出去 self.ElementCheck.random_click('xpath', '//android.widget.ImageView/..', 'long_pass') #点击收藏 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/btn_star') self.ElementCheck.check_assertTrue(result, msg='收藏按钮失败') #分享到微信 self.ElementCheck.share_picture_weixin() def text_gif_text(self): """制图文字表情""" #点击制图 result = self.ElementCheck.click_change( 'id', 'com.bugua.fight:id/zhitu_pic') self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败') #点击更多 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/more_tv') self.ElementCheck.check_assertTrue(result, msg='点击更多失败') #点击海量生成模板 result = self.ElementCheck.click_jump('id', 'com.bugua.fight:id/text_gif', 'name', '文字表情') self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败') #移动文字框到左上角 loction = self.d.find_element_by_id( 'com.bugua.fight:id/img_container').location size = self.d.find_element_by_id( 'com.bugua.fight:id/img_container').size #print(size) editText = self.d.find_element_by_xpath( '//*[@resource-id="com.bugua.fight:id/img_container"]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.EditText[1]' ) TouchAction(self.d).press(editText).move_to( x=loction['x'] - editText.location['x'], y=loction['y'] - editText.location['y']).perform() time.sleep(1) self.d.get_screenshot_as_file( './result/text_gif_text_move_edittext.png') #将文字框扩大到最大 button = self.d.find_element_by_xpath( '//*[@resource-id="com.bugua.fight:id/img_container"]/android.widget.FrameLayout/android.widget.ImageView' ) TouchAction(self.d).long_press(button).move_to( x=(size['width'] - button.location['x']), y=(loction['y'] + size['height'] - button.location['y'])).release().perform() time.sleep(2) self.d.get_screenshot_as_file( './result/text_gif_text_edittext_max.png') #随机选择文案 name = self.ElementCheck.random_click_get_name( 'xpath', '//android.support.v7.widget.RecyclerView/android.widget.TextView') self.assertEqual(editText.get_attribute('name'), name, '选择文案失败') #点击字体 self.ElementCheck.click_change('id', 'com.bugua.fight:id/font') #随机点击字体 #self.extnd.get_screenshot_by_element(editText).write_to_file('./Temp','editText') self.ElementCheck.random_click( 'xpath', '//*[@resource-id="com.bugua.fight:id/container"]/android.widget.LinearLayout/android.widget.FrameLayout' ) self.d.get_screenshot_as_file( './result/text_gif_text_edittext_font.png') #点击颜色 self.ElementCheck.click_change('id', 'com.bugua.fight:id/color') #随机选择颜色 #self.extnd.get_screenshot_by_element(editText).write_to_file('./Temp','editText') self.ElementCheck.random_click('id', 'com.bugua.fight:id/image') self.d.get_screenshot_as_file( './result/text_gif_text_edittext_color.png') #点击对其 self.ElementCheck.click_change('id', 'com.bugua.fight:id/align') #随机选择对齐 self.extnd.get_screenshot_by_element(editText).write_to_file( './Temp', 'editText') self.ElementCheck.random_click('id', 'com.bugua.fight:id/image') self.d.get_screenshot_as_file( './result/text_gif_text_edittext_align.png') #点击保存 self.ElementCheck.click_change('id', 'com.bugua.fight:id/right_corner_btn', 'hide') #发送到微信 self.ElementCheck.click_change('id', 'com.bugua.fight:id/share_to_wechat', 'hide') time.sleep(3) #发送给管昭 self.d.find_element_by_name('管昭').click() time.sleep(2) self.d.find_element_by_name('分享').click() time.sleep(1) self.d.find_element_by_id('com.tencent.mm:id/a7m').click()
class Edit_informationTest(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.ElementCheck = ElementCheck(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def HeadPortraitTest(self): """修改头像""" #点击【我的】按钮 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/my_tab') self.ElementCheck.check_assertTrue(result, msg='进入我的页面失败') #点击资料编辑入口 result = self.ElementCheck.click_jump( 'xpath', '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout', 'name', '编辑信息') self.ElementCheck.check_assertTrue(result, msg='进入资料编辑失败') #点击头像 result = self.ElementCheck.click_jump( 'xpath', '//android.widget.RelativeLayout/android.widget.ImageView', 'name', '最近') self.ElementCheck.check_assertTrue(result, msg='进入头像选择失败') #收集图片 result = self.ElementCheck.random_click( 'id', 'com.android.documentsui:id/icon_thumb') self.ElementCheck.check_assertTrue(result, msg='选择头像失败') self.d.get_screenshot_as_file( './result/HeadportraitTes.jpg') #其实这里可以用图片不同进行判断 def RenameTest(self): """修改昵称""" #点击【我的】按钮 result = self.ElementCheck.click_change('id', 'com.bugua.fight:id/my_tab') self.ElementCheck.check_assertTrue(result, msg='进入我的页面失败') #点击资料编辑入口 result = self.ElementCheck.click_jump( 'xpath', '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout', 'name', '编辑信息') self.ElementCheck.check_assertTrue(result, msg='进入资料编辑失败') exname = self.ElementCheck.attribute_name( 'id', 'com.bugua.fight:id/user_name') #点击昵称 result = self.ElementCheck.click_jump( 'id', 'com.bugua.fight:id/nick_name_container', 'name', '修改昵称') self.ElementCheck.check_assertTrue(result, msg='修改昵称提示框未弹出') #情况昵称输入框 self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').clear() #获取字数统计 self.assertEqual(self.ElementCheck.attribute_name( 'id', 'com.bugua.fight:id/count'), '14', msg='字是统计有问题') #随机产生输入的位数 number = random.choice(range(1, 14)) name = number * u"g" number2 = str(14 - number) #输入number个g self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').send_keys(name) #获取字数统计 self.assertEqual(self.ElementCheck.attribute_name( 'id', 'com.bugua.fight:id/count'), number2, msg='字数统计有问题') #点击确定 self.d.find_element_by_id('com.bugua.fight:id/ok').click() #点击返回 self.d.back() validate = self.d.find_elements_by_name(name) self.assertEqual(len(validate), 1, msg='名字修改未成功') #回复原来的名字 self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout').click() self.d.find_element_by_id( 'com.bugua.fight:id/nick_name_container').click() self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').clear() self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').send_keys(exname) self.d.find_element_by_id('com.bugua.fight:id/ok').click() def SexTest(self): """修改性别""" #点击【我的】按钮 self.d.find_element_by_id('com.bugua.fight:id/my_tab').click() #点击资料编辑入口 self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout').click() #点击性别 self.d.find_element_by_id( 'com.bugua.fight:id/gender_container').click() validate = self.d.find_elements_by_id('com.bugua.fight:id/male') self.assertEqual(len(validate), 1, msg='未发现性别选择按钮_男') validate = self.d.find_elements_by_id('com.bugua.fight:id/female') self.assertEqual(len(validate), 1, msg='未发现性别选择按钮_女') #点击女 self.d.find_element_by_id('com.bugua.fight:id/female').click() validate = self.d.find_elements_by_name('女') self.assertEqual(len(validate), 1, msg='性别为女修改失败') self.d.find_element_by_id( 'com.bugua.fight:id/gender_container').click() #点击男 self.d.find_element_by_id('com.bugua.fight:id/male').click() validate = self.d.find_elements_by_name('男') self.assertEqual(len(validate), 1, msg='性别为男修改失败') def SelfIntroductionTest(self): """修改自我介绍""" #点击【我的】按钮 self.d.find_element_by_id('com.bugua.fight:id/my_tab').click() #点击资料编辑入口 self.d.find_element_by_xpath( '//android.support.v7.widget.RecyclerView/' 'android.widget.LinearLayout/android.widget.LinearLayout').click() #点击自我介绍 self.d.find_element_by_id('com.bugua.fight:id/self_intro').click() self.assertEqual(self.d.find_element_by_id( 'com.bugua.fight:id/title').get_attribute('name'), '自我介绍', msg='进入自我介绍修改页面失败') #情况输入框 self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').clear() self.assertEqual(self.d.find_element_by_id( 'com.bugua.fight:id/count').get_attribute('name'), '19', msg='字数统计') #随机产生输入的位数 number = random.choice(range(1, 19)) Introduction = number * u"图" number2 = str(19 - number) #输入number个图 self.d.find_element_by_id( 'com.bugua.fight:id/edit_folder_name').send_keys(Introduction) #获取字数统计 self.assertEqual(self.d.find_element_by_id( 'com.bugua.fight:id/count').get_attribute('name'), number2, msg='字数统计有问题') self.d.find_element_by_id('com.bugua.fight:id/ok').click() #修改内容检查 self.assertEqual(self.d.find_element_by_id( 'com.bugua.fight:id/intro_tv').get_attribute('name'), Introduction, msg='编辑页面自我介绍显示有问题') self.d.back() validate = self.d.find_elements_by_name(Introduction) self.assertEqual(len(validate), 1, msg='编辑页面自我介绍显示有问题')
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='内容输入错误')