• 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         explicit WidgetSelector(bool addVisibleMatcher = true);
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         void AddParentLocator(const WidgetSelector &selector, ApiCallErr &error);
43 
44         void AddAppLocator(string app);
45 
46         std::string GetAppLocator() const;
47 
48         /**Select all the matched widgets on the given tree. Results are arranged in the
49          * receiver in <b>DFS</b> order. */
50         void Select(const WidgetTree &tree, std::vector<std::reference_wrapper<const Widget>> &results) const;
51 
52         /**Returns a description of this selector.*/
53         std::string Describe() const;
54 
GetFrontendClassDef()55         const FrontEndClassDef& GetFrontendClassDef() const override
56         {
57             return ON_DEF;
58         }
59 
60     private:
61         std::vector<WidgetAttrMatcher> selfMatchers_;
62         std::vector<WidgetSelector> frontLocators_;
63         std::vector<WidgetSelector> rearLocators_;
64         std::vector<WidgetSelector> parentLocators_;
65         string appLocator_ = "";
66     };
67 }
68 
69 #endif