Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Change default strategy for @HowToUseLocators programatically

Đang mở
#2,122 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java

Hướng nghiên cứu

Bắt đầu bằng cách đọc phần Page-objects.md và Javadoc của HowToUseLocators, sau đó kiểm tra cách PageFactory.initElements và AppiumFieldDecorator áp dụng các chiến lược định vị. Xác định cách một mặc định ở cấp trang sẽ cùng tồn tại với các annotation ở cấp phần tử, đồng thời xác nhận rằng các chiến lược rõ ràng hiện có vẫn tiếp tục có hiệu lực. Hoàn thành khi một cấu hình duy nhất ở cấp trang hoạt động với các phần tử không được gắn annotation và được kiểm thử.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

Description

Appium provides a way to use multiple locator startegies via @HowToUseLocators annotation. The default starategy is set to LocatorGroupStrategy.CHAIN, so if we want to use the alternative strategy i.e. LocatorGroupStrategy.ALL_POSSIBLE, then we need to annotate our WebElements via

@HowToUseLocators(androidAutomation = ALL_POSSIBLE, iOSAutomation = ALL_POSSIBLE)
@FindAll{@FindBy(someStrategy1), @FindBy(someStrategy2)}) 
@AndroidFindBy(someStrategy1) @AndroidFindBy(someStrategy2) 
@iOSFindBy(someStrategy1) @iOSFindBy(someStrategy2) 
RemoteWebElement someElement;

More on this here:
https://github.com/appium/java-client/blob/master/docs/Page-objects.md#--any-possible
https://www.javadoc.io/doc/io.appium/java-client/latest/io/appium/java_client/pagefactory/HowToUseLocators.html

The problem is that we have many WebElements and almost all of them use the LocatorGroupStrategy.ALL_POSSIBLE. This means that for each of the WebElement we have to write an additional line to annotate it with @HowToUseLocators(androidAutomation = ALL_POSSIBLE, iOSAutomation = ALL_POSSIBLE). This causes alot of repetitive code which could be avoided by changing the default strategy in one place.

I am looking for a way to set the default strategy at single place, so it can be applied to all the WebElements unless it is annotated differently.

Is there a way to achieve this currently? If not, would you be interested in adding this functionality to page objects?

Environment

  • Appium Java client 9.1.0

Details

Perhaps we can set this via following ways by passing an extra parameter which changes the default strategy for web elements of page:

PageFactory.initElements(new AppiumFieldDecorator(searchContext, 
	    new TimeOutDuration(15, TimeUnit.SECONDS),
            HowToUseLocators(androidAutomation = ALL_POSSIBLE, iOSAutomation = ALL_POSSIBLE)
            ), 
           pageObject
);

Code To Reproduce Issue [ Good To Have ]

Please remember: it's easier to reproduce and fix the bug with sample code.
You can git clone https://github.com/appium/appium/tree/master/sample-code or https://github.com/appium/appium/tree/master/sample-code/apps and reproduce an issue using Java and sample apps.
Also you can create a gist with pasted java code sample or put it here using markdown. About markdown please read Mastering markdown and
Writing on GitHub

Exception Stacktraces

Please create a gist with the pasted stacktrace of the exception thrown by java.

Link To Appium Logs

Please create a gist which is a paste of your full Appium logs, and link them here. Do not paste your full Appium logs here, as it will make this issue very long and hard to read!
If you are reporting a bug, always include Appium logs as linked gists! It helps to define the problem correctly and clearly.

Ngôn ngữ chính
Java
Star
1.3k
Fork
752
Merge trung bình
5 ngày 14 giờ
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của appium/java-client

Tất cả issue của appium/java-client

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.