According to given xpath selector, containing text, content, classname, resource id, test if this current element has the same property value as the given xpath selector. \param xpathSelector Describe property values of a xml element should have. \return If this element could be matched to the given xpath selector, return true.
| 45 | /// \param xpathSelector Describe property values of a xml element should have. |
| 46 | /// \return If this element could be matched to the given xpath selector, return true. |
| 47 | bool Element::matchXpathSelector(const XpathPtr &xpathSelector) const { |
| 48 | if (!xpathSelector) |
| 49 | return false; |
| 50 | bool match; |
| 51 | bool isResourceIDEqual = (!xpathSelector->resourceID.empty() && |
| 52 | this->getResourceID() == xpathSelector->resourceID); |
| 53 | bool isTextEqual = (!xpathSelector->text.empty() && this->getText() == xpathSelector->text); |
| 54 | bool isContentEqual = (!xpathSelector->contentDescription.empty() && |
| 55 | this->getContentDesc() == xpathSelector->contentDescription); |
| 56 | bool isClassNameEqual = (!xpathSelector->clazz.empty() && |
| 57 | this->getClassname() == xpathSelector->clazz); |
| 58 | bool isIndexEqual = xpathSelector->index > -1 && this->getIndex() == xpathSelector->index; |
| 59 | BDLOG("begin find xpathSelector :\n " |
| 60 | "XPathSelector:\n resourceID: %s text: %s contentDescription: %s clazz: %s index: %d \n" |
| 61 | "UIPageElement:\n resourceID: %s text: %s contentDescription: %s clazz: %s index: %d \n" |
| 62 | "equality: \n isResourceIDEqual:%d isTextEqual:%d isContentEqual:%d isClassNameEqual:%d isIndexEqual:%d", |
| 63 | xpathSelector->resourceID.c_str(), |
| 64 | xpathSelector->text.c_str(), |
| 65 | xpathSelector->contentDescription.c_str(), |
| 66 | xpathSelector->clazz.c_str(), |
| 67 | xpathSelector->index, |
| 68 | this->getResourceID().c_str(), |
| 69 | this->getText().c_str(), |
| 70 | this->getContentDesc().c_str(), |
| 71 | this->getClassname().c_str(), |
| 72 | this->getIndex(), |
| 73 | isResourceIDEqual, |
| 74 | isTextEqual, |
| 75 | isContentEqual, |
| 76 | isClassNameEqual, |
| 77 | isIndexEqual); |
| 78 | if (xpathSelector->operationAND) { |
| 79 | match = true; |
| 80 | if (!xpathSelector->clazz.empty()) |
| 81 | match = isClassNameEqual; |
| 82 | if (!xpathSelector->contentDescription.empty()) |
| 83 | match = match && isContentEqual; |
| 84 | if (!xpathSelector->text.empty()) |
| 85 | match = match && isTextEqual; |
| 86 | if (!xpathSelector->resourceID.empty()) |
| 87 | match = match && isResourceIDEqual; |
| 88 | if (xpathSelector->index != -1) |
| 89 | match = match && isIndexEqual; |
| 90 | } else |
| 91 | match = isResourceIDEqual || isTextEqual || isContentEqual || isClassNameEqual; |
| 92 | return match; |
| 93 | } |
| 94 | |
| 95 | /// Select elements if it satisfies bool function func |
| 96 | /// \param func bool function |
no test coverage detected