Repository navigation
feat(pagefactory): support custom @PageFactoryFinder locator annotations #2499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hoanle0126
wants to merge
4
commits into
appium:master
Choose a base branch
from
hoanle0126:feat/custom-findby-annotations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,293
−84
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a0789c5
feat(pagefactory): support custom @PageFactoryFinder locator annotations
hoanle0126 6f511b1
Merge remote-tracking branch 'upstream/master' into feat/custom-findb…
hoanle0126 fcc8fb0
fix(pagefactory): keep @PageFactoryFinder non-breaking and deduplicat…
hoanle0126 c5f3892
fix(pagefactory): address review feedback on finder validation and Se…
hoanle0126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/io/appium/java_client/support/PageFactoryFinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.appium.java_client.support; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** Marks a custom locator annotation with its builder class. */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| public @interface PageFactoryFinder { | ||
| /** | ||
| * Specify the builder implementation used to construct a locator from the annotated type. | ||
| * | ||
| * @return the builder class | ||
| */ | ||
| Class<? extends AbstractFindByBuilder<?>> value(); | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
src/main/java/io/appium/java_client/support/pagefactory/Annotations.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.appium.java_client.support.pagefactory; | ||
|
|
||
| import io.appium.java_client.support.ByIdOrName; | ||
| import io.appium.java_client.support.CacheLookup; | ||
| import io.appium.java_client.support.pagefactory.internal.PageFactoryFinderSupport; | ||
| import org.openqa.selenium.By; | ||
|
|
||
| import java.lang.reflect.Field; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| /** | ||
| * Processes locator and cache annotations on a page object field. | ||
| * | ||
| * <p>Selenium's protected {@code AbstractAnnotations} hooks ({@code buildByFromFindBy}, | ||
| * {@code buildByFromShortFindBy}, {@code buildByFromLongFindBy}, {@code assertValidFindBys}, | ||
| * and {@code assertValidFindAll}) are intentionally omitted because finder resolution and | ||
| * conflict validation are centralized in {@link PageFactoryFinderSupport} via | ||
| * {@link io.appium.java_client.support.PageFactoryFinder} and | ||
| * {@link io.appium.java_client.support.AbstractFindByBuilder}. | ||
| */ | ||
| public class Annotations extends AbstractAnnotations { | ||
| private final Field field; | ||
|
|
||
| /** | ||
| * Creates an annotation processor for the given field. | ||
| * | ||
| * @param field the field to inspect | ||
| */ | ||
| public Annotations(Field field) { | ||
| this.field = requireNonNull(field, "Field must not be null"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLookupCached() { | ||
| return PageFactoryFinderSupport.isCompatibleAnnotationPresent(field, CacheLookup.class); | ||
| } | ||
|
|
||
| @Override | ||
| public By buildBy() { | ||
|
mykola-mokhnach marked this conversation as resolved.
Resolved
|
||
| assertValidAnnotations(); | ||
|
|
||
| By ans = PageFactoryFinderSupport.buildBy(field); | ||
| if (ans == null) { | ||
| ans = buildByFromDefault(); | ||
| } | ||
| return ans; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the annotated field handled by this instance. | ||
| * | ||
| * @return the field | ||
| */ | ||
| protected Field getField() { | ||
| return field; | ||
| } | ||
|
|
||
| /** | ||
| * Builds the fallback locator when no locator annotation produces one. | ||
| * | ||
| * @return a locator using the field name | ||
| */ | ||
| protected By buildByFromDefault() { | ||
| return new ByIdOrName(field.getName()); | ||
| } | ||
|
|
||
| /** Verifies that mutually exclusive locator annotations are not combined on the field. */ | ||
| protected void assertValidAnnotations() { | ||
| PageFactoryFinderSupport.validateFinderAnnotations(field); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.