Skip to content

Commit

Permalink
Merge pull request #278 from baechul/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonahss committed Dec 4, 2015
2 parents 90b4a1b + 8232eb3 commit 07fe6d4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 12 deletions.
29 changes: 23 additions & 6 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Set;

import static io.appium.java_client.MobileCommand.*;
import org.openqa.selenium.remote.http.HttpClient;

/**
* @param <RequiredElementType> means the required type from the list of allowed types below
Expand Down Expand Up @@ -156,34 +157,50 @@ protected static ImmutableMap<String, Object> getCommandImmutableMap(
return builder.build();
}

private AppiumDriver(CommandExecutor executor, Capabilities capabilities){
private AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities){
super(executor, capabilities);
this.executeMethod = new AppiumExecutionMethod(this);
locationContext = new RemoteLocationContext(executeMethod);
super.setErrorHandler(errorHandler);
this.remoteAddress = executor.getAddressOfRemoteServer();
}

public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(
getMobileCommands(), remoteAddress), desiredCapabilities);
this.remoteAddress = remoteAddress;
}

public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(
getMobileCommands(), remoteAddress, httpClientFactory), desiredCapabilities);
}

public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(
getMobileCommands(), service), desiredCapabilities);
this.remoteAddress = service.getUrl();
}

public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(
getMobileCommands(), service, httpClientFactory), desiredCapabilities);
}

public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {
this(builder.build(), desiredCapabilities);
}


public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
this(builder.build(), httpClientFactory, desiredCapabilities);
}

public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, desiredCapabilities);
}

public AppiumDriver(Capabilities desiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);
}


@Override
protected Response execute(String command) {
return super.execute(command, ImmutableMap.<String, Object>of());
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static io.appium.java_client.remote.MobileCapabilityType.APP_WAIT_ACTIVITY;
import static io.appium.java_client.remote.MobileCapabilityType.APP_WAIT_PACKAGE;
import static io.appium.java_client.remote.MobileCapabilityType.DONT_STOP_APP_ON_RESET;
import org.openqa.selenium.remote.http.HttpClient;

/**
* @param <RequiredElementType> means the required type from the list of allowed types below
Expand Down Expand Up @@ -81,19 +82,43 @@ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(remoteAddress, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {
super(service, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(service, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {
super(builder, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}


public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(builder, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(httpClientFactory, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

public AndroidDriver(Capabilities desiredCapabilities) {
super(substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;

import static io.appium.java_client.MobileCommand.*;
import org.openqa.selenium.remote.http.HttpClient;

/**
* @param <RequiredElementType> means the required type from the list of allowed types below
Expand All @@ -56,18 +57,42 @@ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(remoteAddress, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {
super(service, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(service, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {
super(builder, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(builder, httpClientFactory, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
super(httpClientFactory, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

public IOSDriver(Capabilities desiredCapabilities) {
super(substituteMobilePlatform(desiredCapabilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,35 @@
import java.net.ConnectException;
import java.net.URL;
import java.util.Map;
import org.openqa.selenium.remote.internal.ApacheHttpClient;

public class AppiumCommandExecutor extends HttpCommandExecutor{

private final DriverService service;

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer) {
super(additionalCommands, addressOfRemoteServer);
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
URL addressOfRemoteServer,
HttpClient.Factory httpClientFactory) {
super(additionalCommands, addressOfRemoteServer, httpClientFactory);
service = null;
}

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service) {
super(additionalCommands, service.getUrl());

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
DriverService service,
HttpClient.Factory httpClientFactory) {
super(additionalCommands, service.getUrl(), httpClientFactory);
this.service = service;
}

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
URL addressOfRemoteServer) {
this(additionalCommands, addressOfRemoteServer, new ApacheHttpClient.Factory());
}

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
DriverService service) {
this(additionalCommands, service, new ApacheHttpClient.Factory());
}

@Override
public Response execute(Command command) throws IOException, WebDriverException {
Expand Down

0 comments on commit 07fe6d4

Please sign in to comment.