def _screenshot(name): date_time = time.strftime('%H%M%S', time.localtime(time.time())) screenshot = name + '-' + date_time + '.PNG' path = os.path.join(ReportPath().get_path(), screenshot) driver = BasePage().get_driver() driver.screenshot(path) return screenshot
def _screenshot(name): date_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) screenshot = name + '-' + date_time + '.PNG' path = ReportPath().get_path() + '\\' + screenshot driver = BasePage().get_driver() driver.save_screenshot(path) return screenshot
def _screenshot_for_gif(): tmp_path = os.path.join(ReportPath().get_path(), 'tmp') if not os.path.exists(tmp_path): os.mkdir(tmp_path) tmpshot = str(round(time.time() * 1000)) + '.PNG' path = os.path.join(tmp_path, tmpshot) driver = BasePage().get_driver() driver.screenshot(path) return path
def click_filter_btn(self, text): '''点击选择滤镜''' ele = self.d(resourceId="com.quvideo.xiaoying:id/rc_editor_filter") BasePage().find_element_by_swipe_left(self.d(text=text), ele) time.sleep(1) # 等待主题馆展开 self.d(resourceId="com.quvideo.xiaoying:id/item_fitler_child_name", text=text).click()
def click_signin_button(self): if BasePage.element_is_exists(self.d(resourceId="com.vova.android:id/tv_sign_in"), timeout=0) is False: self.find_element_by_swipe_down(self.d(resourceId="com.vova.android:id/tv_sign_in")) self.d(resourceId="com.vova.android:id/tv_sign_in").click() log.i("点击SIGN IN按钮") self.d(resourceId="com.vova.android:id/tv_sign_in").wait_gone(timeout=1.0) if self.d(resourceId="com.vova.android:id/tv_sign_in").click_exists(timeout=1.0): log.i("二次点击SIGN IN按钮") # 兼容低概率点不上的bug
def _run_maxim(run, cases, command, actions, widget_black): log = Log() log.set_logger(run.get_device()['model'], os.path.join(run.get_path(), 'client.log')) log.i('udid: %s', run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) else: base_page.set_driver(run.get_device()['serial']) try: # run cases base_page.d.shell('logcat -c') # 清空logcat if cases: run.run_cases(cases) Maxim().run_monkey(monkey_shell=command, actions=actions, widget_black=widget_black) base_page.d.shell('logcat -d > /sdcard/logcat.log') time.sleep(1) base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log')) base_page.d.pull('/sdcard/monkeyerr.txt', os.path.join(path.get_path(), 'monkeyerr.txt')) base_page.d.pull('/sdcard/monkeyout.txt', os.path.join(path.get_path(), 'monkeyout.txt')) base_page.set_original_ime() base_page.identify() if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]: log.i('release device %s ' % run.get_device()['serial']) atxserver2(ReadConfig().get_server_url()).release_device( run.get_device()['serial']) else: pass except AssertionError as e: log.e('AssertionError, %s', e)
def click_setting_button(self): if BasePage.element_is_exists(self.d(text="YOU MIGHT LIKE"), timeout=0) is False: self.find_element_by_swipe_up(self.d(text="YOU MIGHT LIKE")) # 往下拉一拉再点,兼容点不上的情况 log.i("经上滑已发现setting位置") self.d(resourceId="com.vova.android:id/tv_setting", text='Settings').click() log.i("点击Setting按钮") self.d(resourceId="com.vova.android:id/tv_setting", text='Settings').wait_gone(timeout=1.0) if self.d(resourceId="com.vova.android:id/tv_setting", text='Settings').click_exists(timeout=1.0): log.i("二次点击Setting按钮") # 兼容低概率点不上的bug
def _run_cases(run, cases): log = Log() log.set_logger(run.get_device()['model'], run.get_path() + '/' + 'client.log') log.i('udid: %s', run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() base_page.set_driver(run.get_device()['ip']) try: # run cases run.run(cases) except AssertionError as e: log.e('AssertionError, %s', e)
def _run_cases(server_url, run, cases): log = Log() # Windows # log.set_logger(run.get_device()['udid'], run.get_path() + '\\' + 'client.log') # MacOS log.set_logger(run.get_device()['udid'], run.get_path() + '/' + 'client.log') log.i('platformName: %s', run.get_device()['platformName']) log.i('udid: %s', run.get_device()['udid']) # log.i('package: %s\n', run.get_device()['package']) log.i('bundleId: %s\n', run.get_device()['bundleId']) log.i('autoAcceptAlerts: %s\n', run.get_device()['autoAcceptAlerts']) log.i('macaca server port: %d\n', run.get_port()) # init driver driver = WebDriver(run.get_device(), server_url) driver.init() # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) login_status = LoginStatus() login_status.set_status(False) # set cls.driver, it must be call before operate on any page base_page = BasePage() base_page.set_driver(driver) try: # skip wizard # if not into home page will raise AssertionError skip_wizard_to_home() # run cases run.run(cases) except AssertionError as e: log.e('AssertionError, %s', e) # quit driver driver.quit()
def click_my_orders_button(self): if BasePage.element_is_exists( self.d(resourceId="com.vova.android:id/tv_my_orders_view_all"), timeout=1) is False: self.find_element_by_swipe_down(self.d(resourceId="com.vova.android:id/tv_my_orders_view_all")) time.sleep(.5) self.d(resourceId="com.vova.android:id/tv_my_orders_view_all").click() log.i("点击orders列表按钮") self.d(resourceId="com.vova.android:id/tv_my_orders_view_all").wait_gone(timeout=1.0) if self.d(resourceId="com.vova.android:id/tv_my_orders_view_all").click_exists(timeout=1.0): log.i("二次点击orders列表按钮") # 兼容低概率点不上的bug
def select_filter(self, text="原图"): '''选择滤镜卷,并点击展开滤镜卷''' ele = self.d(resourceId="com.quvideo.xiaoying:id/rc_editor_filter") BasePage().find_element_by_swipe_left(self.d(text=text), ele, max_swipe=15) time.sleep(1) self.d(resourceId="com.quvideo.xiaoying:id/item_fitler_parent_name", text=text).click() time.sleep(3) # 等待下载完成
def test_04_click_to_top(self): '''点击击我Tab均可返回当前页顶部并刷新 ##查看截图''' log.i('点击击我Tab均可返回当前页顶部并刷新') creation.creation_page().click_my_btn() for i in range(5): BasePage().swipe_up(steps=0.05) log.i('点击前截图') self.screenshot() creation.creation_page().click_my_btn() log.i('点击后截图') self.screenshot()
def test_03_back_top(self): '''上移页面可收起个人信息栏,点击一键回顶部的按钮,可返回视频列表顶部 ##查看截图''' log.i('上移页面可收起个人信息栏,点击一键回顶部的按钮') creation.creation_page().click_my_btn() for i in range(5): BasePage().swipe_up(steps=0.05) log.i('点击前截图') self.screenshot() community.userinfo_page().click_back_top_btn() log.i('点击后截图') self.screenshot()
def _run_cases(server_url, run, cases, index): log = Log() log.set_logger(run.get_device()['udid'], run.get_path() + '/' + 'client.log') log.i('platformName: %s', run.get_device()['platformName']) log.i('udid: %s', run.get_device()['udid']) log.i('app: %s', run.get_device()['app']) log.i('reuse: %s\n', run.get_device()['reuse']) # log.i('autoAcceptAlerts: %s', run.get_device()['autoAcceptAlerts']) log.i('macaca server port: %d\n', run.get_port()) # init driver driver = WebDriver(run.get_device(), server_url) driver.init() # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # login_status = LoginStatus() # login_status.set_status(False) # set cls.driver, it must be call before operate on any page base_page = BasePage() base_page.set_driver(driver) base_page.set_index(index) try: # run cases run.run(cases) except AssertionError as e: log.e('AssertionError, %s', e) # quit driver driver.quit()
def drive(server_url, run): log = Log() log.set_logger(run.get_device()['udid'], run.get_path() + '\\' + 'client.log') log.i('platformName: %s', run.get_device()['platformName']) log.i('udid: %s', run.get_device()['udid']) log.i('package: %s\n', run.get_device()['package']) log.i('macaca server port: %d\n', run.get_port()) # init driver driver = WebDriver(run.get_device(), server_url) driver.init() # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() base_page.set_driver(driver) while True: cmd = input("Please input run or exit:").lower() if cmd == 'run': print('Run run.py') print(os.system('python run.py %s %s %s %s' % (run.get_port(), run.get_device()['udid'], run.get_path(), driver.session_id ) ) ) elif cmd == 'exit': print('Good Bye') break # quit driver driver.quit()
def init(): port = int(sys.argv[1]) udid = sys.argv[2] report_path = str(sys.argv[3]) session = sys.argv[4] server_url = { 'hostname': '127.0.0.1', 'port': port, } log = Log() log.set_logger(udid, report_path + '\\' + 'client.log') driver = WebDriver('', server_url) driver.attach(session) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(report_path) # set cls.driver, it must be call before operate on any page base_page = BasePage() base_page.set_driver(driver)
def setUpClass(cls): cls.driver = BasePage().get_driver() cls.index = BasePage().get_index()
#!/usr/bin/env python # -*- coding: utf-8 -*- import time import uiautomator2 as u2 from Public.chromedriver import ChromeDriver #将chromedriver.py和该脚本放在同一目录下 from Public.BasePage import BasePage base_page = BasePage() base_page.set_driver('10.0.31.63') d = base_page.get_driver() # d.app_stop('com.github.android_app_bootstrap') # d.app_start('com.github.android_app_bootstrap') # d(text='Login').click() # d(text='Baidu').click() # time.sleep(3) driver = ChromeDriver(d).driver() driver.find_element_by_id('index-kw').click() driver.find_element_by_id('index-kw').send_keys('Python') time.sleep(3) driver.find_element_by_id('index-bn').click() driver.quit() ChromeDriver(d).windows_kill()
# 私信 community.userinfo_page().select_more_action("私信") self.assertTrue(login.login_page().is_login_page()) self.back() # 拉黑 community.userinfo_page().select_more_action("直接拉黑") self.assertTrue(login.login_page().is_login_page()) self.back() @testcase def test_03_login(self): '''小影账号登录''' creation.creation_page().click_my_btn() login.login_page().click_login_btn() login.login_page().click_qq() self.assertTrue( self.d( resourceId="com.quvideo.xiaoying:id/studio_title_text").wait()) self.screenshot() if __name__ == '__main__': from Public.Log import Log Log().set_logger('udid', './log.log') BasePage().set_driver('10.0.29.65') suite = unittest.TestSuite() suite.addTest(community_not_login('test_02_jump_login')) runner = unittest.TextTestRunner() runner.run(suite)
info = community.fans_follow_list_page().get_info() log.i(info) community.fans_follow_list_page().click_avatar() title = community.userinfo_page().get_user_info() self.assertEqual(info[0], title) self.back() community.fans_follow_list_page().click_follow_btn() new_info = community.fans_follow_list_page().get_info() log.i('点击关注之后的信息:%s' % str(new_info)) self.assertIsNot(info[2], new_info[2]) if __name__ == '__main__': from Public.Log import Log Log().set_logger('udid', './log.log') BasePage().set_driver(None) # d = BasePage().get_driver() # d.app_start("com.quvideo.xiaoying") suite = unittest.TestSuite() suite.addTest(community_userinfo('test_01_getinfo')) suite.addTest(community_userinfo('test_01_getinfo')) suite.addTest(community_userinfo('test_02_tab_action')) suite.addTest(community_userinfo('test_03_back_top')) suite.addTest(community_userinfo('test_04_click_to_top')) suite.addTest(community_userinfo('test_05_click_fans_btn')) suite.addTest(community_userinfo('test_06_follow')) suite.addTest(community_userinfo('test_07_fans')) runner = unittest.TextTestRunner() runner.run(suite)
def setUpClass(cls): cls.driver = BasePage().get_driver()
def _run_cases(run, cases): log = Log() log.set_logger(run.get_device()['model'], run.get_path() + '/' + 'client.log') log.i('udid: %s', run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() # base_page.set_driver(run.get_device()['ip']) if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) else: base_page.set_driver(run.get_device()['serial']) try: # run cases base_page.set_fastinput_ime() run.run(cases) base_page.set_original_ime() base_page.unwatch_device() base_page.identify() except AssertionError as e: log.e('AssertionError, %s', e)
def _run_cases(run, cases): log = Log() log.set_logger(run.get_device()['model'], run.get_path() + '/' + 'client.log') log.i('udid: %s' % run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() # base_page.set_driver(run.get_device()['ip']) if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) else: base_page.set_driver(run.get_device()['serial']) try: # 运行前准备 base_page.set_fastinput_ime() # 设置fastime输入法 # base_page.d.shell('rm -rf /sdcard/DCIM/XiaoYingLite') # 删除之前的导出视频 # base_page.d.shell('rm -rf /sdcard/XiaoYingLite') # 删除之前的导出视频 base_page.d.shell('logcat -c') # 清空logcat # 开始执行测试 run.run(cases) # 结束后操作 base_page.unwatch_device() base_page.set_original_ime() base_page.identify() # 将logcat文件上传到报告 base_page.d.shell('logcat -d > /sdcard/logcat.log') time.sleep(2) base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log')) time.sleep(5) if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]: log.i('release device %s ' % run.get_device()['serial']) atxserver2(ReadConfig().get_server_url()).release_device( run.get_device()['serial']) else: pass except AssertionError as e: log.e('AssertionError, %s' % e)
def _run_cases(run, cases): log = Log() log.set_logger(run.get_device()['model'], os.path.join(run.get_path(), 'client.log')) log.i('udid: %s' % run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) else: base_page.set_driver(run.get_device()['serial']) try: # run cases base_page.set_fastinput_ime() base_page.d.shell('logcat -c') # 清空logcat run.run(cases) # 将logcat文件上传到报告 base_page.d.shell('logcat -d > /sdcard/logcat.log') time.sleep(1) base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log')) base_page.set_original_ime() base_page.identify() if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]: log.i('release device %s ' % run.get_device()['serial']) atxserver2(ReadConfig().get_server_url()).release_device( run.get_device()['serial']) else: pass except AssertionError as e: log.e('AssertionError, %s', e)
:Usage: is_toast_exist(driver, "toast消息的内容") """ try: toast_loc = ("xpath", ".//*[contains(@text,'%s')]" % text) WebDriverWait(driver, timeout, poll_frequency).until( expected_conditions.presence_of_element_located(toast_loc)) return True except Exception as e: print('Cannot find toast \n %s' % e) return False if __name__ == '__main__': base_page = BasePage() base_page.set_driver('10.0.31.63') d = base_page.get_driver() d(text='Show Dialog').click() time.sleep(0.3) base_page.is_toast_exist("Hello")
def preview_swipe_right(self): '''预览页左滑动''' ele = self.d(resourceId="com.quvideo.xiaoying:id/preview_layout") BasePage().swipe_right(ele)
def effect_view_swipe_rigth(self): '''素材效果页seekbar右滑''' ele = self.d( resourceId="com.quvideo.xiaoying:id/video_editor_seek_gallery") BasePage().swipe_right(ele)