refactor: avoid casting to RemoteWebElement#1345
Merged
mykola-mokhnach merged 2 commits intoappium:masterfrom May 14, 2020
asolntsev:avoid-casting-to-remote-web-element
Merged
refactor: avoid casting to RemoteWebElement#1345mykola-mokhnach merged 2 commits intoappium:masterfrom asolntsev:avoid-casting-to-remote-web-element
mykola-mokhnach merged 2 commits intoappium:masterfrom
asolntsev:avoid-casting-to-remote-web-element
Conversation
* instead, cast to interface HasIdentity (because it's a weaker type). * this commit is similar to https://github.com/appium/java-client/pull/432/files Some background: as a developer of framework which uses proxies for WebElement (Selenide), I cannot create proxy for RemoteWebElement since it's an abstract class, not interface.
| + "extends org.openqa.selenium.remote.RemoteWebElement", | ||
| (RemoteWebElement.class.isAssignableFrom(element.getClass()))); | ||
| elementId = RemoteWebElement.class.cast(element).getId(); | ||
| (HasIdentity.class.isAssignableFrom(element.getClass()))); |
Contributor
There was a problem hiding this comment.
why not to use instanceof?
Contributor
Author
There was a problem hiding this comment.
I don't know. I just tried to make a minimal change. You never know what can go wrong. :)
Contributor
There was a problem hiding this comment.
Nothing is ideal. Lets do it properly
| (RemoteWebElement.class.isAssignableFrom(element.getClass()))); | ||
| elementId = RemoteWebElement.class.cast(element).getId(); | ||
| (HasIdentity.class.isAssignableFrom(element.getClass()))); | ||
| elementId = HasIdentity.class.cast(element).getId(); |
Contributor
There was a problem hiding this comment.
can explicit typecast be used here?
| @@ -85,8 +85,8 @@ public ElementOption withElement(WebElement element) { | |||
| checkNotNull(element); | |||
| checkArgument(true, "Element should be an instance of the class which " | |||
| + "extends org.openqa.selenium.remote.RemoteWebElement", | |||
Contributor
There was a problem hiding this comment.
this message should be updated
mykola-mokhnach
approved these changes
May 13, 2020
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Some background: as a developer of framework which uses proxies for WebElement (Selenide), I cannot create proxy for RemoteWebElement since it's an abstract class, not interface.
Change list
Please provide briefly described change list which are you going to propose.
Types of changes
What types of changes are you proposing/introducing to Java client?
Put an
xin the boxes that applyDetails
Please provide more details about changes if it is necessary. If there are new features you can provide code samples which show the way they
work and possible use cases. Also you can create gists with pasted java code samples or put them here using markdown.
About markdown please read Mastering markdown and Writing on GitHub