How to use getAttributeCount method in Airtest

Best Python code snippet using Airtest

axmlparser3.py

Source: axmlparser3.py Github

copy

Full Screen

...345 offset = index * 5346 if offset >= len(self.m_attributes):347 traceback.print_exc("Invalid attribute index")348 return offset349 def getAttributeCount(self):350 if self.m_event != START_TAG:351 return -1352 return len(self.m_attributes) /​ ATTRIBUTE_LENGHT353 def getAttributePrefix(self, index):354 offset = self.getAttributeOffset(index)355 uri = self.m_attributes[offset + ATTRIBUTE_IX_NAMESPACE_URI]356 prefix = self.getPrefixByUri(uri)357 if prefix == -1:358 return ""359 return self.sb.getRaw(prefix)360 def getAttributeName(self, index):361 offset = self.getAttributeOffset(index)362 name = self.m_attributes[offset + ATTRIBUTE_IX_NAME]363 if name == -1:364 return ""365 return self.sb.getRaw(name)366 def getAttributeValueType(self, index):367 offset = self.getAttributeOffset(index)368 return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]369 def getAttributeValueData(self, index):370 offset = self.getAttributeOffset(index)371 return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA]372 def getAttributeValue(self, index):373 offset = self.getAttributeOffset(index)374 valueType = self.m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]375 if valueType == TYPE_STRING:376 valueString = self.m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING]377 return self.sb.getRaw(valueString)378 # WIP379 return ""380 # int valueData=m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];381 # return TypedValue.coerceToString(valueType,valueData);382START_DOCUMENT = 0383END_DOCUMENT = 1384START_TAG = 2385END_TAG = 3386TEXT = 4387TYPE_ATTRIBUTE = 2388TYPE_DIMENSION = 5389TYPE_FIRST_COLOR_INT = 28390TYPE_FIRST_INT = 16391TYPE_FLOAT = 4392TYPE_FRACTION = 6393TYPE_INT_BOOLEAN = 18394TYPE_INT_COLOR_ARGB4 = 30395TYPE_INT_COLOR_ARGB8 = 28396TYPE_INT_COLOR_RGB4 = 31397TYPE_INT_COLOR_RGB8 = 29398TYPE_INT_DEC = 16399TYPE_INT_HEX = 17400TYPE_LAST_COLOR_INT = 31401TYPE_LAST_INT = 31402TYPE_NULL = 0403TYPE_REFERENCE = 1404TYPE_STRING = 3405RADIX_MULTS = [0.00390625, 3.051758E-005, 1.192093E-007, 4.656613E-010]406DIMENSION_UNITS = ["px", "dip", "sp", "pt", "in", "mm", "", ""]407FRACTION_UNITS = ["%", "%p", "", "", "", "", "", ""]408COMPLEX_UNIT_MASK = 15409class AXMLPrinter:410 def __init__(self, raw_buff):411 self.parser = AXMLParser(raw_buff)412 self.xmlns = False413 self.buff = ''414 self.content = {}415 self.uses_permissions = set()416 self.permissions = set()417 self.activities = []418 self.mainActivity = None419 self.receivers = {} # { rev : actions }420 self.services = {} # { ser : actions }421 self.actions = set()422 self.parse()423 self.xml = self.format_xml()424 def parse(self):425 mainFlag = -2426 action_list = []427 whichTag = -1428 tagName = ""429 ACT = 0430 REV = 1431 SER = 2432 tag = "notag"433 while True:434 _type = self.parser.next()435 if "</​manifest>" in self.buff:436 break437 if _type == START_DOCUMENT:438 self.buff += '''<?xml version="1.0" encoding="utf-8"?>\n'''439 elif _type == START_TAG:440 prefix = self.getPrefix(441 self.parser.getPrefix()) + self.parser.getName()442 if len(prefix) == 0:443 tag = "notag"444 self.buff += '<' + prefix + '\n'445 self.buff += self.parser.getXMLNS()446 tag = prefix447 for i in range(0, int(self.parser.getAttributeCount())):448 self.buff += "%s%s=\"%s\"\n" % (449 self.getPrefix(self.parser.getAttributePrefix(i)),450 self.parser.getAttributeName(i),451 self._escape(self.getAttributeValue(i)))452 self.buff += '>\n'453 if tag == "manifest" or tag == "uses-sdk":454 for i in range(0, int(self.parser.getAttributeCount())):455 name = self.parser.getAttributeName(i)456 value = self._escape(self.getAttributeValue(i))457 self.content[name] = value458 elif "permission" == tag:459 for i in range(0, int(self.parser.getAttributeCount())):460 name = self.parser.getAttributeName(i)461 value = self._escape(self.getAttributeValue(i))462 if name == "name":463 self.permissions.add(value)464 break465 elif "permission" in tag:466 for i in range(0, int(self.parser.getAttributeCount())):467 name = self.parser.getAttributeName(i)468 value = self._escape(self.getAttributeValue(i))469 if name == "name":470 self.uses_permissions.add(value)471 break472 elif tag == "application":473 for i in range(0, int(self.parser.getAttributeCount())):474 name = self.parser.getAttributeName(i)475 value = self._escape(self.getAttributeValue(i))476 if name == "name":477 self.content["application"] = value478 break479 elif "activity" in tag:480 whichTag = ACT481 for i in range(0, int(self.parser.getAttributeCount())):482 name = self.parser.getAttributeName(i)483 value = self._escape(self.getAttributeValue(i))484 if name == "name":485 tagName = value486 self.activities.append(value)487 elif "receiver" in tag:488 whichTag = REV489 for i in range(0, int(self.parser.getAttributeCount())):490 name = self.parser.getAttributeName(i)491 value = self._escape(self.getAttributeValue(i))492 if name == "name":493 tagName = value494 break495 elif "service" in tag:496 whichTag = SER497 for i in range(0, int(self.parser.getAttributeCount())):498 name = self.parser.getAttributeName(i)499 value = self._escape(self.getAttributeValue(i))500 if name == "name":501 tagName = value502 break503 elif "action" in tag:504 if whichTag == ACT:505 for i in range(0, int(self.parser.getAttributeCount())):506 name = self.parser.getAttributeName(i)507 value = self._escape(self.getAttributeValue(i))508 if name == "name":509 self.actions.add(value)510 if value == "android.intent.action.MAIN":511 mainFlag += 1512 elif whichTag == REV or whichTag == SER:513 for i in range(0, int(self.parser.getAttributeCount())):514 name = self.parser.getAttributeName(i)515 value = self._escape(self.getAttributeValue(i))516 if name == "name":517 action_list.append(value)518 self.actions.add(value)519 break520 elif 'category' in tag:521 if whichTag == ACT:522 for i in range(0, int(self.parser.getAttributeCount())):523 value = self._escape(self.getAttributeValue(i))524 if value == "android.intent.category.LAUNCHER":525 mainFlag += 1526 else:527 for i in range(0, int(self.parser.getAttributeCount())):528 name = self.parser.getAttributeName(i)529 value = self._escape(self.getAttributeValue(i))530 self.content[name] = value531 if "permission" in value:532 self.permissions.add(value)533 else:534 self.content[name] = value535 elif _type == END_TAG:536 prefix = self.getPrefix(537 self.parser.getPrefix()) + self.parser.getName()538 if len(prefix) == 0:539 prefix = "notag"540 self.buff += "</​%s>\n" % (prefix)541 if prefix == "activity":...

Full Screen

Full Screen

axmlparser.py

Source: axmlparser.py Github

copy

Full Screen

...345 offset = index * 5346 if offset >= len(self.m_attributes):347 traceback.print_exc("Invalid attribute index")348 return offset349 def getAttributeCount(self):350 if self.m_event != START_TAG:351 return -1352 return len(self.m_attributes) /​ ATTRIBUTE_LENGHT353 def getAttributePrefix(self, index):354 offset = self.getAttributeOffset(index)355 uri = self.m_attributes[offset + ATTRIBUTE_IX_NAMESPACE_URI]356 prefix = self.getPrefixByUri(uri)357 if prefix == -1:358 return ""359 return self.sb.getRaw(prefix)360 def getAttributeName(self, index):361 offset = self.getAttributeOffset(index)362 name = self.m_attributes[offset + ATTRIBUTE_IX_NAME]363 if name == -1:364 return ""365 return self.sb.getRaw(name)366 def getAttributeValueType(self, index):367 offset = self.getAttributeOffset(index)368 return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]369 def getAttributeValueData(self, index):370 offset = self.getAttributeOffset(index)371 return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA]372 def getAttributeValue(self, index):373 offset = self.getAttributeOffset(index)374 valueType = self.m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]375 if valueType == TYPE_STRING:376 valueString = self.m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING]377 return self.sb.getRaw(valueString)378 # WIP379 return ""380 # int valueData=m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];381 # return TypedValue.coerceToString(valueType,valueData);382START_DOCUMENT = 0383END_DOCUMENT = 1384START_TAG = 2385END_TAG = 3386TEXT = 4387TYPE_ATTRIBUTE = 2388TYPE_DIMENSION = 5389TYPE_FIRST_COLOR_INT = 28390TYPE_FIRST_INT = 16391TYPE_FLOAT = 4392TYPE_FRACTION = 6393TYPE_INT_BOOLEAN = 18394TYPE_INT_COLOR_ARGB4 = 30395TYPE_INT_COLOR_ARGB8 = 28396TYPE_INT_COLOR_RGB4 = 31397TYPE_INT_COLOR_RGB8 = 29398TYPE_INT_DEC = 16399TYPE_INT_HEX = 17400TYPE_LAST_COLOR_INT = 31401TYPE_LAST_INT = 31402TYPE_NULL = 0403TYPE_REFERENCE = 1404TYPE_STRING = 3405RADIX_MULTS = [0.00390625, 3.051758E-005, 1.192093E-007, 4.656613E-010]406DIMENSION_UNITS = ["px", "dip", "sp", "pt", "in", "mm", "", ""]407FRACTION_UNITS = ["%", "%p", "", "", "", "", "", ""]408COMPLEX_UNIT_MASK = 15409class AXML:410 def __init__(self, raw_buff):411 self.parser = AXMLParser(raw_buff)412 self.xmlns = False413 self.buff = ''414 self.content = {}415 self.uses_permissions = set()416 self.permissions = set()417 self.activities = []418 self.mainActivity = None419 self.receivers = {} # { rev : actions }420 self.services = {} # { ser : actions }421 self.actions = set()422 self.parse()423 self.xml = self.format_xml()424 def parse(self):425 mainFlag = -2426 action_list = []427 whichTag = -1428 tagName = ""429 ACT = 0430 REV = 1431 SER = 2432 tag = "notag"433 while True:434 _type = self.parser.next()435 if "</​manifest>" in self.buff:436 break437 if _type == START_DOCUMENT:438 self.buff += '''<?xml version="1.0" encoding="utf-8"?>\n'''439 elif _type == START_TAG:440 prefix = self.getPrefix(441 self.parser.getPrefix()) + self.parser.getName()442 if len(prefix) == 0:443 tag = "notag"444 self.buff += '<' + prefix + '\n'445 self.buff += self.parser.getXMLNS()446 tag = prefix447 for i in range(0, int(self.parser.getAttributeCount())):448 self.buff += "%s%s=\"%s\"\n" % (449 self.getPrefix(self.parser.getAttributePrefix(i)),450 self.parser.getAttributeName(i),451 self._escape(self.getAttributeValue(i)))452 self.buff += '>\n'453 if tag == "manifest" or tag == "uses-sdk":454 for i in range(0, int(self.parser.getAttributeCount())):455 name = self.parser.getAttributeName(i)456 value = self._escape(self.getAttributeValue(i))457 self.content[name] = value458 elif "permission" == tag:459 for i in range(0, int(self.parser.getAttributeCount())):460 name = self.parser.getAttributeName(i)461 value = self._escape(self.getAttributeValue(i))462 if name == "name":463 self.permissions.add(value)464 break465 elif "permission" in tag:466 for i in range(0, int(self.parser.getAttributeCount())):467 name = self.parser.getAttributeName(i)468 value = self._escape(self.getAttributeValue(i))469 if name == "name":470 self.uses_permissions.add(value)471 break472 elif tag == "application":473 for i in range(0, int(self.parser.getAttributeCount())):474 name = self.parser.getAttributeName(i)475 value = self._escape(self.getAttributeValue(i))476 if name == "name":477 self.content["application"] = value478 break479 elif "activity" in tag:480 whichTag = ACT481 for i in range(0, int(self.parser.getAttributeCount())):482 name = self.parser.getAttributeName(i)483 value = self._escape(self.getAttributeValue(i))484 if name == "name":485 tagName = value486 self.activities.append(value)487 elif "receiver" in tag:488 whichTag = REV489 for i in range(0, int(self.parser.getAttributeCount())):490 name = self.parser.getAttributeName(i)491 value = self._escape(self.getAttributeValue(i))492 if name == "name":493 tagName = value494 break495 elif "service" in tag:496 whichTag = SER497 for i in range(0, int(self.parser.getAttributeCount())):498 name = self.parser.getAttributeName(i)499 value = self._escape(self.getAttributeValue(i))500 if name == "name":501 tagName = value502 break503 elif "action" in tag:504 if whichTag == ACT:505 for i in range(0, int(self.parser.getAttributeCount())):506 name = self.parser.getAttributeName(i)507 value = self._escape(self.getAttributeValue(i))508 if name == "name":509 self.actions.add(value)510 if value == "android.intent.action.MAIN":511 mainFlag += 1512 elif whichTag == REV or whichTag == SER:513 for i in range(0, int(self.parser.getAttributeCount())):514 name = self.parser.getAttributeName(i)515 value = self._escape(self.getAttributeValue(i))516 if name == "name":517 action_list.append(value)518 self.actions.add(value)519 break520 elif 'category' in tag:521 if whichTag == ACT:522 for i in range(0, int(self.parser.getAttributeCount())):523 value = self._escape(self.getAttributeValue(i))524 if value == "android.intent.category.LAUNCHER":525 mainFlag += 1526 else:527 for i in range(0, int(self.parser.getAttributeCount())):528 name = self.parser.getAttributeName(i)529 value = self._escape(self.getAttributeValue(i))530 self.content[name] = value531 if "permission" in value:532 self.permissions.add(value)533 else:534 self.content[name] = value535 elif _type == END_TAG:536 prefix = self.getPrefix(537 self.parser.getPrefix()) + self.parser.getName()538 if len(prefix) == 0:539 prefix = "notag"540 self.buff += "</​%s>\n" % (prefix)541 if prefix == "activity":...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

QA&#8217;s and Unit Testing &#8211; Can QA Create Effective Unit Tests

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.

LIVE With Automation Testing For OTT Streaming Devices ????

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.

Why Agile Is Great for Your Business

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.

Options for Manual Test Case Development &#038; Management

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.

Test strategy and how to communicate it

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.

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:

YouTube

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?

Helpful

NotHelpful