def setUp(self): # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # get browser type self.browser_type = self.env.get_browser_type() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # Start video recordings self.profilers = Profilers(self.env) self.profilers.start_profiling(self.profiler_list) # init sikuli self.sikuli = sikuli.Sikuli() # minimize all windows desktopHelper.minimize_window() # launch browser desktopHelper.launch_browser(self.browser_type)
def __init__(self): self.enabled = None self.available = None self.env = Environment(sys.argv) self.cluster_name = Cloud.CLUSTER_NAME.format(self.env.get("USER")) self.block_disk_size = Cloud.BLOCK_DISK_SIZE self.disk_size_on_node = Cloud.DISK_SIZE_ON_NODE self.nodes = Cloud.NODES self.disks = Cloud.DISKS self.alpha = Cloud.ALPHA
class PerfBaseTest(unittest.TestCase): profiler_list = [{"path": "lib.profiler.avconvProfiler", "name": "AvconvProfiler"}] def setUp(self): # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # get browser type self.browser_type = self.env.get_browser_type() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # Start video recordings self.profilers = Profilers(self.env) self.profilers.start_profiling(self.profiler_list) # init sikuli self.sikuli = sikuli.Sikuli() # minimize all windows desktopHelper.minimize_window() # launch browser desktopHelper.launch_browser(self.browser_type) def tearDown(self): # Stop profiler and save profile data self.profilers.stop_profiling() # Stop browser desktopHelper.stop_browser(self.browser_type, self.env) # Delete Url if self.test_url_id: self.target_helper.delete_target(self.test_url_id) # output result if self.sikuli_status == 0: resultHelper.result_calculation(self.env) else: print "[WARNING] This running result of sikuli execution is not successful, return code: " + str(self.sikuli_status)
def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) # Get Terminal Window Object here when it still active if sys.platform == 'darwin': terminal_title = ['Terminal.app', 'iTerm.app'] elif sys.platform == 'win32': terminal_title = ['cmd', 'Command Prompt', 'runtest.py'] else: terminal_title = ['Hasal'] # Linux will get current by wmctrl_get_current_window_id() method if current is True self.terminal_window_obj = WindowObject(terminal_title, current=True)
def get_pendulumA2C(worker=None): env = Environment(discrete_action_bound=[2], observation_space_dimension=(3, ), action_space_dimension=(1, ), is_continuous=True, gym_string="Pendulum-v0") feature_transform = GAE(obs_dimension=env.observation_space_dimension, a_dimension=env.action_space_dimension, gamma=0.90, beta=1, is_continuous=env.is_continuous, max_reward=0, min_reward=-16.2736044) feed_forward = Model(a_len=env.discrete_action_bound, a_dimension=env.action_space_dimension, obs_dimension=env.observation_space_dimension, is_continuous=env.is_continuous, a_bound=env.a_bound) actor = A2C( obs_dimension=env.observation_space_dimension, lr=0.0001, feature_transform=feature_transform, model=feed_forward, a_dimension=env.action_space_dimension, action_space_length=env.discrete_action_bound, regular_str=1e-2, minibatch=32, epoch=10, max_grad_norm=0.5, ) train = Train(train=True, max_episode=5e5, max_step=10000, batch_size=8192) return actor, env, train
def setUp(self): # Get profiler list self.profiler_list = self.get_profiler_list() # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # 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() # 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() # minimize all windows desktopHelper.minimize_window() # launch browser self.profile_dir_path = desktopHelper.launch_browser(self.browser_type, self.profile_zip_path) # switch to content window, prevent cursor twinkling time.sleep(3) if self.browser_type == desktopHelper.DEFAULT_BROWSER_TYPE_FIREFOX: self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, "test_firefox_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) else: self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, "test_chrome_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) # execute pre-run-script. # You have to specify the pre_run_script and test_url before calling parent setup in your test class if hasattr(self, "pre_run_script"): # clone pre run script test url id if hasattr(self, "pre_run_script_test_url_id"): test_url_id = getattr(self.env, self.pre_run_script_test_url_id) self.test_url, self.test_url_id = self.target_helper.clone_target(test_url_id, self.pre_run_script + "_" + self.env.time_stamp) # execute pre run script self.sikuli_status = self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, self.pre_run_script, self.pre_run_script + "_" + self.env.time_stamp, test_url=self.test_url) # capture 1st snapshot time.sleep(5) captureHelper.capture_screen(self.env, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn)
def setUp(self): # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # get browser type self.browser_type = self.env.get_browser_type() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # Start video recordings self.profilers = Profilers(self.env) self.profilers.start_profiling(self.profiler_list) # init sikuli self.sikuli = sikuli.Sikuli() # minimize all windows desktopHelper.minimize_window() # launch browser desktopHelper.launch_browser(self.browser_type)
def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) # Init config name inner class self.config_name = self.ConfigName() # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) # Get current platform and its release version self.current_platform_name = sys.platform self.current_platform_ver = platform.release() # load all settings into self object self.load_configs() # Get Terminal Window Object self.terminal_window_obj = terminalHelper.get_terminal_window_object()
class PerfBaseTest(unittest.TestCase): profiler_list = [{"path": "lib.profiler.avconvProfiler", "name": "AvconvProfiler"}] def setUp(self): # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # get browser type self.browser_type = self.env.get_browser_type() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # Start video recordings self.profilers = Profilers(self.env) self.profilers.start_profiling(self.profiler_list) # init sikuli self.sikuli = sikuli.Sikuli() # minimize all windows desktopHelper.minimize_window() # launch browser desktopHelper.launch_browser(self.browser_type) def tearDown(self): # Stop profiler and save profile data self.profilers.stop_profiling() # Stop browser desktopHelper.stop_browser(self.browser_type, self.env) # Delete Url if self.test_url_id: self.target_helper.delete_target(self.test_url_id) # output result resultHelper.result_calculation(self.env)
def get_racingPPO_CNN(worker=None): env = Environment(discrete_action_bound=[2], observation_space_dimension=(96, 96, 3), action_space_dimension=(3, ), is_continuous=True, gym_string="CarRacing-v0") feature_transform = GAE(obs_dimension=env.observation_space_dimension, a_dimension=env.action_space_dimension, gamma=0.99, beta=0.95, is_continuous=env.is_continuous, max_reward=100, min_reward=-0.10000000000000142) conv = ConvNet(a_len=env.discrete_action_bound, a_dimension=env.action_space_dimension, obs_dimension=env.observation_space_dimension, is_continuous=env.is_continuous, a_bound=env.a_bound) actor = PPO( obs_dimension=env.observation_space_dimension, lr=0.0001, feature_transform=feature_transform, model=conv, worker=worker, epsilon=0.1, a_dimension=env.action_space_dimension, action_space_length=env.discrete_action_bound, regular_str=1e-2, minibatch=128, vf_coef=1, epoch=10, max_grad_norm=0.5, ) train = Train(train=True, max_episode=5e5, max_step=100000, batch_size=8192, print_every_episode=1) return actor, env, train
def get_car_pole(worker=None): env = Environment(discrete_action_bound=[2], observation_space_dimension=(4, ), action_space_dimension=(1, ), is_continuous=False, gym_string="CartPole-v0") feature_transform = GAE(obs_dimension=env.observation_space_dimension, a_dimension=env.action_space_dimension, gamma=0.99, beta=1, is_continuous=env.is_continuous, max_reward=1, min_reward=0) feed_forward = Model(a_len=env.discrete_action_bound, a_dimension=env.action_space_dimension, obs_dimension=env.observation_space_dimension, is_continuous=env.is_continuous, a_bound=env.a_bound, is_cat=True) actor = PPO( obs_dimension=env.observation_space_dimension, lr=1e-4, feature_transform=feature_transform, model=feed_forward, epsilon=0.1, a_dimension=env.action_space_dimension, action_space_length=env.discrete_action_bound, regular_str=1e-2, worker=worker, minibatch=16, vf_coef=1, epoch=5, max_grad_norm=0.5, ) train = Train(train=True, max_episode=1e5, max_step=10000, batch_size=64) return actor, env, train
def __init__(self, *args, **kwargs): super(PerfBaseTest, self).__init__(*args, **kwargs) # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc)
class PerfBaseTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(PerfBaseTest, self).__init__(*args, **kwargs) # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) def get_profiler_list(self): avconv_profiler = {"path": "lib.profiler.avconvProfiler", "name": "AvconvProfiler", "profile_name": None} mitmdump_profiler = {"path": "lib.profiler.mitmDumpProfiler", "name": "MitmDumpProfiler", "profile_name": None} har_profiler = {"path": "lib.profiler.harProfiler", "name": "HarProfiler", "profile_name": "AutoSaveHAR.zip"} performance_timing_profiler = {"path": "lib.profiler.performanceTimingProfiler", "name": "PerformanceTimingProfiler", "profile_name": None} gecko_profiler = {"path": "lib.profiler.geckoProfiler", "name": "GeckoProfiler", "profile_name": "GeckoProfiler.zip"} tracelogger_profiler = {"path": "lib.profiler.traceloggerProfiler", "name": "TraceLoggerProfiler", "profile_name": None} result_list = [] profiler_list_str = os.getenv("PROFILER") self.enabled_profiler_list = [item.strip() for item in profiler_list_str.split(',')] if self.env.PROFILER_FLAG_FXALL in self.enabled_profiler_list: result_list.append(avconv_profiler) result_list.append(har_profiler) result_list.append(performance_timing_profiler) result_list.append(gecko_profiler) result_list.append(tracelogger_profiler) return result_list if self.env.PROFILER_FLAG_JUSTPROFILER in self.enabled_profiler_list: result_list.append(har_profiler) result_list.append(performance_timing_profiler) result_list.append(gecko_profiler) result_list.append(tracelogger_profiler) return result_list if self.env.PROFILER_FLAG_AVCONV in self.enabled_profiler_list: result_list.append(avconv_profiler) if self.env.PROFILER_FLAG_GECKOPROFILER in self.enabled_profiler_list: result_list.append(gecko_profiler) if self.env.PROFILER_FLAG_HAREXPORT in self.enabled_profiler_list: result_list.append(har_profiler) if self.env.PROFILER_FLAG_MITMDUMP in self.enabled_profiler_list: result_list.append(mitmdump_profiler) if self.env.PROFILER_FLAG_FXTRACELOGGER in self.enabled_profiler_list: result_list.append(tracelogger_profiler) return result_list def set_variable(self, **kwargs): for variable_name in kwargs.keys(): setattr(self, variable_name, kwargs[variable_name]) def args_parser(self, input_script_name, input_args): result_args = [] for arg in input_args: if type(arg) == dict: if "clone_url" in arg.keys(): test_url_id = getattr(self.env, arg["clone_url"]) self.test_url, self.test_url_id = self.target_helper.clone_target(test_url_id, input_script_name + "_" + self.env.time_stamp) result_args.append(arg["clone_url"]) else: result_args.append(arg[arg.keys()[0]]) else: result_args = input_args return result_args 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 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))
class Cloud(object): DIR = os.path.dirname(__file__) ALPHA = False DISK_SIZE_ON_NODE = 500 BLOCK_DISK_SIZE = 375 CLOUD_USER = "******" CLUSTER_NAME = "{0}-cluster" NODES = 5 DISKS = 3 _clouds = None _cloud_instances = None prompts = None def __init__(self): self.enabled = None self.available = None self.env = Environment(sys.argv) self.cluster_name = Cloud.CLUSTER_NAME.format(self.env.get("USER")) self.block_disk_size = Cloud.BLOCK_DISK_SIZE self.disk_size_on_node = Cloud.DISK_SIZE_ON_NODE self.nodes = Cloud.NODES self.disks = Cloud.DISKS self.alpha = Cloud.ALPHA # The name of the cloud module def get_name(self): raise NotImplementedException("get_name method must be implemented") # any operations that are needed to build the cloud K8S cluster are done here def build_cloud(self): raise NotImplementedException("build_cloud method must be implemented") # after the cloud is built, any configuration of K8S client is done here def configure_cloud(self): raise NotImplementedException( "configure_cloud method must be implemented") # is this cloud enabled and should be seen by the end user (immediete fast checks) def is_enabled(self): raise NotImplementedException("is_enabled method must be implemented") # if the cloud is available after determining that the particular cloud is enabled (long running checks) def is_available(self): raise NotImplementedException( "is_available method must be implemented") @staticmethod def initialize(prompts): Cloud.prompts = prompts Cloud._clouds = list() Cloud._cloud_instances = dict() files = os.listdir(Cloud.DIR) Log.info("Initializing cloud support. One moment please...") for afile in files: full_file = os.path.join(Cloud.DIR, afile) if not full_file.endswith(".py"): Log.debug( "Not inspecting: {0} because it is not a py file".format( full_file)) continue if not os.path.isfile(full_file): Log.debug( "Not inspecting: {0} because it is not a file".format( full_file)) continue if afile == "cloud.py" or afile == "__init__.py": Log.debug( "Not inspecting: {0} because it is not a file".format( full_file)) continue module_name = full_file[:full_file.index(".")] file_module = imp.load_source(module_name, os.path.join(Cloud.DIR, full_file)) class_members = inspect.getmembers(file_module, inspect.isclass) Log.debug("class_members for file_module {0} is: {1}".format( str(file_module), str(class_members))) for clazz in class_members: # if the class is of the correct subclass add it to the list of tests if not issubclass(clazz[1], Cloud) or clazz[ 1] == Cloud or clazz[1] in Cloud._clouds: continue Cloud._clouds.append(clazz[1]) instance = clazz[1]() name = instance.get_name() if instance.is_enabled(): Cloud._cloud_instances[name] = instance Log.debug( "Cloud {0} was added to list because it is enabled". format(name)) else: Log.debug( "Cloud {0} was not added to list because it is not enabled" .format(name)) Log.debug("There were {0} cloud providers found".format( len(Cloud._clouds))) @staticmethod def check_available(): available_instances = dict() for cloud_name, cloud_instance in Cloud._cloud_instances.items(): if cloud_instance.is_available(): Log.debug("{0} cloud is available".format(cloud_name)) available_instances[cloud_name] = cloud_instance else: Log.warning( "{0} cloud was enabled but did not pass availability tests" .format(cloud_name)) Cloud._cloud_instances = available_instances @staticmethod def get_instance(name): instance = Cloud._cloud_instances.get(name) if instance is None: raise NotFoundException( "Could not find an instance with a name of {0}".format(name)) return instance @staticmethod def get_cloud_names(): return sorted(Cloud._cloud_instances.keys())
class PerfBaseTest(unittest.TestCase): def get_profiler_list(self): avconv_profiler = {"path": "lib.profiler.avconvProfiler", "name": "AvconvProfiler", "profile_name": None} har_profiler = {"path": "lib.profiler.harProfiler", "name": "HarProfiler", "profile_name": "AutoSaveHAR.zip"} performance_timing_profiler = {"path": "lib.profiler.performanceTimingProfiler", "name": "PerformanceTimingProfiler", "profile_name": None} gecko_profiler = {"path": "lib.profiler.geckoProfiler", "name": "GeckoProfiler", "profile_name": "GeckoProfiler.zip"} result_list = [] if int(os.getenv("ENABLE_PROFILER")) == 1: if int(os.getenv("DISABLE_AVCONV")) == 0: result_list.append(avconv_profiler) result_list.append(har_profiler) result_list.append(performance_timing_profiler) result_list.append(gecko_profiler) else: result_list.append(avconv_profiler) return result_list def setUp(self): # Get profiler list self.profiler_list = self.get_profiler_list() # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # 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() # 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() # minimize all windows desktopHelper.minimize_window() # launch browser self.profile_dir_path = desktopHelper.launch_browser(self.browser_type, self.profile_zip_path) # switch to content window, prevent cursor twinkling time.sleep(3) if self.browser_type == desktopHelper.DEFAULT_BROWSER_TYPE_FIREFOX: self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, "test_firefox_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) else: self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, "test_chrome_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) # execute pre-run-script. # You have to specify the pre_run_script and test_url before calling parent setup in your test class if hasattr(self, "pre_run_script"): # clone pre run script test url id if hasattr(self, "pre_run_script_test_url_id"): test_url_id = getattr(self.env, self.pre_run_script_test_url_id) self.test_url, self.test_url_id = self.target_helper.clone_target(test_url_id, self.pre_run_script + "_" + self.env.time_stamp) # execute pre run script self.sikuli_status = self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, self.pre_run_script, self.pre_run_script + "_" + self.env.time_stamp, test_url=self.test_url) # capture 1st snapshot time.sleep(5) captureHelper.capture_screen(self.env, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) def tearDown(self): # capture 2nd snapshot time.sleep(5) captureHelper.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) # Stop browser if int(os.getenv("CLOSE_BROWSER")) == 1: desktopHelper.stop_browser(self.browser_type, self.env) # Delete Url if self.test_url_id: self.target_helper.delete_target(self.test_url_id) # output sikuli status to static file with open(self.env.DEFAULT_SIKULI_STATUS_RESULT, "w") as fh: fh.write(str(self.sikuli_status)) # output result if self.sikuli_status == 0: resultHelper.result_calculation(self.env) else: print "[WARNING] This running result of sikuli execution is not successful, return code: " + str(self.sikuli_status)
class BaseTest(unittest.TestCase): class ConfigName(object): EXEC = 'exec_config' INDEX = 'index_config' GLOBAL = 'global_config' FIREFOX = 'firefox_config' CHROME = 'chrome_config' UPLOAD = 'upload_config' def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) # Init config name inner class self.config_name = self.ConfigName() # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) # Get current platform and its release version self.current_platform_name = sys.platform self.current_platform_ver = platform.release() # load all settings into self object self.load_configs() # Get Terminal Window Object self.terminal_window_obj = terminalHelper.get_terminal_window_object() def set_profiler_path(self): for name in self.env.firefox_settings_extensions: if not name.lower().startswith("chrome"): self.env.firefox_settings_extensions[name]['path'] = "lib.profiler." + name[0].lower() + name[1:] def set_variable(self, **kwargs): for variable_name in kwargs.keys(): setattr(self, variable_name, kwargs[variable_name]) def args_parser(self, input_script_name, input_args): result_args = [] for arg in input_args: if type(arg) == dict: if "clone_url" in arg.keys(): test_url_id = getattr(self.env, arg["clone_url"]) self.test_url, self.test_url_id = \ self.target_helper.clone_target(test_url_id, input_script_name + "_" + self.env.time_stamp) result_args.append(arg["clone_url"]) else: result_args.append(arg[arg.keys()[0]]) else: result_args = input_args return result_args 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 clone_test_file(self): if hasattr(self, "test_target"): # init target helper self.target_helper = targetHelper.TagetHelper(self.env, self.global_config) 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) def remove_test_file(self): if hasattr(self, "test_url_id"): self.target_helper.delete_target(self.test_url_id) def extract_platform_dep_settings(self, config_value): return HasalConfigUtil.extract_platform_dep_settings(config_value, self.current_platform_name, self.current_platform_ver) # This will set new configs into variables and update if the variables already exist def set_configs(self, config_variable_name, config_value): # only the config in the following list can be created or updated acceptable_config_list = [self.config_name.EXEC, self.config_name.INDEX, self.config_name.GLOBAL, self.config_name.FIREFOX, self.config_name.UPLOAD, self.config_name.CHROME] self.__dict__.update( HasalConfigUtil.overwrite_platform_dep_settings_into_configs(self, config_variable_name, config_value, acceptable_config_list, self.current_platform_name, self.current_platform_ver).__dict__) def load_configs(self): config_fp_list = ['EXEC_CONFIG_FP', 'INDEX_CONFIG_FP', 'GLOBAL_CONFIG_FP', 'FIREFOX_CONFIG_FP', 'UPLOAD_CONFIG_FP', 'CHROME_CONFIG_FP'] for config_env_name in config_fp_list: config_variable_name = config_env_name.rsplit('_', 1)[0].lower() with open(os.getenv(config_env_name)) as fh: config_value = json.load(fh) self.set_configs(config_variable_name, config_value) self.extract_screen_settings_from_env() # TODO: these screen settings should be moved to exec config in the future def extract_screen_settings_from_env(self): screen_settings = { 'browser-pos-x': self.env.DEFAULT_BROWSER_POS_X, 'browser-pos-y': self.env.DEFAULT_BROWSER_POS_Y, 'browser-width': self.env.DEFAULT_BROWSER_WIDTH, 'browser-height': self.env.DEFAULT_BROWSER_HEIGHT, 'viewport-width': self.env.DEFAULT_VIEWPORT_WIDTH, 'viewport-height': self.env.DEFAULT_VIEWPORT_HEIGHT, 'video-recording-pos-x': self.env.DEFAULT_VIDEO_RECORDING_POS_X, 'video-recording-pos-y': self.env.DEFAULT_VIDEO_RECORDING_POS_Y, 'video-recording-width': self.env.DEFAULT_VIDEO_RECORDING_WIDTH, 'video-recording-height': self.env.DEFAULT_VIDEO_RECORDING_HEIGHT } self.set_configs(self.config_name.EXEC, screen_settings) def get_new_recording_size(self): recording_width = min(self.exec_config['browser-width'] + 100, 1920) if self.current_platform_name.lower() == "darwin": recording_height = min(self.exec_config['browser-height'] + 120, 900) else: recording_height = min(self.exec_config['browser-height'] + 180, 1080) recording_setting = {'video-recording-width': recording_width, 'video-recording-height': recording_height } return recording_setting def setUp(self): # Original profiler list was substitute by self.env.firefox_settings_extensions # We set the original profiler path variable in the variable self.set_profiler_path() # Init sikuli status for webdriver/sikuli self.round_status = 0 # Init output dirs self.env.init_output_dir() # get browser type # TODO Maybe we can set runtime_case_data['browser_type' here, so baseTest.py can use one line self.browser_type = os.getenv("browser_type"). if self.exec_config['user-simulation-tool'] == self.global_config['default-user-simulation-tool-webdriver']: self.browser_type = os.getenv("browser_type") else: self.browser_type = self.env.get_browser_type() # clone test target self.clone_test_file() def tearDown(self): # Delete Url self.remove_test_file() # output status to static file self.objStatusRecorder = StatusRecorder(self.global_config['default-running-statistics-fn']) self.objStatusRecorder.record_current_status({self.objStatusRecorder.STATUS_SIKULI_RUNNING_VALIDATION: str(self.round_status)}) # output result if self.round_status == 0: if hasattr(self, "crop_data"): generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.upload_config, os.getenv("SUITE_RESULT_DP"), self.crop_data) else: generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.upload_config, os.getenv("SUITE_RESULT_DP")) else: logger.warning("This running result of execution is not successful, return code: " + str(self.round_status))
def setUp(self): # Get profiler list self.profiler_list = self.get_profiler_list() # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # 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() # 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() # minimize all windows desktopHelper.minimize_window() # launch browser self.profile_dir_path = desktopHelper.launch_browser( self.browser_type, self.profile_zip_path) # switch to content window, prevent cursor twinkling time.sleep(3) if self.browser_type == desktopHelper.DEFAULT_BROWSER_TYPE_FIREFOX: self.sikuli.run( self.env.sikuli_path, self.env.hasal_dir, "test_firefox_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) else: self.sikuli.run( self.env.sikuli_path, self.env.hasal_dir, "test_chrome_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) # execute pre-run-script. # You have to specify the pre_run_script and test_url before calling parent setup in your test class if hasattr(self, "pre_run_script"): # clone pre run script test url id if hasattr(self, "pre_run_script_test_url_id"): test_url_id = getattr(self.env, self.pre_run_script_test_url_id) self.test_url, self.test_url_id = self.target_helper.clone_target( test_url_id, self.pre_run_script + "_" + self.env.time_stamp) # execute pre run script self.sikuli_status = self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, self.pre_run_script, self.pre_run_script + "_" + self.env.time_stamp, test_url=self.test_url) # capture 1st snapshot time.sleep(5) captureHelper.capture_screen(self.env, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn)
class PerfBaseTest(unittest.TestCase): def get_profiler_list(self): avconv_profiler = { "path": "lib.profiler.avconvProfiler", "name": "AvconvProfiler", "profile_name": None } har_profiler = { "path": "lib.profiler.harProfiler", "name": "HarProfiler", "profile_name": "AutoSaveHAR.zip" } performance_timing_profiler = { "path": "lib.profiler.performanceTimingProfiler", "name": "PerformanceTimingProfiler", "profile_name": None } gecko_profiler = { "path": "lib.profiler.geckoProfiler", "name": "GeckoProfiler", "profile_name": "GeckoProfiler.zip" } result_list = [] if int(os.getenv("ENABLE_PROFILER")) == 1: if int(os.getenv("DISABLE_AVCONV")) == 0: result_list.append(avconv_profiler) result_list.append(har_profiler) result_list.append(performance_timing_profiler) result_list.append(gecko_profiler) else: result_list.append(avconv_profiler) return result_list def setUp(self): # Get profiler list self.profiler_list = self.get_profiler_list() # Init environment variables self.env = Environment(self._testMethodName) # Init output dirs self.env.init_output_dir() # Init sikuli status self.sikuli_status = 0 # 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() # 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() # minimize all windows desktopHelper.minimize_window() # launch browser self.profile_dir_path = desktopHelper.launch_browser( self.browser_type, self.profile_zip_path) # switch to content window, prevent cursor twinkling time.sleep(3) if self.browser_type == desktopHelper.DEFAULT_BROWSER_TYPE_FIREFOX: self.sikuli.run( self.env.sikuli_path, self.env.hasal_dir, "test_firefox_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) else: self.sikuli.run( self.env.sikuli_path, self.env.hasal_dir, "test_chrome_switchcontentwindow", self.env.test_method_name + "_" + self.env.time_stamp) # execute pre-run-script. # You have to specify the pre_run_script and test_url before calling parent setup in your test class if hasattr(self, "pre_run_script"): # clone pre run script test url id if hasattr(self, "pre_run_script_test_url_id"): test_url_id = getattr(self.env, self.pre_run_script_test_url_id) self.test_url, self.test_url_id = self.target_helper.clone_target( test_url_id, self.pre_run_script + "_" + self.env.time_stamp) # execute pre run script self.sikuli_status = self.sikuli.run(self.env.sikuli_path, self.env.hasal_dir, self.pre_run_script, self.pre_run_script + "_" + self.env.time_stamp, test_url=self.test_url) # capture 1st snapshot time.sleep(5) captureHelper.capture_screen(self.env, self.env.video_output_sample_1_fp, self.env.img_sample_dp, self.env.img_output_sample_1_fn) def tearDown(self): # capture 2nd snapshot time.sleep(5) captureHelper.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) # Stop browser if int(os.getenv("CLOSE_BROWSER")) == 1: desktopHelper.stop_browser(self.browser_type, self.env) # Delete Url if self.test_url_id: self.target_helper.delete_target(self.test_url_id) # output sikuli status to static file with open(self.env.DEFAULT_SIKULI_STATUS_RESULT, "w") as fh: fh.write(str(self.sikuli_status)) # output result if self.sikuli_status == 0: resultHelper.result_calculation(self.env) else: print "[WARNING] This running result of sikuli execution is not successful, return code: " + str( self.sikuli_status)
class BaseTest(unittest.TestCase): class ConfigName(object): EXEC = 'exec_config' INDEX = 'index_config' GLOBAL = 'global_config' FIREFOX = 'firefox_config' ONLINE = 'online_config' def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) # Init config name inner class self.config_name = self.ConfigName() # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) # Get current platform and its release version self.current_platform_name = sys.platform self.current_platform_ver = platform.release() # load all settings into self object self.load_configs() # Get Terminal Window Object self.terminal_window_obj = terminalHelper.get_terminal_window_object() def set_profiler_path(self): for name in self.env.firefox_settings_extensions: if not name.lower().startswith("chrome"): self.env.firefox_settings_extensions[name][ 'path'] = "lib.profiler." + name[0].lower() + name[1:] def set_variable(self, **kwargs): for variable_name in kwargs.keys(): setattr(self, variable_name, kwargs[variable_name]) def args_parser(self, input_script_name, input_args): result_args = [] for arg in input_args: if type(arg) == dict: if "clone_url" in arg.keys(): test_url_id = getattr(self.env, arg["clone_url"]) self.test_url, self.test_url_id = \ self.target_helper.clone_target(test_url_id, input_script_name + "_" + self.env.time_stamp) result_args.append(arg["clone_url"]) else: result_args.append(arg[arg.keys()[0]]) else: result_args = input_args return result_args 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 clone_test_file(self): if hasattr(self, "test_target"): # init target helper self.target_helper = targetHelper.TagetHelper( self.env, self.global_config) 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) def remove_test_file(self): if hasattr(self, "test_url_id"): self.target_helper.delete_target(self.test_url_id) # be careful to have "default" value for each and every platform in conf file, or it would raise exception. def extract_platform_dep_settings(self, config_value): platform_dep_variables = {} # get current platform value or default value of it if self.current_platform_name in config_value: if self.current_platform_ver in config_value[ self.current_platform_name]: platform_dep_variables = copy.deepcopy(config_value[ self.current_platform_name][self.current_platform_ver]) elif 'default' in config_value[self.current_platform_name]: platform_dep_variables = copy.deepcopy( config_value[self.current_platform_name]['default']) # return {} if no matching system platform and no default value return platform_dep_variables # This will set new configs into variables and update if the variables already exist def set_configs(self, config_variable_name, config_value): # only the config in the following list can be created or updated acceptable_config_list = [ self.config_name.EXEC, self.config_name.INDEX, self.config_name.GLOBAL, self.config_name.FIREFOX, self.config_name.ONLINE ] if config_variable_name not in acceptable_config_list: raise Exception( 'Invalid configuration name {config_name}: {config_value}'. format(config_name=config_variable_name, config_value=config_value)) default_platform_dep_settings_key = "platform-dep-settings" if default_platform_dep_settings_key in config_value: # Load the index config's settings under "platform-dep-settings" base on platform platform_dep_variables = self.extract_platform_dep_settings( config_value[default_platform_dep_settings_key]) config_value.update(platform_dep_variables) config_value.pop(default_platform_dep_settings_key) if hasattr(self, config_variable_name): # getattr is a way to get variable by reference and doesn't need to be set back new_config_value = getattr(self, config_variable_name) new_config_value.update(config_value) setattr(self, config_variable_name, new_config_value) else: setattr(self, config_variable_name, config_value) def load_configs(self): config_fp_list = [ 'EXEC_CONFIG_FP', 'INDEX_CONFIG_FP', 'GLOBAL_CONFIG_FP', 'FIREFOX_CONFIG_FP', 'ONLINE_CONFIG_FP' ] for config_env_name in config_fp_list: config_variable_name = config_env_name.rsplit('_', 1)[0].lower() with open(os.getenv(config_env_name)) as fh: config_value = json.load(fh) self.set_configs(config_variable_name, config_value) self.extract_screen_settings_from_env() # TODO: these screen settings should be moved to exec config in the future def extract_screen_settings_from_env(self): screen_settings = { 'browser-pos-x': self.env.DEFAULT_BROWSER_POS_X, 'browser-pos-y': self.env.DEFAULT_BROWSER_POS_Y, 'browser-width': self.env.DEFAULT_BROWSER_WIDTH, 'browser-height': self.env.DEFAULT_BROWSER_HEIGHT, 'viewport-width': self.env.DEFAULT_VIEWPORT_WIDTH, 'viewport-height': self.env.DEFAULT_VIEWPORT_HEIGHT, 'video-recording-pos-x': self.env.DEFAULT_VIDEO_RECORDING_POS_X, 'video-recording-pos-y': self.env.DEFAULT_VIDEO_RECORDING_POS_Y, 'video-recording-width': self.env.DEFAULT_VIDEO_RECORDING_WIDTH, 'video-recording-height': self.env.DEFAULT_VIDEO_RECORDING_HEIGHT } self.set_configs(self.config_name.EXEC, screen_settings) def get_new_recording_size(self): recording_width = min(self.exec_config['browser-width'] + 100, 1920) if self.current_platform_name.lower() == "darwin": recording_height = min(self.exec_config['browser-height'] + 120, 900) else: recording_height = min(self.exec_config['browser-height'] + 180, 1080) recording_setting = { 'video-recording-width': recording_width, 'video-recording-height': recording_height } return recording_setting def setUp(self): # Original profiler list was substitute by self.env.firefox_settings_extensions # We set the original profiler path variable in the variable self.set_profiler_path() # Init sikuli status for webdriver/sikuli self.round_status = 0 # Init output dirs self.env.init_output_dir() # get browser type # TODO Maybe we can set runtime_case_data['browser_type' here, so baseTest.py can use one line self.browser_type = os.getenv("browser_type"). if self.exec_config['user-simulation-tool'] == self.global_config[ 'default-user-simulation-tool-webdriver']: self.browser_type = os.getenv("browser_type") else: self.browser_type = self.env.get_browser_type() # clone test target self.clone_test_file() def tearDown(self): # Delete Url self.remove_test_file() # output status to static file self.objStatusRecorder = StatusRecorder( self.global_config['default-running-statistics-fn']) self.objStatusRecorder.record_current_status({ self.objStatusRecorder.STATUS_SIKULI_RUNNING_VALIDATION: str(self.round_status) }) # output result if self.round_status == 0: if hasattr(self, "crop_data"): generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.online_config, os.getenv("SUITE_RESULT_DP"), self.crop_data) else: generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.online_config, os.getenv("SUITE_RESULT_DP")) else: logger.warning( "This running result of execution is not successful, return code: " + str(self.round_status))
class BaseTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) # Init environment variables self.env = Environment(self._testMethodName, self._testMethodDoc) # Get Terminal Window Object here when it still active if sys.platform == 'darwin': terminal_title = ['Terminal.app', 'iTerm.app'] elif sys.platform == 'win32': terminal_title = ['cmd', 'Command Prompt', 'runtest.py'] else: terminal_title = ['Hasal'] # Linux will get current by wmctrl_get_current_window_id() method if current is True self.terminal_window_obj = WindowObject(terminal_title, current=True) def set_profiler_path(self): for name in self.env.firefox_settings_extensions: if not name.startswith("chrome"): self.env.firefox_settings_extensions[name][ 'path'] = "lib.profiler." + name[0].lower() + name[1:] def set_variable(self, **kwargs): for variable_name in kwargs.keys(): setattr(self, variable_name, kwargs[variable_name]) def args_parser(self, input_script_name, input_args): result_args = [] for arg in input_args: if type(arg) == dict: if "clone_url" in arg.keys(): test_url_id = getattr(self.env, arg["clone_url"]) self.test_url, self.test_url_id = \ self.target_helper.clone_target(test_url_id, input_script_name + "_" + self.env.time_stamp) result_args.append(arg["clone_url"]) else: result_args.append(arg[arg.keys()[0]]) else: result_args = input_args return result_args 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 clone_test_file(self): 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) def remove_test_file(self): if hasattr(self, "test_url_id"): self.target_helper.delete_target(self.test_url_id) def load_configs(self): default_platform_dep_settings_key = "platform-dep-settings" config_fp_list = [ 'EXEC_CONFIG_FP', 'INDEX_CONFIG_FP', 'GLOBAL_CONFIG_FP', 'FIREFOX_CONFIG_FP', 'ONLINE_CONFIG_FP' ] current_platform_name = sys.platform for config_env_name in config_fp_list: config_variable_name = "_".join( config_env_name.split("_")[:2]).lower() with open(os.getenv(config_env_name)) as fh: config_value = json.load(fh) if default_platform_dep_settings_key in config_value: if current_platform_name in config_value[ default_platform_dep_settings_key]: platform_dep_variables = copy.deepcopy( config_value[default_platform_dep_settings_key] [current_platform_name]) config_value.update(platform_dep_variables) config_value.pop(default_platform_dep_settings_key) setattr(self, config_variable_name, config_value) def setUp(self): # load all settings into self object self.load_configs() # Original profiler list was substitute by self.env.firefox_settings_extensions # We set the original profiler path variable in the variable self.set_profiler_path() # init target helper self.target_helper = targetHelper.TagetHelper(self.env) # Init sikuli status for webdriver/sikuli self.round_status = 0 # Init output dirs self.env.init_output_dir() # get browser type # TODO Maybe we can set runtime_case_data['browser_type' here, so baseTest.py can use one line self.browser_type = os.getenv("browser_type"). if self.exec_config['user-simulation-tool'] == self.global_config[ 'default-user-simulation-tool-webdriver']: self.browser_type = os.getenv("browser_type") else: self.browser_type = self.env.get_browser_type() # clone test target self.clone_test_file() def tearDown(self): # Delete Url self.remove_test_file() # output status to static file with open(self.env.DEFAULT_STAT_RESULT, "w") as fh: stat_data = {'round_status': str(self.round_status)} json.dump(stat_data, fh) # output result if self.round_status == 0: if hasattr(self, "crop_data"): generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.online_config, os.getenv("SUITE_RESULT_DP"), self.crop_data) else: generatorHelper.calculate(self.env, self.global_config, self.exec_config, self.index_config, self.firefox_config, self.online_config, os.getenv("SUITE_RESULT_DP")) else: logger.warning( "This running result of execution is not successful, return code: " + str(self.round_status))