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

Unable to inherit from MobileElement class for version 3.1.0 #220

Closed
alewang opened this issue Jul 25, 2015 · 13 comments
Closed

Unable to inherit from MobileElement class for version 3.1.0 #220

alewang opened this issue Jul 25, 2015 · 13 comments
Labels

Comments

@alewang
Copy link
Contributor

alewang commented Jul 25, 2015

I am unable to inherit from the MobileElement class. One of the samples of the errors I see is:

- The return types are incompatible for the inherited methods
FindsByLinkText.findElementsByLinkText(String),
MobileElement.findElementsByLinkText(String)

I took a look through the source code, and it seems the cause is due to the DefaultGenericMobileElement class (MobileElement's parent class) extending from RemoteWebElements and implementing the various interfaces. The method signatures in RemoteWebElements and the Generic* interfaces match exactly, but they have different return types. RemoteWebElement's methods' return types are of the type List, while the return types for the various interfaces are List (with T being the parametrized type).

I would like to extend from the MobileElement class for some very specific functionality. I tried using the @SuppressWarnings annotation with various names (including "all"), but nothing seems to tell Eclipse that this error is not a problem.

What can I do on my end to "fix" this error?

What can I do for Appium to prevent these conflicting, overlapping methods with equivalent signatures from well.... overlapping?

@TikhomirovSergey
Copy link
Contributor

Hi @alewang
Right now I could suggest you to use Intellij Idea 12.x or higher. You have to enable Eclipse java compiler. Also I could suggest you to add the folowing at your pom file:

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerId>eclipse</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-eclipse</artifactId>
                        <version>2.5</version>
                    </dependency>
                </dependencies>
            </plugin>
                 ...
        </plugins>
    </build>

If it is not acceptable solution and it extremally needs to use eclipse then it needs time. Which Eclipse version do you use? I use Eclipse Luna. There are many plugins are installed for my needs (Spring, JBoss tools and more). When I use this Eclipse instance the code like yours is compiled. When I use another instance without these plugins I'm facing the same problem. So one of plugins or their companents manages this code to be compiled. So there is lack of information about Eclipse configuration at README (this info is for contributors).

Why do you have to extend MobileElement? There are two interesting points. The first is that it is possible to find more simple solution. The second is.. I think about a new feature for Appium java client. Maybe it is your case. :)

@TikhomirovSergey
Copy link
Contributor

I'm working on your problem...

@alewang
Copy link
Contributor Author

alewang commented Jul 27, 2015

Hi @TikhomirovSergey!

Thanks for the help. I will give this a try today.

@alewang
Copy link
Contributor Author

alewang commented Jul 27, 2015

Our reason for why we want to extend MobileElement is that we want to cache some data about an element so that we do not have to query the Appium server for that data each time. In one of our particular cases, it was most natural to have the element object itself maintain a reference to its own cached data, so we tried doing that by extending the MobileElement class. We saw an interesting surprise when we changed the java-client version to 3.1.0.

@TikhomirovSergey
Copy link
Contributor

Yeah! It is compiled some unusual way in order to avoid excessive casting from WebElement to MobileElement. Users complained so much. But java has some restrictions.

Why do you not use page objects? Page object design pattern. Page factory for java client.

@alewang
Copy link
Contributor Author

alewang commented Jul 29, 2015

I'll take a look! Thanks for the help.

@TikhomirovSergey
Copy link
Contributor

Do IDEA and it's settings help you?

It is not possible to solve this problem only on Appium side. Fortunately I have a good idea... ;)

Jonahss added a commit that referenced this issue Jul 30, 2015
Minor improvements of the method declaration
@afwang
Copy link

afwang commented Jul 30, 2015

I tried IDEA 14.1.4 with the updated settings in the POM file, but the same error shows up on the child class.

I'm thinking about ways to solve this, and I think the cleanest solution might be for me to go to Selenium's source and open a pull request to make their RemoteWebElements class parametrized. When I have some time, I'll try doing that.

@TikhomirovSergey
Copy link
Contributor

Have you tried to change java compiler to "Eclipse" in IDEA? It's workaround for now

Right now I could suggest you to use Intellij Idea 12.x or higher. You have to enable Eclipse java compiler. Also I could suggest you to add the folowing at your pom file:

@afwang

I'm thinking about ways to solve this, and I think the cleanest solution might be for me to go to Selenium's source and open a pull request to make their RemoteWebElements class parametrized. When I have some time, I'll try doing that.

Actually I'm aready doing this. I'll add some improvements to this PR today or tomorrow: SeleniumHQ/selenium#604

Actually we've tried to propose something similar. That change was rejected. I just forgot about generic construction that you can see here: SeleniumHQ/selenium#604

@afwang
Copy link

afwang commented Jul 30, 2015

Neat, I didn't know I could change the compiler. The error just shows as a warning with the Eclipse compiler.

@TikhomirovSergey
Copy link
Contributor

For somebody who doesn't know how to change compiler

  1. Go to "Settings"

compiler

@afwang It will just allow to compile a subclass.

@TikhomirovSergey
Copy link
Contributor

Please look at SeleniumHQ/selenium#863

@TikhomirovSergey
Copy link
Contributor

Fixed at #413
Will be published at 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants