def warrior_framework_details(): """This gets framework details such the executing framework path, release & version details. """ #The logic uses relative file path to locate Warrior framework and its\ # release notes.Assumes the relative structure remains constant. release = False version = False version_file_path = os.path.normpath( os.path.join(__file__, "..{0}..{0}..".format(os.sep))) version_file = os.path.join(version_file_path, "version.txt") version_file_exists = file_Utils.fileExists(version_file) if version_file_exists: release_notes = open(version_file, "r") for line in release_notes: line = line.strip() #pattern matching Release:<> if re.match('(Release.*):(.*)', line): match = re.match(r'(Release.*):(.*)', line) release = match.group(2) #pattern matching Version:<> if re.match('(Version.*):(.*)', line): match = re.match(r'(Version.*):(.*)', line) version = match.group(2) user = getpass.getuser() proc1 = subprocess.Popen(['git', 'branch'], stdout=subprocess.PIPE) proc2 = subprocess.Popen(['grep', '*'], stdin=proc1.stdout, stdout=subprocess.PIPE, stderr=None) proc1.stdout.close() # Allow proc1 to receive a SIGPIPE if proc2 exits. branch = proc2.communicate()[0] if release and version and version_file_path: pNote( "========================== WARRIOR FRAMEWORK DETAILS ==========================", 'notype') print_info( 'The Warrior framework used is {0}'.format(version_file_path)) print_info('The Warrior framework user is {0}'.format(user)) print_info('The Warrior framework Release is{0}'.format(release)) print_info('The Warrior framework version is{0}'.format(version)) print_info('The Warrior framework branch is{0}'.format( branch.strip('*'))) print_info( 'The Warrior framework running on python version: {0} with OS: {1}' .format(platform.python_version(), platform.platform())) pNote( "========================== WARRIOR FRAMEWORK DETAILS ==========================", 'notype') #Sleep for the user to view the console for a second on the framework detail time.sleep(2) return None
def check_tmp_file_exists(self, system_name="", filename=""): """ check if temp folder exist in the parallel execution result tmp dir """ if system_name != "" and filename == "": filename = data_Utils.getSystemData(self.datafile, system_name, "filename") elif system_name == "" and filename == "": pNote("No system or filename found, needs to provide at least one", "error") path = data_Utils.get_object_from_datarepository( "parallel_exec_tmp_dir") path = os.path.join(path, filename) return file_Utils.fileExists(path)
def get_execution_files(filepath, execution_dir, extn): """Get the execution files like resultfile, logfile etc""" filename = file_Utils.getFileName(filepath) nameonly = file_Utils.getNameOnly(filename) if extn.lower() == "res": fullpath = execution_dir + os.sep + nameonly + "_results" + "." + extn else: fullpath = execution_dir + os.sep + nameonly + '.' + extn if file_Utils.fileExists(fullpath): fullpath = file_Utils.addTimeDate(fullpath) return fullpath
def check_get_datafile(self): """Check InputDatFile tag in the xml file and based on the values return the datafile to be used for the testcase/testsuite - If user provided a datafile, will use it. - If user specified 'Default' will use the default datafile - If user did not provide any value will use default datafile - If user specified 'NODATA' will print a msg saying so. """ datafile = xml_Utils.getChildTextbyParentTag(self.filepath, 'Details', 'InputDataFile') if datafile is None or datafile is False or \ str(datafile).strip() == "": if self.filetype == "tc": #print "get default datatype for testcase" datafile = get_default_xml_datafile(self.filepath) if self.filetype == "ts": # Check if test suite datatype starts with iterative. # If yes then get default datafile else set it as false # this is because at testsuite level input datafile is # supported only if the suite datatype is iterative seq/parallel datatype = self.check_get_datatype(False) if str(datatype).lower().startswith("iterative"): datafile = get_default_xml_datafile(self.filepath) else: datafile = False elif self.filetype == "proj": datafile = False elif str(datafile).strip().upper() == "DEFAULT": print_info( "This testcase will be executed using the default InputDataFile" ) datafile = get_default_xml_datafile(self.filepath) elif str(datafile).strip().upper() == 'NO_DATA': print_info('This test case will be run without any InputDataFile') datafile = "NO_DATA" elif datafile is not None and datafile is not False: datafile_rel = str(datafile).strip() datafile = file_Utils.getAbsPath(datafile_rel, os.path.dirname(self.filepath)) if str(datafile).strip().upper( ) != 'NO_DATA' and datafile is not False: if not file_Utils.fileExists(datafile): print '\n' print_error("!!! *** InputDataFile does not exist in provided path:"\ "{0} *** !!!".format(datafile)) return datafile
def check_defect_file(path): """Gets the list of defect json files for the testcase execution """ abs_cur_dir = os.path.abspath(os.curdir) value = None if path.endswith(".json"): defect_file = file_Utils.getAbsPath(path, abs_cur_dir) if file_Utils.fileExists(defect_file): print_info("Defect file location is :{0}".format(defect_file)) value = defect_file else: print_error("File Does not exist in provided location: "\ "{0} relative to cwd".format(path)) return value
def warrior_framework_details(): """This gets framework details such the executing framework path, release & version details. """ #The logic uses relative file path to locate Warrior framework and its\ # release notes.Assumes the relative structure remains constant. release = False version = False version_file_path = os.path.normpath( os.path.join(__file__, "..{0}..{0}..".format(os.sep))) version_file = os.path.join(version_file_path, "version.txt") version_file_exists = file_Utils.fileExists(version_file) if version_file_exists: release_notes = open(version_file, "r") for line in release_notes: line = line.strip() #pattern matching Release:<> if re.match('(Release.*):(.*)', line): match = re.match(r'(Release.*):(.*)', line) release = match.group(2) #pattern matching Version:<> if re.match('(Version.*):(.*)', line): match = re.match(r'(Version.*):(.*)', line) version = match.group(2) if release and version and version_file_path: pNote( "========================== WARRIOR FRAMEWORK DETAILS ==========================", 'notype') print_info( 'The Warrior framework used is {0}'.format(version_file_path)) print_info('The Warrior framework Release is{0}'.format(release)) print_info('The Warrior framework version is{0}'.format(version)) print_info( 'The Warrior framework running on python version: {0} with OS: {1}' .format(platform.python_version(), platform.platform())) pNote( "========================== WARRIOR FRAMEWORK DETAILS ==========================", 'notype') #Sleep for the user to view the console for a second on the framework detail time.sleep(2) return None
def _make_ff(self, webdriver_remote_url, desired_capabilites, profile_dir, **kwargs): """Create an instance of firefox browser""" binary = kwargs.get("binary", None) gecko_path = kwargs.get("gecko_path", None) # gecko_log is the absolute path to save geckodriver log gecko_log = kwargs.get("gecko_log", None) proxy_ip = kwargs.get("proxy_ip", None) proxy_port = kwargs.get("proxy_port", None) ff_profile = None # if firefox is being used with proxy, set the profile here # if firefox_proxy details are not given, set profile_dir # as the ff_profile. if proxy_ip is not None and proxy_port is not None: ff_profile = self.set_firefox_proxy(profile_dir, proxy_ip, proxy_port) else: ff_profile = profile_dir log_dir = get_object_from_datarepository("wt_logsdir") if \ gecko_log in [None, False] else gecko_log log_dir = os.path.join(log_dir, "gecko_"+kwargs.get("browser_name", "default")+".log") browser = None try: if webdriver_remote_url: browser = self._create_remote_web_driver( webdriver.DesiredCapabilities.FIREFOX, webdriver_remote_url, desired_capabilites, ff_profile) else: optional_args = {} ff_capabilities = webdriver.DesiredCapabilities.FIREFOX # This is for internal testing needs...some https cert is not secure # And firefox will need to know how to handle it ff_capabilities['acceptInsecureCerts'] = True if binary not in [False, None]: if not fileExists(binary): print_warning("Given firefox binary '{}' does not exist, default " "firefox will be used for execution.".format(binary)) binary = None else: print_info("No value given for firefox binary, default " "firefox will be used for execution.") # Force disable marionette, only needs in Selenium 3 with FF ver < 47 # Without these lines, selenium may encounter capability not found issue # https://github.com/seleniumhq/selenium/issues/2739 # https://github.com/SeleniumHQ/selenium/issues/5106#issuecomment-347298110 if self.get_firefox_version(binary) < LooseVersion("47.0.0"): ff_capabilities["marionette"] = False else: # gecko_log will only get generate if there is failure/error # Need to specify log_path for geckodriver log # Gecko driver will only launch if FF version is 47 or above optional_args["log_path"] = log_dir ffbinary = FirefoxBinary(binary) if binary is not None else None if gecko_path is not None: optional_args["executable_path"] = gecko_path browser = webdriver.Firefox(firefox_binary=ffbinary, capabilities=ff_capabilities, firefox_profile=ff_profile, **optional_args) except WebDriverException as err: if "executable needs to be in PATH" in str(err): print_error("Please provide path for geckodriver executable") elif "Expected browser binary location" in str(err): print_error("Please provide path of firefox executable") print_error(err) traceback.print_exc() except Exception as err: print_error(err) traceback.print_exc() if browser is None and\ any((LooseVersion(webdriver.__version__) < LooseVersion("3.5.0"), gecko_path is None)): print_info("Unable to create Firefox browser, one possible reason is because"\ "Firefox version >= 47.0.1 and Selenium version < 3.5"\ "In order to launch Firefox ver 47 and up, Selenium needs to be updated to >= 3.5"\ "and needs geckodriver > 0.16") return browser