Uh oh!
There was an error while loading. Please reload this page.
Java: All searching interfaces are made generic - #863
Conversation
lukeis
commented
Jul 31, 2015
TikhomirovSergey
commented
Jul 31, 2015
TikhomirovSergey
commented
Jul 31, 2015
Ok guys, thanks for remarks |
lukeis
commented
Jul 31, 2015
can't assume @alexec has, since he never mentioned it in the other PR and hasn't had a commit merged in the selenium tree. |
TikhomirovSergey
commented
Jul 31, 2015
lukeis
commented
Jul 31, 2015
duplicating is the same as "copying" and since alexec's employer could potentially claim copyright on that code if we 'copied' since he hasn't signed the CLA.... then no, you can't duplicate it. And I would then suggest you remove his commits from your tree. That being said, it would then be nice to have an additional test ;) |
TikhomirovSergey
commented
Jul 31, 2015
Ok. So I'll make improvements that are required soon... |
alexec
commented
Aug 1, 2015
Hi everyone, I'm not sure if I've signed the CLA. If you really need to me too, then just let me know. |
TikhomirovSergey
commented
Aug 1, 2015
@alexec Yeah, we really need you. Btw. Can you squash your commits? |
alexec
commented
Aug 2, 2015
CLA signed. I'm afraid I don't know how to squash commits. |
TikhomirovSergey
commented
Aug 2, 2015
@alexec Please try something like that: git reset --soft head~8 |
alexec
commented
Aug 2, 2015
I got weird merge issue. I don't know how to do this and it'll take me ages to figure out. Do you think you could do it please? |
TikhomirovSergey
commented
Aug 2, 2015
ok. I'll try this later... |
TikhomirovSergey
commented
Aug 2, 2015
TikhomirovSergey
commented
Aug 9, 2015
Oh my god! There were problems with the merging... I'll add soon all that was required |
TikhomirovSergey
commented
Aug 9, 2015
There were problems with the merging... So the new commit was delayed What I've done:
<TextendsWebElement> List<T> findElements
<TextendsWebElement> TfindElementThe same way were enhanced WebElement and WebDriver. Their common implementations work as usual. There shouldn't be backward compatibility issues.
Actually I don't know what test I can make up. All this project is like a test stand for this change. |
jleyba
commented
Aug 17, 2015
No further comments on the actual code. At the design level, I'm not sure how I feel about the lack of type safety this introduces: This is now perfectly valid (and I guess the point), but the |
TikhomirovSergey
commented
Aug 17, 2015
@jleyba Ok. Does it makes sense to declare the following: <TextendsWebElement> List<T> findElements(Byby) throwsClassCastException;
<TextendsWebElement> TfindElement(Byby) throwsClassCastException;? Actially this enhancement is supposed to be used when there is need to implement user's customized WebDriver/WebElement. I think that it makes sense to point these special things out at documentation if this is supposed to be merged... |
6381978 to
a140a04Comparea140a04 to
48453b0Compare004a6fb to
ad00dd5CompareThe problem: There are many Selenium-based projects such as Appium (java_client), Selendroid, IOSDriver and so on. They are used not only for the web/browser testing and they have their own WebElement implementations. Also there is probably need to re-implement all changed interfaces for some end user purposes. Current design doesn't allow user to use their own WebElement subclasses without additional casting. It is annoying and makes code dirty. Any trying to avoid this causes problems. This change is backward compatible with existing projects and will allow to create factories or user's customized Webdrivers and WebElements that return desired WebElement subclasses.
TikhomirovSergey
commented
Sep 13, 2015
@ddavison |
There was a problem hiding this comment.
Are these comments about ClassCastException unnecessary? ClassCastException is unchecked.
There was a problem hiding this comment.
@alexec this is just information. If end users will re-implement the proposed API then there won't be any problem. An end user will face a problem when they use common Selenium implementations, because it not so flexible like API.
cyril265
commented
Oct 9, 2015
Why is there a need to make the interfaces generic? My only issue is with the The following will break without compile error or warning if you change the implementation of the webdriver: Or am I missing something? |
TikhomirovSergey
commented
Oct 10, 2015
@squallified There are some problems:
and
There shouldn't be any compilation problem if API will be changed the proposed way. As you see all tests have passed. There are possible "warnings" when you are trying to re-implement the proposed API forcing finders (WebDriver/WebElement) to return your own WebElement subclass.
This is just an attempt to make API a bit more convenient and flexible. 😄 |
cyril265
commented
Oct 12, 2015
You can fix the first example by changing the return type of the findElement method in your subclass: This doesn't work for the findElements method though. For this to work the method signature in the interface needs to be changed to: I agree that findElements needs to be changed (either generic interface or a wildcard). I guess it's just a preference thing. |
TikhomirovSergey
commented
Oct 13, 2015
@squallified So the proposed PR allows end user to use API and it don't force user to use only certain implementations if their project contains a customized WebElement implementation which their own WebDrivers return: WebDriverd;
CustomWebElement = d.findElement(By.id("test")) //works with these changesList<CustomWebElement> = d.findElements(By.id("test")) //works with these changesSo it is one more advantage of proposed changes. |
coding-yogi
commented
Nov 3, 2015
Following |
bootstraponline
commented
Nov 11, 2015
👍 |
jleyba
commented
Nov 12, 2015
I prefer @squallified 's suggestion of changing findElements to |
TikhomirovSergey
commented
Nov 12, 2015
@jleyba |
TikhomirovSergey
commented
Nov 15, 2015
@jleyba The simple sample:
As you can see the first class was extended without problems. Ok. Lets go ahead. but The same is true for our case. I was able to build API artefact. There were lots of compilation errors. And now we can see: Summary: So I'll keep this PR as is. Advantages:
Disadvantages:
Related threads where the mentioned wildcard problem was discussed: |
TikhomirovSergey
commented
Nov 20, 2015
It is possible that proposed code will be changed the way below: publicinterfaceSearchContext<TextendsWebElement> {
List<T> findElements(Byby);
TfindElement(Byby);
}
publicinterfaceWebdriver<TextendsWebElement> extendsSearchContext<T> {
...
List<T> findElements(Byby);
TfindElement(Byby);
...
}
publicclassRemoteWebDriverimplementsWebdriver<WebElement> {
...
}How do you feel about that change? It alows to avoid API contract problems but users will face rawtype warning at the first time. I think it is very major change... |
vsadineni1
commented
Sep 27, 2018
Hello there, Relevant discussion on the appium project - appium/java-client#1021 |
lukeis
commented
Sep 27, 2018
Venkata, your tone of voice in your comment is entitled. Please read what you write before you post on open source projects. Your issue, shouldn't be an issue at all for the selenium project and you'll need to follow up with the appium developers. Please read my comment on this other issue raised and referenced in this PR: As it stands, I think this PR might never get merged (it currently has merge conflicts too). I've also come to dislike the style of generics used here as it can cause many unintended side effects and makes for refactoring code a very difficult chore to unwind. |
vsadineni1
commented
Sep 28, 2018
Luke, Yes, I checked with appium devs. They sounded like the PR is pending with selenium that is why we have to duplicate the classes in appium. |
|
diemol
commented
May 19, 2020
Apologies for the poor handling of this PR by our side, nevertheless it looks like the approach was never fully accepted. On the other hand, I can see that the purpose of this PR was achieved in the end through the implementation of generics in the Java bindings for Appium, in this PR appium/java-client#413. |











The problem:
There are many Selenium-based projects such as Appium (java_client),
Selendroid, IOSDriver and so on. They are used not only
for the web/browser testing and they have their own WebElement
implementations. Also there is probably need to re-implement all changed
interfaces for some end user purposes.
Current design doesn't allow user to use their own WebElement subclasses
without additional casting. It is annoying and makes code dirty. Any
trying to avoid this causes problems.
This change is backward compatible with existing projects and
will allow to create factories or user's customized Webdrivers and
WebElements that return desired WebElement subclasses.
This change is