• 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 "select_strategy.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 WidgetMatchModel &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 appName);
45 
46         std::string GetAppLocator() const;
47 
48         void AddDisplayLocator(int32_t displayId);
49 
50         std::int32_t GetDisplayLocator() 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         void SetWantMulti(bool wantMulti);
61 
62         bool IsWantMulti() const;
63 
64         void Select(const Window window,
65                     ElementNodeIterator &elementNodeRef,
66                     std::vector<Widget> &visitWidgets,
67                     std::vector<int> &targetWidgets) const;
68 
69     private:
70         std::vector<WidgetMatchModel> GetSelfMatchers() const;
71         std::unique_ptr<SelectStrategy> ConstructSelectStrategy() const;
72         std::vector<WidgetMatchModel> selfMatchers_;
73         std::vector<WidgetSelector> frontLocators_;
74         std::vector<WidgetSelector> rearLocators_;
75         std::vector<WidgetSelector> parentLocators_;
76         string appLocator_ = "";
77         bool wantMulti_ = false;
78         int32_t displayLocator_ = -1;
79     };
80 } // namespace OHOS::uitest
81 
82 #endif