def test_music_02_recommend(self): """音乐库-推荐音乐下载.""" sc.logger.info('音乐库-推荐音乐下载') fun_name = 'test_preview_recommend' sc.logger.info('点击“添加配乐”按钮') WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("添加配乐")).click() # 推荐音乐下载 sc.logger.info('向上滑动') start_x = self.width // 2 start_y = self.height // 8 start_bottom = self.height - start_y for i in range(2): sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.7, 300) sc.logger.info('下载音乐') sc.driver.find_element_by_xpath(iOS_elements.el_mus_download).click() # music_list = sc.driver.find_elements_by_name(iOS_elements.el_mus_download) # if len(music_list) >= 3: # music_list = music_list[:3] # for el_music in music_list: # el_music.click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('音乐库-推荐音乐下载测试完成')
def home_first_click(el_fun): ''' 从创作页面进入各个入口. :param fun: 打开的入口 :param el: 点击的控件 :return: ''' """ 视频剪辑/高清拍摄/次要功能位置相关/更多草稿等 """ sc.logger.info('点击创作中心主按钮') home_enter() sc.logger.info('点击 %s', el_fun) try: WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name(el_fun)).click() except TimeoutException: sc.logger.info('向左滑动') el_template = sc.driver.find_element_by_name('素材中心') coord_x = el_template.location.get('x') coord_y = el_template.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.6, 500) # 从素材中心向左滑动 WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name(el_fun)).click()
def swipe_left(el_loc, ratio, duration): ''' 以某个元素作为标准点,左滑动 :param el_loc: 某标准点元素 :param ratio: 滑动距离与屏幕的比例,范围0到1 :param duration: 滑动时间,单位ms :return: ''' sc.logger.info('向左滑动') coord_x = el_loc.location.get('x') coord_y = el_loc.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', ratio, duration) # 从素材中心向左滑动
def test_template_06_sticker(self): """素材中心-动画贴纸.""" sc.logger.info('素材中心-动画贴纸') fun_name = 'test_template_sticker' sc.logger.info('向上滑动') el_text = sc.driver.find_element_by_name("字体") coord_x = el_text.location.get('x') coord_y = el_text.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'up', 0.7, 500) sc.logger.info('点击“动画贴纸”') WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name('动画贴纸')).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('下载并使用动画贴纸') ba.material_used(iOS_elements.el_store_download1) sc.capture_screen(fun_name, self.img_path) sc.logger.info('添加"视频"') ba.gallery_clip_add('视频', 2) sc.logger.info('点击下一步进入预览页') ba.find_element_click('predicate', 10, iOS_elements.el_gallery_next) sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“确认”') ba.effect_add_confirm() sc.logger.info('返回创作页') ba.back_to_home() ba.home_first_click('素材中心') sc.logger.info('向上滑动') el_text = sc.driver.find_element_by_name("字体") coord_x = el_text.location.get('x') coord_y = el_text.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'up', 0.7, 500) sc.logger.info('点击“动画贴纸”') WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name('动画贴纸')).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('删除下载的动画贴纸') ba.material_manager('动画贴纸', iOS_elements.el_store_del) sc.capture_screen(fun_name, self.img_path) sc.logger.info('素材中心-动画贴纸测试完成')
def home_enter(): sc.logger.info('点击创作中心主按钮') try: WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_accessibility_id( iOS_elements.el_home_create)).click() except TimeoutException: sc.logger.info('当前已经是在创作页面') sc.logger.info('下拉刷新') start_x = width // 2 start_bottom = height // 2 sc.swipe_by_ratio(start_x, start_bottom, 'down', 0.3, 500)
def clip_mult_select(): '''多选-删除''' sc.logger.info('工具栏左滑一些') el_t = sc.driver.find_element_by_name("转场") coord_x = el_t.location.get('x') coord_y = el_t.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.5, 600) sc.logger.info('删除镜头') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("删除")).click() sc.logger.info('确认删除') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("确认")).click()
def test_music_01(self): """拍摄-音乐视频(3:4)-音频下载.""" sc.logger.info('拍摄-音乐视频(3:4)-音频下载') fun_name = 'test_music_download' sc.logger.info('点击音乐视频') ba.home_first_click('音乐视频') # 第一次从次要功能位打开音乐视频,拍摄按钮是另一个控件,所以先关闭再打开 sc.logger.info('退出拍摄') time.sleep(0.5) WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name( iOS_elements.el_cam_close)).click() # 退回首页后,常无法再次获取到音乐视频控件,此处重启一次app sc.logger.info('重启app') sc.driver.close_app() time.sleep(1) sc.driver.launch_app() sc.logger.info('点击音乐视频') ba.home_first_click('音乐视频') sc.logger.info('切换到3:4拍摄') time.sleep(1) ba.find_element_click('name', 5, iOS_elements.el_ful) sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“点击添加配乐”按钮') sc.driver.find_element_by_name("点击添加配乐").click() time.sleep(2) sc.logger.info('下拉刷新') start_x = self.width // 2 start_bottom = self.height // 5 sc.swipe_by_ratio(start_x, start_bottom, 'down', 0.3, 300) sc.logger.info('下载音乐') sc.driver.find_element_by_xpath(iOS_elements.el_mus_download).click() time.sleep(10) sc.logger.info('拍摄-音乐视频(3:4)-音频下载完成')
def test_fans_list(self): """粉丝页面上下滑动测试.""" sc.logger.info('用户空间作品页面上下滑动测试开始') fun_name = 'test_fans_list' start_x = self.width // 2 start_y = self.height // 4 start_bottom = self.height - start_y time.sleep(1) # 先上滑 sc.logger.info('上滑截图开始') result_up = sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.7, 300) time.sleep(1) sc.capture_screen(fun_name, self.img_path) # 再下滑,同理 sc.logger.info('下滑截图开始') result_down = sc.swipe_by_ratio(start_x, start_y, 'down', 0.3, 300) time.sleep(1) sc.capture_screen(fun_name, self.img_path) assert result_up and result_down is True
def refresh(direct, ratio, duration, times=1): ''' 刷新 :param direct: 滑动方向,只支持'up'、'down'两种方向参数 :param ratio: 滑动距离与屏幕的比例,范围0到1 :param duration:滑动时间,单位ms :param times: 滑动次数,默认1次 :return: ''' start_x = width // 2 start_y = height // 8 start_bottom = height - start_y if direct == 'down': for i in range(times): sc.logger.info('第 %d 次下拉刷新', i) sc.swipe_by_ratio(start_x, start_y, 'down', ratio, duration) time.sleep(.500) elif direct == 'up': for i in range(times): sc.logger.info('第 %d 次上滑动', i) sc.swipe_by_ratio(start_x, start_bottom, 'up', ratio, duration) time.sleep(.500)
def test_template_08_transition(self): """素材中心-转场.""" sc.logger.info('素材中心-转场') fun_name = 'test_template_transition' start_x = self.width // 2 start_y = self.height // 8 start_bottom = self.height - start_y sc.logger.info('向上滑动') el_text = sc.driver.find_element_by_name("字体") coord_x = el_text.location.get('x') coord_y = el_text.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'up', 0.7, 500) sc.logger.info('点击“转场”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name('转场')).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('向上滑动直到最底部') while True: try: sc.driver.find_element_by_name("没有更多了…").click() break except NoSuchElementException: sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.7, 300) sc.logger.info('下载并使用转场') ba.material_used(iOS_elements.el_store_download1) sc.capture_screen(fun_name, self.img_path) sc.logger.info('添加"视频"') ba.gallery_clip_add('视频', 2) sc.logger.info('点击下一步进入预览页') ba.find_element_click('predicate', 10, iOS_elements.el_gallery_next) sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('返回创作页') ba.back_to_home() ba.home_first_click('素材中心') sc.logger.info('向上滑动') el_text = sc.driver.find_element_by_name("字体") coord_x = el_text.location.get('x') coord_y = el_text.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'up', 0.7, 500) sc.logger.info('点击“转场”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name('转场')).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('删除下载的转场') ba.material_manager('转场', iOS_elements.el_store_del) sc.capture_screen(fun_name, self.img_path) sc.logger.info('素材中心-动画贴纸测试完成')
def test_edit_filter(self): """剪辑-滤镜下载/使用.""" sc.logger.info('剪辑-滤镜下载/使用') fun_name = 'test_edit_filter' start_x = self.width // 2 start_y = self.height // 8 start_bottom = self.height - start_y sc.logger.info('打开一个草稿视频') ba.home_first_click('更多草稿') sc.logger.info('点击草稿封面') ba.open_draft(iOS_elements.el_studio_draft) sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“镜头编辑”') WebDriverWait(sc.driver, 5, 1).until( lambda x: x.find_element_by_name("镜头编辑")).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击"滤镜"') WebDriverWait(sc.driver, 5, 1).until( lambda x: x.find_element_by_name("滤镜")).click() sc.logger.info('下载更多') try: sc.driver.find_element_by_name('下载更多').click() except NoSuchElementException: sc.logger.info('右滑一些,再选择下载更多') el_fliter = sc.driver.find_element_by_name("缓流") coord_x = el_fliter.location.get('x') coord_y = el_fliter.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'right', 0.5, 500) sc.driver.find_element_by_name('下载更多').click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('下拉刷新') ba.refresh('down', 0.3, 500, 1) sc.logger.info('下载并使用滤镜') while True: try: sc.driver.find_element_by_name(iOS_elements.el_store_download2).click() break except NoSuchElementException: sc.logger.info('当前页面已无未下载主题') sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.5, 300) sc.logger.info('使用滤镜') WebDriverWait(sc.driver, 20, 1).until( lambda x: x.find_element_by_name("使用")).click() WebDriverWait(sc.driver, 5, 1).until( lambda x: x.find_element_by_name("应用于全部镜头")).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('点击“存草稿”按钮') WebDriverWait(sc.driver, 5, 1).until( lambda el: el.find_element_by_name("存草稿")).click() sc.logger.info('剪辑-滤镜下载/使用测试完成')
def test_normal_01_filter(self): """拍摄-滤镜下载.""" sc.logger.info('拍摄-滤镜下载') fun_name = 'test_normal_filter_download' start_x = self.width // 2 start_y = self.height // 8 start_bottom = self.height - start_y sc.logger.info('点击创作中心主按钮') ba.home_enter() sc.logger.info('点击“高清拍摄”按钮') try: WebDriverWait(sc.driver, 3, 1).until(lambda x: x.find_element_by_xpath( iOS_elements.home_camera)).click() except TimeoutException: WebDriverWait(sc.driver, 3, 1).until(lambda x: x.find_element_by_xpath( iOS_elements.el_home_camera)).click() sc.logger.info('点击滤镜图标') time.sleep(1) try: WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name( iOS_elements.el_filter_icon)).click() except TimeoutException: sc.logger.info('滤镜列表已自动弹出') sc.capture_screen(fun_name, self.img_path) sc.logger.info('下载滤镜') try: sc.logger.info('点击下载按钮') sc.driver.find_element_by_xpath( iOS_elements.el_filter_download).click() sc.capture_screen(fun_name, self.img_path) try: sc.driver.find_element_by_name('取消').click() except NoSuchElementException: sc.logger.info('该滤镜不是解锁滤镜') except NoSuchElementException: sc.logger.info('当前页面已无未下载滤镜') sc.logger.info('下载更多') try: time.sleep(0.5) sc.driver.find_element_by_name(iOS_elements.el_filter_more).click() sc.capture_screen(fun_name, self.img_path) except NoSuchElementException: sc.logger.info('当前页面是vip订阅页面') sc.driver.find_element_by_name(iOS_elements.el_vip_close).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('重新点击下载更多') sc.driver.find_element_by_name(iOS_elements.el_filter_more).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('下载并使用滤镜') while True: try: sc.driver.find_element_by_name( iOS_elements.el_store_download2).click() break except NoSuchElementException: sc.logger.info('当前页面已无未下载主题') sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.5, 300) sc.logger.info('使用滤镜') WebDriverWait(sc.driver, 20, 1).until(lambda x: x.find_element_by_name("使用")).click() sc.logger.info('退出拍摄') ba.find_element_click('name', 5, iOS_elements.el_cam_close) sc.logger.info('拍摄-滤镜下载测试完成')
def clip_fun_loop(): """剪辑-镜头编辑-功能遍历.""" sc.logger.info('点击“镜头编辑”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("镜头编辑")).click() video_flag = 0 sc.logger.info('镜头编辑-滤镜') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("滤镜")).click() sc.logger.info('下载更多') try: sc.driver.find_element_by_name('下载更多').click() except NoSuchElementException: sc.logger.info('右滑一些,再选择下载更多') el_fliter = sc.driver.find_element_by_name("缓流") coord_x = el_fliter.location.get('x') coord_y = el_fliter.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'right', 0.5, 500) sc.driver.find_element_by_name('下载更多').click() sc.logger.info('下拉刷新') refresh('down', 0.3, 500, 1) sc.logger.info('下载并使用滤镜') while True: try: sc.driver.find_element_by_name( iOS_elements.el_store_download2).click() break except NoSuchElementException: sc.logger.info('当前页面已无未下载主题') sc.logger.info('使用滤镜') WebDriverWait(sc.driver, 20, 1).until(lambda x: x.find_element_by_name("使用")).click() WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("应用于全部镜头")).click() sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('镜头编辑-比例') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("比例和背景")).click() sc.logger.info('切换到"比例tab"') try: WebDriverWait(sc.driver, 5, 1).until( lambda x: x.find_element_by_name(iOS_elements.btn_bg_pro)).click() except TimeoutException: sc.logger.info('已经在"比例tab"') sc.logger.info('剪辑-切换1:1比例') el_proportion = "vivavideo_edit_icon_proportion_1_1" clip_proportion(el_proportion) sc.logger.info('镜头编辑-图片时长') try: sc.logger.info('点击“图片时长”') WebDriverWait( sc.driver, 3, 1).until(lambda x: x.find_element_by_name("图片时长")).click() sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() except TimeoutException: video_flag = 1 sc.logger.info('当前镜头是视频,不支持时长') sc.logger.info('镜头编辑-修剪') if video_flag == 1: sc.logger.info('点击“修剪”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("修剪")).click() sc.logger.info('点击“剪除”') try: WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("剪中间")).click() except TimeoutException: WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("剪除")).click() sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('镜头编辑-分割') if video_flag == 1: sc.logger.info('点击“分割”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("分割")).click() sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('剪辑-镜头编辑-复制') sc.driver.find_element_by_name("复制").click() sc.logger.info('工具栏左滑一些') el_copy = sc.driver.find_element_by_name("复制") coord_x = el_copy.location.get('x') coord_y = el_copy.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.5, 500) sc.logger.info('镜头编辑-变速') if video_flag == 1: sc.logger.info('点击"变速"') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("变速")).click() sc.logger.info('应用于全部镜头') sc.driver.find_element_by_name('应用于全部镜头').click() sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() sc.logger.info('镜头编辑-调色') sc.logger.info('点击“调色”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("调色")).click() sc.logger.info('点击“取消”') sc.driver.find_element_by_name(iOS_elements.el_cancel_btn).click() sc.logger.info('工具栏左滑一些') el_adjuest = sc.driver.find_element_by_name("调色") coord_x = el_adjuest.location.get('x') coord_y = el_adjuest.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.5, 500) sc.logger.info('镜头编辑-镜头倒放') if video_flag == 1: clip_reverse() sc.logger.info('剪辑-镜头编辑-静音') WebDriverWait(sc.driver, 10, 1).until(lambda x: x.find_element_by_name("静音")).click() sc.logger.info('工具栏左滑一些') el_mute = sc.driver.find_element_by_name("静音") coord_x = el_mute.location.get('x') coord_y = el_mute.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.5, 500) sc.logger.info('镜头编辑-旋转') sc.logger.info('点击“旋转”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("旋转")).click() sc.logger.info('镜头编辑-转场') sc.logger.info('点击“转场”') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("转场")).click() try: WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("应用于全部镜头")).click() except TimeoutException: sc.logger.info('只有一个镜头,无法添加转场') return True sc.logger.info('下载更多') more_download('下载更多') sc.logger.info('选择一个"转场"使用') try: WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_xpath( iOS_elements.btn_transition_cho)).click() except TimeoutException: sc.logger.info('选择一个"转场"下载') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name( iOS_elements.btn_transition_download)).click() sc.logger.info('使用') WebDriverWait(sc.driver, 10, 1).until(lambda x: x.find_element_by_xpath( iOS_elements.btn_transition_cho)).click() sc.logger.info('点击“确认”') WebDriverWait(sc.driver, 10, 1).until( lambda x: x.find_element_by_name(iOS_elements.el_confirm_btn)).click() try: sc.logger.info('点击“确认”') sc.driver.find_element_by_name(iOS_elements.el_confirm_btn).click() except NoSuchElementException: sc.logger.info('只有一个镜头,无法应用转场') sc.logger.info('工具栏左滑一些') el_t = sc.driver.find_element_by_name("转场") coord_x = el_t.location.get('x') coord_y = el_t.location.get('y') sc.swipe_by_ratio(coord_x, coord_y, 'left', 0.5, 600) sc.logger.info('剪辑-镜头编辑-图片动画') if video_flag == 0: sc.logger.info('点击“图片动画”') WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("图片动画")).click() sc.logger.info('剪辑-镜头编辑-多选') WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("多选")).click() WebDriverWait(sc.driver, 5, 1).until( lambda x: x.find_element_by_name(iOS_elements.el_multi_reset)).click()
def feedback(): """设置-意见反馈""" try: WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("+ 新建反馈")).click() except TimeoutException: sc.logger.info("第一次反馈") sc.logger.info("填写问题") el_question = sc.driver.find_element_by_ios_predicate( "type == 'XCUIElementTypeTextView'") el_question.clear() el_question.send_keys("just for ios test") try: WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_xpath( "//XCUIElementTypeButton[@name='Done']")).click() except TimeoutException: sc.logger.info("当前键盘为中文键盘") sc.driver.find_element_by_xpath("完成").click() sc.logger.info("选择问题分类") WebDriverWait( sc.driver, 5, 1).until(lambda x: x.find_element_by_name("告诉我们该问题属于哪一类(可选)")).click() sc.logger.info("滑动选择问题分类") start_x = width // 2 start_bottom = height - height // 10 sc.swipe_by_ratio(start_x, start_bottom, 'up', 0.2, 500) sc.driver.find_element_by_xpath( "//XCUIElementTypeButton[@name='完成']").click() sc.logger.info("提供截图") sc.driver.find_element_by_xpath( "//XCUIElementTypeImage[@name='icon_add_nrm']").click() sc.logger.info("取消添加截图") WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_name("取消")).click() sc.logger.info("输入联系方式") el_contact = sc.driver.find_elements_by_ios_predicate( "type == 'XCUIElementTypeTextField'") for contact in el_contact: if contact.text == u'QQ': contact.send_keys("245603638") break for contact in el_contact: if contact.text == u'手机号': contact.send_keys("15857154810") break sc.logger.info("保存联系方式") WebDriverWait(sc.driver, 5, 1).until(lambda x: x.find_element_by_xpath( "//XCUIElementTypeButton[@name='Done']")).click() sc.logger.info("提交反馈") sc.driver.find_element_by_xpath( "//XCUIElementTypeButton[@name='提交']").click()