Migration to Java 8. API with default implementation. by TikhomirovSergey · Pull Request #470 · appium/java-client

Change list

Epic: #399

  • each one interface extends the io.appium.java_client.ExecutesMethod
  • both AppiumDriver and MobileElement implement io.appium.java_client.ExecutesMethod
  • Current API has default implementation
  • AppiumDriver, MobileElement and subclasses just declare interfaces are implemented.

Types of changes

What types of changes are you proposing/introducing to Java client?

  • 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

We have few targets:

  • We are going to support Windows Mobile automation. Some interesting things were found. It supports some functions which were declared as Android-specific. As well it may support some functions which were declared as iOS-only as well. So we need for very flexible API which allows to implement it easily and without copy-paste.
  • Some users need to use Android/iOS specific functions eventually. Now it should be possible in very pretty way:
import io.appium.java_client.android.StartsActivity;
...

private AppiumDriver<?> driver;

...
       StartsActivity startsActivity = new StartsActivity() {
            @Override
            public Response execute(String driverCommand, Map<String, ?> parameters) {
                return driver.execute(driverCommand, parameters);
            }

            @Override
            public Response execute(String driverCommand) {
                return driver.execute(driverCommand);
            }
        };
        startsActivity.startActivity("yourPackage", "yourActivity");

If somebody wants to use only Selenium and Appium interfaces when even this is possible:

import io.appium.java_client.ExecutesMethod;

public class ExtendedRemoteWebDriver extends RemoteWebDriver implements ExecutesMethod {
...
}

_______________________________________________________________________________________________

import io.appium.java_client.android.StartsActivity;
...

private ExtendedRemoteWebDriver driver;

...
       StartsActivity startsActivity = new StartsActivity() {
            @Override
            public Response execute(String driverCommand, Map<String, ?> parameters) {
                return driver.execute(driverCommand, parameters);
            }

            @Override
            public Response execute(String driverCommand) {
                return driver.execute(driverCommand);
            }
        };
        startsActivity.startActivity("yourPackage", "yourActivity");