How to use get_relative_log method in Airtest

Best Python code snippet using Airtest Github


Full Screen

...384                self.copy_tree(os.path.join(self.static_root, subdir), os.path.join(dirpath, "static", subdir))385386        return dirpath, logpath387388    def get_relative_log(self, output_file):389        try:390            html_dir = os.path.dirname(output_file)391            return os.path.relpath(os.path.join(self.log_root, 'log.txt') ,html_dir)392        except Exception:393            traceback.print_exc()394            return ""395396    def get_console(self, output_file):397        html_dir = os.path.dirname(output_file)398        file = os.path.join(html_dir, 'console.txt')399        content = ""400        if os.path.isfile(file):401            try:402                content = self.readFile(file)403            except Exception:404                try:405                    content = self.readFile(file, "gbk")406                except Exception:407                    content = traceback.format_exc() + content408                    content = content + "Can not read console.txt. Please check file in:\n" + file409        return content410411    def readFile(self, filename, code='utf-8'):412        content = ""413        with, encoding=code) as f:414            for line in f.readlines():415                content = content + line416        return content417418    def report_data(self, output_file=None, record_list=None):419        """420        Generate data for the report page421        :param output_file: The file name or full path of the output file, default HTML_FILE422        :param record_list: List of screen recording files423        :return:424        """425        self._load()426        steps = self._analyse()427428        script_path = os.path.join(self.script_root, self.script_name)429        info = json.loads(get_script_info(script_path))430431        records = [os.path.join(LOGDIR, f) if self.export_dir432                   else os.path.abspath(os.path.join(self.log_root, f)) for f in record_list]433434        if not self.static_root.endswith(os.path.sep):435            self.static_root = self.static_root.replace("\\", "/")436            self.static_root += "/"437438        data = {}439        data['steps'] = steps440        data['name'] = self.script_root441        data['scale'] = self.scale442        data['test_result'] = self.test_result443        data['run_end'] = self.run_end444        data['run_start'] = self.run_start445        data['static_root'] = self.static_root446        data['lang'] = self.lang447        data['records'] = records448        data['info'] = info449        data['log'] = self.get_relative_log(output_file)450        data['console'] = self.get_console(output_file)451        data['data'] = json.dumps(data)452        return data453454    def report(self, template_name=HTML_TPL, output_file=None, record_list=None):455        """456        Generate the report page, you can add custom data and overload it if needed457        :param template_name: default is HTML_TPL458        :param output_file: The file name or full path of the output file, default HTML_FILE459        :param record_list: List of screen recording files460        :return:461        """462        if not self.script_name:463            path, self.script_name = script_dir_name(self.script_root)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?