def tearDown(self): # Record timestamp t2 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) if 't2' not in timestamp: timestamp['t2'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp)) # capture 2nd snapshot time.sleep(5) recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled and self.index_config.get('snapshot-base-sample2', False) is True: videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_2_fp, self.env.img_sample_dp, self.env.img_output_sample_2_fn) # Stop profiler and save profile data self.profilers.stop_profiling(self.profile_dir_path) # Stop browser if self.exec_config['keep-browser'] is False: desktopHelper.close_browser(self.browser_type) super(PerfBaseTest, self).tearDown()
def tearDown(self): # Record timestamp t2 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) if 't2' not in timestamp: timestamp['t2'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp)) # capture 2nd snapshot time.sleep(5) if self.index_config['snapshot-base-sample2']: videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_2_fp, self.env.img_sample_dp, self.env.img_output_sample_2_fn) # Stop profiler and save profile data self.profilers.stop_profiling(self.profile_dir_path) # Stop browser if self.exec_config['keep-browser'] is False: self.wd.close_browser(self.browser_type) super(WebdriverBaseTest, self).tearDown()
def tearDown(self): # Record timestamp t2 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) if 't2' not in timestamp: timestamp['t2'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp)) # capture 2nd snapshot time.sleep(5) if self.env.PROFILER_FLAG_AVCONV in self.env.firefox_settings_extensions: if self.env.firefox_settings_extensions[self.env.PROFILER_FLAG_AVCONV]['enable'] is True and self.index_config['snapshot-base-sample2'] is True: videoHelper.capture_screen(self.env, self.index_config, self.env.video_output_sample_2_fp, self.env.img_sample_dp, self.env.img_output_sample_2_fn) # Stop profiler and save profile data self.profilers.stop_profiling(self.profile_dir_path) # Stop browser if self.exec_config['keep-browser'] is False: desktopHelper.close_browser(self.browser_type) super(PerfBaseTest, self).tearDown()
def get_browser_done(self): # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled: for i in range(10): time.sleep(1) logger.debug("Check browser show up %d time(s)." % (i + 1)) desktopHelper.lock_window_pos(self.browser_type) videoHelper.capture_screen(self.env, self.index_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) if desktopHelper.check_browser_show_up( self.env.img_sample_dp, self.env.img_output_sample_1_fn): logger.debug("Browser shown, adjust viewport by setting.") height_browser, width_browser = desktopHelper.adjust_viewport( self.browser_type, self.env.img_sample_dp, self.env.img_output_sample_1_fn) height_offset = 0 terminal_width = width_browser terminal_height = 60 if sys.platform == 'linux2': height_offset = 20 terminal_height = 60 elif sys.platform == 'win32': import platform release_version = platform.release() if release_version == '10': logger.info("Move terminal window for Windows 10.") height_offset = -4 terminal_height = 100 elif release_version == '7': logger.info("Move terminal window for Windows 7.") height_offset = 0 terminal_height = 80 else: logger.info("Move terminal window for Windows.") height_offset = 0 terminal_height = 80 elif sys.platform == 'darwin': # TODO: This offset settings only be tested on Mac Book Air height_offset = 25 terminal_height = 80 terminal_x = 0 terminal_y = height_browser + height_offset logger.info( 'Move Terminal to (X,Y,W,H): ({}, {}, {}, {})'.format( terminal_x, terminal_y, terminal_width, terminal_height)) self.terminal_window_obj.move_window_pos( pos_x=terminal_x, pos_y=terminal_y, window_width=terminal_width, window_height=terminal_height) break else: time.sleep(3) desktopHelper.lock_window_pos(self.browser_type)
def setUp(self): super(PerfBaseTest, self).setUp() # init sikuli self.sikuli = sikuli.Sikuli( self.env.run_sikulix_cmd_path, self.env.hasal_dir, running_statistics_file_path=self. global_config['default-running-statistics-fn']) # set up the Customized Region settings if StatusRecorder.SIKULI_KEY_REGION in self.index_config: logger.info('Set Sikuli Status for Customized Region') self.sikuli.set_sikuli_status( StatusRecorder.SIKULI_KEY_REGION, self.index_config[StatusRecorder.SIKULI_KEY_REGION]) # Start video recordings self.profilers = Profilers(self.env, self.index_config, self.exec_config, self.browser_type, self.sikuli) self.profilers.start_profiling(self.env.firefox_settings_extensions) # Record initial timestamp with open(self.env.DEFAULT_TIMESTAMP, "w") as fh: timestamp = {self.env.INITIAL_TIMESTAMP_NAME: str(time.time())} json.dump(timestamp, fh) # launch browser _, self.profile_dir_path = desktopHelper.launch_browser( self.browser_type, env=self.env, profiler_list=self.env.firefox_settings_extensions, exec_config=self.exec_config) # wait browser ready self.get_browser_done() # capture 1st snapshot time.sleep(5) # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled and self.index_config.get('snapshot-base-sample1', False) is True: videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) time.sleep(2) # Record timestamp t1 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) timestamp['t1'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp))
def get_browser_done(self): # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled: viewport = dict() viewport_ref_fp = os.path.join(self.env.img_sample_dp, self.env.img_output_sample_1_fn) is_expected_viewport = False desktopHelper.lock_window_pos(self.browser_type, self.exec_config) for i in range(25): time.sleep(1) videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) viewport = find_image_viewport(viewport_ref_fp) if desktopHelper.is_above_half_viewport(viewport, self.exec_config): logger.debug("Browser shown, adjust viewport by setting %d time(s)." % (i + 1)) height_browser, width_browser = desktopHelper.adjust_viewport(self.browser_type, viewport, self.exec_config) # get the terminal location terminal_location = terminalHelper.get_terminal_location(0, 0, width_browser, height_browser) terminal_x = terminal_location.get('x', 0) terminal_y = terminal_location.get('y', 0) terminal_width = terminal_location.get('width', 0) terminal_height = terminal_location.get('height', 0) logger.info('Move Terminal to (X,Y,W,H): ({}, {}, {}, {})'.format(terminal_x, terminal_y, terminal_width, terminal_height)) self.terminal_window_obj.move_window_pos(pos_x=terminal_x, pos_y=terminal_y, window_width=terminal_width, window_height=terminal_height) videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) viewport = find_image_viewport(viewport_ref_fp) is_expected_viewport = desktopHelper.is_expected_viewport(viewport, self.exec_config) if is_expected_viewport: break else: logger.info("Browser launched but viewport still less than half size, already wait %d second(s)." % (i + 1)) # TODO: Doesn't support runtime viewport adjustment for linux now thus won't verify expected viewport size if not is_expected_viewport and self.current_platform_name != 'linux2': raise Exception('[ERROR] Viewport size is not expected: {}'.format(viewport)) else: time.sleep(3) desktopHelper.lock_window_pos(self.browser_type, self.exec_config)
def tearDown(self): # Record timestamp t3 self.exec_timestamp_list.append(time.time()) # capture 2nd snapshot time.sleep(5) if self.env.PROFILER_FLAG_AVCONV in self.enabled_profiler_list or self.env.PROFILER_FLAG_FXALL in self.enabled_profiler_list: videoHelper.capture_screen(self.env, self.env.video_output_sample_2_fp, self.env.img_sample_dp, self.env.img_output_sample_2_fn) # Stop profiler and save profile data self.profilers.stop_profiling(self.profile_dir_path) # Post run sikuli script if os.getenv("POST_SCRIPT_PATH"): post_script_args = [] if hasattr(self, "post_script_args"): post_script_args = self.args_parser(os.getenv("POST_SCRIPT_PATH"), self.post_script_args) self.sikuli.run_test(os.getenv("POST_SCRIPT_PATH"), os.getenv("POST_SCRIPT_PATH") + "_" + self.env.time_stamp, args_list=post_script_args) # Stop browser if int(os.getenv("KEEP_BROWSER")) == 0: self.sikuli.close_browser(self.browser_type) # Delete Url if hasattr(self, "test_url_id"): self.target_helper.delete_target(self.test_url_id) # output sikuli status to static file with open(self.env.DEFAULT_STAT_RESULT, "w") as fh: stat_data = {'sikuli_stat': str(self.sikuli_status)} json.dump(stat_data, fh) # output result if self.sikuli_status == 0: if hasattr(self, "crop_data"): resultHelper.result_calculation(self.env, self.exec_timestamp_list, self.crop_data, int(os.getenv("CALC_SI")), int(os.getenv("ENABLE_WAVEFORM")), os.getenv("PERFHERDER_REVISION"), os.getenv("PERFHERDER_PKG_PLATFORM")) else: resultHelper.result_calculation(self.env, self.exec_timestamp_list, calc_si=int(os.getenv("CALC_SI")), waveform=int(os.getenv("ENABLE_WAVEFORM")), revision=os.getenv("PERFHERDER_REVISION"), pkg_platform=os.getenv("PERFHERDER_PKG_PLATFORM")) else: logger.warning("This running result of sikuli execution is not successful, return code: " + str(self.sikuli_status))
def setUp(self): super(PerfBaseTest, self).setUp() # init sikuli self.sikuli = sikuli.Sikuli(self.env.run_sikulix_cmd_path, self.env.hasal_dir, running_statistics_file_path=self.global_config['default-running-statistics-fn']) # set up the Customized Region settings if StatusRecorder.SIKULI_KEY_REGION in self.index_config: logger.info('Set Sikuli Status for Customized Region') self.sikuli.set_sikuli_status(StatusRecorder.SIKULI_KEY_REGION, self.index_config[StatusRecorder.SIKULI_KEY_REGION]) # Start video recordings self.profilers = Profilers(self.env, self.index_config, self.exec_config, self.browser_type, self.sikuli) self.profilers.start_profiling(self.env.firefox_settings_extensions) # Record initial timestamp with open(self.env.DEFAULT_TIMESTAMP, "w") as fh: timestamp = {self.env.INITIAL_TIMESTAMP_NAME: str(time.time())} json.dump(timestamp, fh) # launch browser _, self.profile_dir_path = desktopHelper.launch_browser(self.browser_type, env=self.env, profiler_list=self.env.firefox_settings_extensions, exec_config=self.exec_config, firefox_config=self.firefox_config, chrome_config=self.chrome_config) # wait browser ready self.get_browser_done() # capture 1st snapshot time.sleep(5) # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled and self.index_config.get('snapshot-base-sample1', False) is True: videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) time.sleep(2) # Record timestamp t1 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) timestamp['t1'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp))
def setUp(self): super(WebdriverBaseTest, self).setUp() # launch browser self.browser_obj, self.profile_dir_path = \ desktopHelper.launch_browser(self.browser_type, env=self.env, type='webdriver', profiler_list=self.env.firefox_settings_extensions, exec_config=self.exec_config) self.driver = self.browser_obj.return_driver() self.wd = wd.Webdriver(self.driver) # Start video recordings # TODO: need to be webdriver related / geckoProfiler and performanceTimingProfiler used Sikuli object self.profilers = Profilers(self.env, self.browser_type, self.wd) self.profilers.start_profiling(self.env.firefox_settings_extensions) # Record initial timestamp with open(self.env.DEFAULT_TIMESTAMP, "w") as fh: timestamp = {self.env.INITIAL_TIMESTAMP_NAME: str(time.time())} json.dump(timestamp, fh) # wait browser ready / must do after launching browser and starting of video recording self.get_browser_done() # capture 1st snapshot time.sleep(5) if self.index_config['snapshot-base-sample1']: videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) time.sleep(2) # Record timestamp t1 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) timestamp['t1'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp))
def setUp(self): super(PerfBaseTest, self).setUp() # init sikuli self.sikuli = sikuli.Sikuli(self.env.run_sikulix_cmd_path, self.env.hasal_dir) # Start video recordings self.profilers = Profilers(self.env, self.index_config, self.browser_type, self.sikuli) self.profilers.start_profiling(self.env.firefox_settings_extensions) # Record initial timestamp with open(self.env.DEFAULT_TIMESTAMP, "w") as fh: timestamp = {self.env.INITIAL_TIMESTAMP_NAME: str(time.time())} json.dump(timestamp, fh) # launch browser _, self.profile_dir_path = desktopHelper.launch_browser(self.browser_type, env=self.env, profiler_list=self.env.firefox_settings_extensions) # wait browser ready self.get_browser_done() # capture 1st snapshot time.sleep(5) # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled and self.index_config.get('snapshot-base-sample1', False) is True: videoHelper.capture_screen(self.env, self.index_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) time.sleep(2) # Record timestamp t1 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) timestamp['t1'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp))
def tearDown(self): # Record timestamp t2 with open(self.env.DEFAULT_TIMESTAMP, "r+") as fh: timestamp = json.load(fh) if 't2' not in timestamp: timestamp['t2'] = time.time() fh.seek(0) fh.write(json.dumps(timestamp)) # capture 2nd snapshot time.sleep(5) if self.index_config['snapshot-base-sample2']: videoHelper.capture_screen(self.env, self.index_config, self.env.video_output_sample_2_fp, self.env.img_sample_dp, self.env.img_output_sample_2_fn) # Stop profiler and save profile data self.profilers.stop_profiling(self.profile_dir_path) # Stop browser if self.exec_config['keep-browser'] is False: self.wd.close_browser(self.browser_type) super(WebdriverBaseTest, self).tearDown()
def setUp(self): # Get profiler list self.profiler_list = self.get_profiler_list() # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # Init timestamp list self.exec_timestamp_list = [] # get browser type self.browser_type = self.env.get_browser_type() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # init sikuli self.sikuli = sikuli.Sikuli(self.env.run_sikulix_cmd_path, self.env.hasal_dir) # Start video recordings self.profilers = Profilers(self.env, self.browser_type, self.sikuli) self.profilers.start_profiling(self.profiler_list) self.profile_zip_path = self.profilers.get_profile_path() # Record timestamp t1 self.exec_timestamp_list.append(self.profilers.get_t1_time()) # minimize all windows desktopHelper.minimize_window() # launch browser self.profile_dir_path = desktopHelper.launch_browser(self.browser_type, profile_path=self.profile_zip_path, env=self.env, enabled_profiler_list=self.enabled_profiler_list) # switch to content window, prevent cursor twinkling time.sleep(3) if self.browser_type == desktopHelper.DEFAULT_BROWSER_TYPE_FIREFOX: self.sikuli.run_test("test_firefox_switchcontentwindow", self.env.output_name) else: self.sikuli.run_test("test_chrome_switchcontentwindow", self.env.output_name) # lock browser start pos at (0,0) desktopHelper.lock_window_pos(self.browser_type) # execute pre-run-script. # You have to specify the pre_run_script and test_url before calling parent setup in your test class if os.getenv("PRE_SCRIPT_PATH"): pre_script_args = [] # clone pre run script test url id if hasattr(self, "pre_script_args"): pre_script_args = self.args_parser(os.getenv("PRE_SCRIPT_PATH"), self.pre_script_args) # execute pre run script self.sikuli_status = self.sikuli.run_test(os.getenv("PRE_SCRIPT_PATH"), os.getenv("PRE_SCRIPT_PATH") + "_" + self.env.time_stamp, args_list=pre_script_args) # clone test target if hasattr(self, "test_target"): if hasattr(self, "target_folder"): self.test_url, self.test_url_id = self.target_helper.clone_target(self.test_target, self.env.output_name, self.target_folder) logger.info("The test url after cloned is : [%s]" % self.test_url) else: self.test_url, self.test_url_id = self.target_helper.clone_target(self.test_target, self.env.output_name) logger.info("The test url after cloned is : [%s]" % self.test_url) # capture 1st snapshot time.sleep(5) if self.env.PROFILER_FLAG_AVCONV in self.enabled_profiler_list or self.env.PROFILER_FLAG_FXALL in self.enabled_profiler_list: videoHelper.capture_screen(self.env, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) time.sleep(2) # Record timestamp t2 self.exec_timestamp_list.append(time.time())
def get_browser_done(self): # check the video recording recording_enabled = CommonUtil.is_video_recording(self.firefox_config) if recording_enabled: viewport = dict() viewport_ref_fp = os.path.join(self.env.img_sample_dp, self.env.img_output_sample_1_fn) is_expected_viewport = False desktopHelper.lock_window_pos(self.browser_type, self.exec_config) for i in range(25): time.sleep(1) videoHelper.capture_screen(self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) viewport = find_image_viewport(viewport_ref_fp) if desktopHelper.is_above_half_viewport( viewport, self.exec_config): logger.debug( "Browser shown, adjust viewport by setting %d time(s)." % (i + 1)) height_browser, width_browser = desktopHelper.adjust_viewport( self.browser_type, viewport, self.exec_config) # get the terminal location terminal_location = terminalHelper.get_terminal_location( 0, 0, width_browser, height_browser) terminal_x = terminal_location.get('x', 0) terminal_y = terminal_location.get('y', 0) terminal_width = terminal_location.get('width', 0) terminal_height = terminal_location.get('height', 0) logger.info( 'Move Terminal to (X,Y,W,H): ({}, {}, {}, {})'.format( terminal_x, terminal_y, terminal_width, terminal_height)) self.terminal_window_obj.move_window_pos( pos_x=terminal_x, pos_y=terminal_y, window_width=terminal_width, window_height=terminal_height) videoHelper.capture_screen( self.env, self.index_config, self.exec_config, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) viewport = find_image_viewport(viewport_ref_fp) is_expected_viewport = desktopHelper.is_expected_viewport( viewport, self.exec_config) if is_expected_viewport: break else: logger.info( "Browser launched but viewport still less than half size, already wait %d second(s)." % (i + 1)) # TODO: Doesn't support runtime viewport adjustment for linux now thus won't verify expected viewport size if not is_expected_viewport and self.current_platform_name != 'linux2': raise Exception( '[ERROR] Viewport size is not expected: {}'.format( viewport)) else: time.sleep(3) desktopHelper.lock_window_pos(self.browser_type, self.exec_config)