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 /**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 void SetWantMulti(bool wantMulti); 55 56 bool IsWantMulti() const; 57 58 void Select(const Window window, 59 ElementNodeIterator &elementNodeRef, 60 std::vector<Widget> &visitWidgets, 61 std::vector<int> &targetWidgets) const; 62 63 private: 64 std::vector<WidgetMatchModel> GetSelfMatchers() const; 65 std::unique_ptr<SelectStrategy> ConstructSelectStrategy() const; 66 std::vector<WidgetMatchModel> selfMatchers_; 67 std::vector<WidgetSelector> frontLocators_; 68 std::vector<WidgetSelector> rearLocators_; 69 std::vector<WidgetSelector> parentLocators_; 70 string appLocator_ = ""; 71 bool wantMulti_ = false; 72 }; 73 } // namespace OHOS::uitest 74 75 #endif