Skip to content
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

refactor: avoid casting to RemoteWebElement #1345

Merged
merged 2 commits into from
May 14, 2020
Merged

refactor: avoid casting to RemoteWebElement #1345

merged 2 commits into from
May 14, 2020

Conversation

asolntsev
Copy link
Contributor

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 x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

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

* 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.
@@ -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",
(RemoteWebElement.class.isAssignableFrom(element.getClass())));
elementId = RemoteWebElement.class.cast(element).getId();
(HasIdentity.class.isAssignableFrom(element.getClass())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not to use instanceof?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I just tried to make a minimal change. You never know what can go wrong. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is ideal. Lets do it properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

(RemoteWebElement.class.isAssignableFrom(element.getClass())));
elementId = RemoteWebElement.class.cast(element).getId();
(HasIdentity.class.isAssignableFrom(element.getClass())));
elementId = HasIdentity.class.cast(element).getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can explicit typecast be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message should be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mykola-mokhnach mykola-mokhnach merged commit 7915d34 into appium:master May 14, 2020
@asolntsev asolntsev deleted the avoid-casting-to-remote-web-element branch May 14, 2020 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants