Best Python code snippet using Airtest
apk.py
Source: apk.py
1import inspect2import os3import click4from cli.config import Config5from cli.internal.models.apkparsing.apk import APK6from cli.internal.models.artifacts import IArtifact7from cli.internal.utils.hashing import hash_file8from cli.internal.utils.logging import LazyLog9from cli.internal.utils.ui import section10from cli.internal.utils.validation import validate_artifact_version11class Apk(IArtifact):12 def __init__(self, config: Config, binary, apk: APK):13 self.config = config14 self.binary = binary15 self.apk = apk16 self.name = apk.get_package() if apk.is_valid_APK() else None17 self.version = apk.get_androidversion_code() if apk.is_valid_APK() else None18 self.details = None19 @staticmethod20 def parse(config, apk):21 parsed = Apk(config, apk, APK(apk))22 parsed.validate()23 return parsed24 # TODO: Move this entire validation to service side.25 def validate(self):26 # If not parsed well by apk_parse27 if not self.apk.is_valid_APK():28 self.config.logger.error('Not a valid APK.')29 raise click.Abort()30 validate_artifact_version(self.config, self.version, self.get_type())31 min_sdk = int(self.apk.get_min_sdk_version())32 # We don't support anything higher right now33 if min_sdk > 30:34 self.config.logger.error(inspect.cleandoc("""35 File Name: {}36 Mason Platform does not currently support applications with a minimum sdk greater37 than API 30. Please lower the minimum sdk value in your manifest or38 gradle file.39 """.format(self.binary)))40 raise click.Abort()41 is_debug = False42 if self.apk.is_signed_v1():43 for cert_name in self.apk.get_signature_names():44 cert = self.apk.get_certificate(cert_name)45 is_debug = is_debug or cert.subject.native.get('common_name', '') == 'Android Debug'46 elif min_sdk >= 25 and self.apk.is_signed_v2():47 for cert in self.apk.get_certificates_v2():48 is_debug = is_debug or cert.subject.native.get('common_name', '') == 'Android Debug'49 elif min_sdk >= 28 and self.apk.is_signed_v3():50 for cert in self.apk.get_certificates_v3():51 is_debug = is_debug or cert.subject.native.get('common_name', '') == 'Android Debug'52 else:53 self.config.logger.error(inspect.cleandoc("""54 File Name: {}55 A signing certificate was not detected.56 The Mason Platform requires your app to be signed with a signing scheme.57 For more details on app signing, visit https://s.android.com/security/apksigning.58 """.format(self.binary)))59 raise click.Abort()60 if is_debug:61 self.config.logger.error(inspect.cleandoc("""62 Apps signed with debug keys are not allowed.63 Please sign the APK with your release keys and try again.64 """))65 raise click.Abort()66 def log_details(self):67 with section(self.config, self.get_pretty_type()):68 self.config.logger.info('File path: {}'.format(self.binary))69 self.config.logger.info('Package name: {}'.format(self.get_name()))70 self.config.logger.info('Version name: {}'.format(self.apk.get_androidversion_name()))71 self.config.logger.info('Version code: {}'.format(self.apk.get_androidversion_code()))72 self.config.logger.debug(LazyLog(73 lambda: 'File size: {}'.format(os.path.getsize(self.binary))))74 self.config.logger.debug(LazyLog(75 lambda: 'File SHA256: {}'.format(hash_file(self.binary, 'sha256'))))76 self.config.logger.debug(LazyLog(77 lambda: 'File SHA1: {}'.format(hash_file(self.binary, 'sha1'))))78 self.config.logger.debug(LazyLog(79 lambda: 'File MD5: {}'.format(hash_file(self.binary, 'md5'))))80 def get_content_type(self):81 return 'application/vnd.android.package-archive'82 def get_type(self):83 return 'apk'84 def get_pretty_type(self):85 return 'App'86 def get_sub_type(self):87 return88 def get_name(self):89 return self.name90 def get_version(self):91 return self.version92 def get_registry_meta_data(self):93 meta_data = {94 'apk': {95 'versionName': self.apk.get_androidversion_name(),96 'versionCode': self.apk.get_androidversion_code(),97 'packageName': self.get_name()98 },99 }100 return meta_data101 def __eq__(self, other):...
androguard-APK.py
Source: androguard-APK.py
1#!/usr/bin/python2# -*- coding: utf-8 -*-3from androguard.misc import APK4from pprint import pprint5import sys6def analysis(apkfile):7 app = APK(apkfile)8 if not app.is_valid_APK():9 print('{} is not a valid apk')10 sys.exit(0)11 pprint(app.filename)12 pprint(app.androidversion)13 pprint(app.files)14 # app._patch_magic15 # app.androidversion16 # app.arsc17 # app.axml18 # app.declared_permissions19 # app.filename20 # app.files21 # app.files_crc3222 # app.format_value23 # app.get_AndroidManifest24 # app.get_activities25 # app.get_android_manifest_axml26 # app.get_android_manifest_xml27 # app.get_android_resources28 # app.get_androidversion_code29 # app.get_androidversion_name30 # app.get_app_name31 # app.get_certificate32 # app.get_declared_permissions33 # app.get_declared_permissions_details34 # app.get_details_permissions35 # app.get_dex36 # app.get_element37 # app.get_elements38 # app.get_file39 # app.get_filename40 # app.get_files41 # app.get_files_crc3242 # app.get_files_information43 # app.get_files_types44 # app.get_intent_filters45 # app.get_libraries46 # app.get_main_activity47 # app.get_max_sdk_version48 # app.get_min_sdk_version49 # app.get_package50 # app.get_permissions51 # app.get_providers52 # app.get_raw53 # app.get_receivers54 # app.get_requested_aosp_permissions55 # app.get_requested_aosp_permissions_details56 # app.get_requested_permissions57 # app.get_requested_third_party_permissions58 # app.get_services59 # app.get_signature60 # app.get_signature_name61 # app.get_target_sdk_version62 # app.is_valid_APK63 # app.magic_file64 # app.new_zip65 # app.package66 # app.permission_module67 # app.permissions68 # app.show69 # app.valid_apk70 # app.xml71 # app.zip72 # app.zipmodule73if __name__ == '__main__':74 if len(sys.argv) != 2:75 print('{} <apkfile>'.format(sys.argv[0]))76 sys.exit(0)...
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!!