Change default strategy for @HowToUseLocators programatically

Aperta
#2,122 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java

Direzione di ricerca

Inizia leggendo la sezione Page-objects.md e il Javadoc di HowToUseLocators, quindi esamina come PageFactory.initElements e AppiumFieldDecorator applicano le strategie di localizzazione. Definisci come un valore predefinito a livello di pagina debba coesistere con le annotazioni a livello di elemento e conferma che le strategie esplicite esistenti rimangano efficaci. Il lavoro è completato quando un’unica configurazione a livello di pagina funziona per gli elementi altrimenti privi di annotazioni ed è coperta da test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
1.3k
Fork
752
Merge medio
6g 21h
PR unite (30g)
8

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di appium/java-client

Tutte le issue di appium/java-client

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.