Best Python code snippet using Airtest
runner.py
Source: runner.py
...64 def exec_other_script(cls, scriptpath):65 """run other script in test script"""66 warnings.simplefilter("always")67 warnings.warn("please use using() api instead.", PendingDeprecationWarning)68 def _sub_dir_name(scriptname):69 dirname = os.path.splitdrive(os.path.normpath(scriptname))[-1]70 dirname = dirname.strip(os.path.sep).replace(os.path.sep, "_").replace(cls.SCRIPTEXT, "_sub")71 return dirname72 def _copy_script(src, dst):73 if os.path.isdir(dst):74 shutil.rmtree(dst, ignore_errors=True)75 os.mkdir(dst)76 for f in os.listdir(src):77 srcfile = os.path.join(src, f)78 if not (os.path.isfile(srcfile) and f.endswith(cls.TPLEXT)):79 continue80 dstfile = os.path.join(dst, f)81 shutil.copy(srcfile, dstfile)82 # find script in PROJECT_ROOT83 scriptpath = os.path.join(ST.PROJECT_ROOT, scriptpath)84 # copy submodule's images into sub_dir85 sub_dir = _sub_dir_name(scriptpath)86 sub_dirpath = os.path.join(cls.args.script, sub_dir)87 _copy_script(scriptpath, sub_dirpath)88 # read code89 pyfilename = os.path.basename(scriptpath).replace(cls.SCRIPTEXT, ".py")90 pyfilepath = os.path.join(scriptpath, pyfilename)91 pyfilepath = os.path.abspath(pyfilepath)92 with open(pyfilepath, 'r', encoding='utf8') as f:93 code = f.read()94 # replace tpl filepath with filepath in sub_dir95 code = re.sub("[\'\"](\w+.png)[\'\"]", "\"%s/\g<1>\"" % sub_dir, code)96 exec(compile(code.encode("utf8"), pyfilepath, 'exec'), cls.scope)97def setup_by_args(args):98 # init devices99 if isinstance(args.device, list):...
airtest_runner.py
Source: airtest_runner.py
...60 def exec_other_script(cls, scriptpath):61 """run other script in test script"""62 warnings.simplefilter("always")63 warnings.warn("please use using() api instead.", PendingDeprecationWarning)64 def _sub_dir_name(scriptname):65 dirname = os.path.splitdrive(os.path.normpath(scriptname))[-1]66 dirname = dirname.strip(os.path.sep).replace(os.path.sep, "_").replace(cls.SCRIPTEXT, "_sub")67 return dirname68 def _copy_script(src, dst):69 if os.path.isdir(dst):70 shutil.rmtree(dst, ignore_errors=True)71 os.mkdir(dst)72 for f in os.listdir(src):73 srcfile = os.path.join(src, f)74 if not (os.path.isfile(srcfile) and f.endswith(cls.TPLEXT)):75 continue76 dstfile = os.path.join(dst, f)77 shutil.copy(srcfile, dstfile)78 # find script in PROJECT_ROOT79 scriptpath = os.path.join(ST.PROJECT_ROOT, scriptpath)80 # copy submodule's images into sub_dir81 sub_dir = _sub_dir_name(scriptpath)82 sub_dirpath = os.path.join(cls.args.script, sub_dir)83 _copy_script(scriptpath, sub_dirpath)84 # read code85 pyfilename = os.path.basename(scriptpath).replace(cls.SCRIPTEXT, ".py")86 pyfilepath = os.path.join(scriptpath, pyfilename)87 pyfilepath = os.path.abspath(pyfilepath)88 with open(pyfilepath, 'r', encoding='utf8') as f:89 code = f.read()90 # replace tpl filepath with filepath in sub_dir91 code = re.sub("[\'\"](\w+.png)[\'\"]", "\"%s/\g<1>\"" % sub_dir, code)92 exec(compile(code.encode("utf8"), pyfilepath, 'exec'), cls.scope)93def setup_by_args(args):94 # init devices95 if isinstance(args.device, list):...
initializer.py
Source: initializer.py
...34 MacMaker.make_mac(self.c['generate']['config'])35 def _make_phantom(self):36 from .phantom import PhantomBinFileMaker37 PhantomBinFileMaker(self.fs, self.c['phantom']).make()38 def _sub_dir_name(self, i):39 return '{name}.{did}'.format(name=self.c_full['split']['name'], did=i)40 @property41 def _nb_sub_dirs(self):42 return self.c_full['split']['nb_split']43 def _make_subdirs(self):44 for i in range(self._nb_sub_dirs):45 self.fs.makedir(self._sub_dir_name(i), recreate=True)46 def _make_map_shell_scripts(self):47 from .shell import ShellScriptMaker48 ssm = ShellScriptMaker(self.fs, self.c_full)49 ssm.make()50 def _copy_sources_to_subdirs(self):51 from dxpy import batch52 from fs.copy import copy_file53 all_sources = batch.FilesFilter(['*']).lst(self.fs)54 for i in range(self._nb_sub_dirs):55 with self.fs.opendir(self._sub_dir_name(i)) as d:56 for f in all_sources:57 copy_file(self.fs, f, d, f)58 def pre_sub(self):59 if 'source' in self.c:60 self._copy_sources_from_template()61 if 'generate' in self.c:62 self._make_mac()63 if 'phantom' in self.c:64 self._make_phantom()65 def make_sub(self):66 self._make_subdirs()67 self._copy_sources_to_subdirs()...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!