• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef WIDGET_SELECTOR_H
17 #define WIDGET_SELECTOR_H
18 
19 #include "frontend_api_handler.h"
20 #include "widget_matcher.h"
21 
22 namespace OHOS::uitest {
23     /**
24      * Selector that searches Widgets on the given WidgetTree according to the matchers
25      * of the target widget and its adjacent (front/rear/ancestor/descendant) widgets.
26      * */
27     class WidgetSelector : public BackendClass {
28     public:
29         WidgetSelector() = default;
30 
~WidgetSelector()31         ~WidgetSelector() override {};
32 
33         /**Add a matcher as the target widget attribute requirement.*/
34         void AddMatcher(const WidgetAttrMatcher &matcher);
35 
36         /**Add a selector as the front locator widget requirement.*/
37         void AddFrontLocator(const WidgetSelector &selector, ApiCallErr &error);
38 
39         /**Add a selector as the rear locator widget requirement.*/
40         void AddRearLocator(const WidgetSelector &selector, ApiCallErr &error);
41 
42         /**Select all the matched widgets on the given tree. Results are arranged in the
43          * receiver in <b>DFS</b> order. */
44         void Select(const WidgetTree &tree, std::vector<std::reference_wrapper<const Widget>> &results) const;
45 
46         /**Returns a description of this selector.*/
47         std::string Describe() const;
48 
GetFrontendClassDef()49         const FrontEndClassDef& GetFrontendClassDef() const override
50         {
51             return ON_DEF;
52         }
53 
54     private:
55         std::vector<WidgetAttrMatcher> selfMatchers_;
56         std::vector<WidgetSelector> frontLocators_;
57         std::vector<WidgetSelector> rearLocators_;
58     };
59 }
60 
61 #endif