-
-
Notifications
You must be signed in to change notification settings - Fork 759
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
#228 fix: The extension of the Page Object design pattern #267
Conversation
Also drafts of the new feature
OverrideWidget
Next steps are: - implementation of the Widget intercepting - providing if test coverage.
The test designing has been started
TODO: - iOS case should be covered with tests - implementation of a fully crossplatform test
@Jonahss @bootstraponline please look at this. Do you like this PR? :) @Simon-Kaz, @saikrishna321 you are invited too :) Please look at this before it will have been merged |
@@ -87,7 +87,6 @@ More can be found in the docs, but here's a quick list of features which this pr | |||
- lockScreen() | |||
- isLocked() | |||
- shake() | |||
- complexFind() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think COMPLEX_FIND is still supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed here
329e84e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
complexfind is still referenced in MobileCommand.java . is this done on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rompic
It is need to think about. Anyway it is not in scope of this PR.
And anyway it should be removed if it useless.
I'm really impressed with this pull request. I think end users will benefit from a robust page object implementation. It's also fantastic that the PR includes tests so people know how to use the feature. I'm worried that some of the coding styles adopted in java-client easily lend themselves to bugs. For example, I think we're better off always using braces for In general I'm a fan of the effective Java approach and Google's style guide. I know it's outside the scope of this PR, however it'd be nice to integrate static analysis tools into the java-client pull request workflow similar to how appium and appium's ruby bindings run lint tools automatically. For Java, I'd recommend checking out google-java-format I think as the code base continues to grow and people contribute, there's an increasing risk of diminishing quality without adopting automatic style formatting. |
@bootstraponline |
Nice. I don't realen understand the chained example. Can you provide an example? |
@rompic All samples are available here. They are proposed in this PR. |
I meant the expected result is not really clear to me. Does it look for all elements using the defined strategies? Btw. I noticed a typo in the first example where some of the methods are called reviev instead of review. great work! |
It means that all locators are used by a chain of searchings. E.g. some element is expected to be found by the first defined by-strategy, a next element should be found from this one and by the second defined by-strategy and so on. The expected result is an element or list of elements found by the last defined by-strategy from a previously found elemen in this chain. FindByAll means that an element or list of elements could be found by any (!!!) of defined locators. There is no chain like above. If the using of some locator has a positive result at this moment (an element is found/size of a list is greater than zero) the the searching is being stopped and the result is being returned. I'm suspecting that there is the naming issue. But this naming was borrowed and it is convinient to Selenium project. Thank you for the remark. This typo will be improved. |
#228 fix: The extension of the Page Object design pattern
Hello, I'm new in Appium. Ex. Let the structure of my classes be like: public class ChatMessages {
@iOSFindBy(className = "UIATableCell")
private List<Message> messageList;
}
public class Message extends Widget {
public Message(WebElement element) {
super(element);
}
@iOSFindBy(className = "UIAStaticText")
public IOSElement userNameElement;
@iOSFindBy(className = "UIAStaticText")
public IOSElement messageElement;
} And all I know that messageElement is the second in cell. How can I get valid element? |
Finally I did it. public class Message extends Widget {
public Message(WebElement element) {
super(element);
}
@iOSFindBy(uiAutomator = ".staticTexts()[0]")
private IOSElement userNameElement;
@iOSFindBy(uiAutomator = ".staticTexts()[1]")
private IOSElement messageElement;
} But I'm still looking other ways to do this. |
Hi @SButterfly |
Change list:
Use cases which are already provided
Information about Page Object design pattern.. Information about PageFactory.
WebElement/list of WebElement field can be populated by default:
If there is need to use convinient locators for mobile native applications then the following is available:
The example for the crossplatform mobile native testing
The fully cross platform examle
Also it is possible to define chained or any possible locators.
Appium Java client is integrated with Selenium PageFactory by AppiumFieldDecorator.
Examples of ways to populate object fields are below:
If time of the waiting for elements differs from usual (longer, or shorter when element is needed only for quick checkings/assertions) then
All mentioned use cases are provided and will be provided further. Below is the new additional option.
Details of the new feature
This feature was designed for the typifying of commonly used groups of elements which are nested in some root element. That should to allow end user the describe of pages/screens in terms of widgets instead of elements. This development was inspired by the Html Elements framework by Yandex. But there is no copy/paste and proposed code is completely original.
The simple example
Let's imagine that the task is to check an Android client of the http://www.rottentomatoes.com. Let it be like a picture below
Lets imagine that it is only a part of the screen.
A typical page object could look like:
The description above can be decomposed. Let's work it out!
Firstly a Movie-widget could be described this way:
So, now page object looks
Ok. What if Movie-class is reused and a wrapped root element is usually found by the same locator?
Then
and
Ok. What if movie list is not a whole screen? E.g. we want to descride it as a widget with nested movies.
Then:
and
Good! How to poputate all these fields?
As usual:
Specification
A class which describes a widget or group of elements should extend
Any widget/group of elements can be described it terms of sub-elements or nested sub-widgets.
Appium-specific annotations are used for this purpose.
Any class which describes the real widget or group of elements can be annotated
That means that when the same "widget" is used frequently and any root element of this can be found by the same locator then user can
and then it is enough
If the widget really should be found using an another locator then
Ok. What should users do if they want to implement a subclass which describes a similar group of elements for the same platform?
There is nothing special.
and
Is it possible to reuse "widgets" in crossplatform testing?
If there is no special details of interaction with an application browser version and/or versions for different mobile OS's then
What if interaction with a "widget" has special details for each used platform, but the same at high-level
Then it is possible
and
and
and even
and then
This use case has some restrictions;
I think that this problem will be resolved next time.
Good! What about widget lists?
All that has been mentioned above is true for "widget" lists.
One more restriction
It is strongly recommended to implement each subclass of io.appium.java_client.pagefactory.Widget with this constructor