Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Change default strategy for @HowToUseLocators programatically

Ouverte
#2,122 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 5 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
30/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
java

Piste de recherche

Commencez par lire la section Page-objects.md et la Javadoc de HowToUseLocators, puis examinez comment PageFactory.initElements et AppiumFieldDecorator appliquent les stratégies de localisation. Définissez comment une valeur par défaut au niveau de la page doit coexister avec les annotations au niveau des éléments, et confirmez que les stratégies explicites existantes restent effectives. Le travail est terminé lorsqu’une configuration unique au niveau de la page fonctionne pour les éléments qui ne sont pas annotés autrement et est couverte par des tests.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Java
Étoiles
1.3k
Forks
755
Merge moyen
5 j 14 h
PR mergées (30 j)
8

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de appium/java-client

Toutes les issues de appium/java-client

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.