2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 using namespace Aurum;
28 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
32 if (mWaiter) delete mWaiter;
35 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
36 const AccessibleNode *node)
39 mNode(std::shared_ptr<AccessibleNode>(const_cast<AccessibleNode *>(node))),
40 mWaiter(new Waiter{this, this})
44 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
45 std::shared_ptr<AccessibleNode> node)
48 mNode(std::move(node)),
49 mWaiter(new Waiter{this, this})
53 UiObject::UiObject(UiObject &&src)
54 : mDevice(src.mDevice),
55 mSelector(std::move(src.mSelector)),
56 mNode(std::move(src.mNode)),
59 src.mDevice = nullptr;
60 src.mSelector = nullptr;
62 src.mWaiter = nullptr;
65 std::shared_ptr<UiSelector> UiObject::getSelector()
67 return this->mSelector;
70 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
72 std::shared_ptr<AccessibleNode> node =
73 Comparer::findObject(mDevice, selector, getAccessibleNode());
74 if (node != nullptr) {
75 // todo : what is this node.recycle()
81 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
83 std::shared_ptr<AccessibleNode> node =
84 Comparer::findObject(mDevice, selector, getAccessibleNode());
86 return std::make_shared<UiObject>(mDevice, selector, std::move(node));
88 return std::shared_ptr<UiObject>{nullptr};
91 std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
92 const std::shared_ptr<UiSelector> selector) const
94 std::vector<std::shared_ptr<UiObject>> result{};
95 auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
96 for ( auto& node : nodes) {
98 LOGI("Skipped! (node == nullptr)");
101 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
106 bool UiObject::waitFor(
107 const std::function<bool(const ISearchable *)> condition) const
109 return mWaiter->waitFor(condition);
112 std::shared_ptr<UiObject> UiObject::waitFor(
113 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
116 return mWaiter->waitFor(condition);
119 bool UiObject::waitFor(
120 const std::function<bool(const UiObject *)> condition) const
122 return mWaiter->waitFor(condition);
125 UiObject *UiObject::getParent() const
127 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
128 if (!node) return nullptr;
129 return new UiObject(mDevice, mSelector, std::move(node));
132 int UiObject::getChildCount() const
134 return getAccessibleNode()->getChildCount();
137 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
138 auto childNode = getAccessibleNode()->getChildAt(index);
140 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
145 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
147 auto sel = Sel::depth(1);
148 return this->findObjects(sel);
151 std::shared_ptr<Node> UiObject::getDescendant()
153 std::vector<std::shared_ptr<Node>> nodeChildren{};
155 auto children = getChildren();
156 for (auto &&child : children) {
157 nodeChildren.push_back(child->getDescendant());
159 return std::make_shared<Node>(shared_from_this(), nodeChildren);
162 std::string UiObject::getApplicationPackage() const
164 return getAccessibleNode()->getPkg();
167 std::string UiObject::getId() const
169 return getAccessibleNode()->getId();
172 std::string UiObject::getAutomationId() const
174 return getAccessibleNode()->getAutomationId();
177 std::string UiObject::getElementType() const
179 return getAccessibleNode()->getType();
182 std::string UiObject::getElementStyle() const
184 return getAccessibleNode()->getStyle();
187 std::string UiObject::getText() const
189 return getAccessibleNode()->getText();
192 std::string UiObject::getRole() const
194 return getAccessibleNode()->getRole();
197 std::string UiObject::getXPath() const
199 return getAccessibleNode()->getXPath();
202 const double UiObject::getMinValue() const
204 return getAccessibleNode()->getMinValue();
207 const double UiObject::getMaxValue() const
209 return getAccessibleNode()->getMaxValue();
212 const double UiObject::getValue() const
214 return getAccessibleNode()->getValue();
217 const double UiObject::getIncrement() const
219 return getAccessibleNode()->getIncrement();
222 bool UiObject::setValue(double value)
224 return getAccessibleNode()->setValue(value);
227 bool UiObject::setText(std::string text)
229 return getAccessibleNode()->setValue(text);
232 bool UiObject::isCheckable() const
234 return getAccessibleNode()->isCheckable();
237 bool UiObject::isChecked() const
239 return getAccessibleNode()->isChecked();
242 bool UiObject::isClickable() const
244 return getAccessibleNode()->isClickable();
247 bool UiObject::isEnabled() const
249 return getAccessibleNode()->isEnabled();
252 bool UiObject::isFocusable() const
254 return getAccessibleNode()->isFocusable();
257 bool UiObject::isFocused() const
259 return getAccessibleNode()->isFocused();
262 bool UiObject::isLongClickable() const
264 return getAccessibleNode()->isLongClickable();
267 bool UiObject::isScrollable() const
269 return getAccessibleNode()->isScrollable();
272 bool UiObject::isSelectable() const
274 return getAccessibleNode()->isSelectable();
277 bool UiObject::isSelected() const
279 return getAccessibleNode()->isSelected();
282 bool UiObject::isVisible() const
284 return getAccessibleNode()->isVisible();
287 bool UiObject::isShowing() const
289 return getAccessibleNode()->isShowing();
292 bool UiObject::isActive() const
294 return getAccessibleNode()->isActive();
297 void UiObject::refresh() const
302 void UiObject::updateRoleName() const
304 mNode->updateRoleName();
307 void UiObject::updateUniqueId() const
309 mNode->updateUniqueId();
312 void UiObject::updateName() const
317 void UiObject::updateApplication() const
319 mNode->updateApplication();
322 void UiObject::updateAttributes() const
324 mNode->updateAttributes();
327 void UiObject::updateStates() const
329 mNode->updateStates();
332 void UiObject::updateExtents() const
334 mNode->updateExtents();
337 void UiObject::updateXPath() const
339 mNode->updateXPath();
342 void UiObject::updateValue() const
344 mNode->updateValue();
347 bool UiObject::setFocus() const
349 return mNode->setFocus();
352 bool UiObject::isValid() const
354 return mNode->isValid();
357 const Rect<int> UiObject::getScreenBoundingBox() const
359 return mNode->getScreenBoundingBox();
362 const Rect<int> UiObject::getWindowBoundingBox() const
364 return mNode->getWindowBoundingBox();
367 void UiObject::click() const
369 mNode->updateExtents();
370 const Rect<int> rect = mNode->getScreenBoundingBox();
371 const Point2D<int> midPoint = rect.midPoint();
372 mDevice->click(midPoint.x, midPoint.y);
375 void UiObject::longClick(const unsigned int durationMs) const
377 mNode->updateExtents();
378 const Rect<int> rect = mNode->getScreenBoundingBox();
379 const Point2D<int> midPoint = rect.midPoint();
380 mDevice->click(midPoint.x, midPoint.y, durationMs);
383 bool UiObject::DoAtspiActivate() const
385 return mNode->doAction("activate");
389 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
391 if (mNode == nullptr) throw;
392 // TODO : wait for animation and refresh current node
393 // mDevice->waitForIdle();