Skip to content

A proposed fix for issue 276 (https://github.com/appium/java-client/i… - #278

Merged
Jonahss merged 2 commits into
appium:masterfrom
baechul:master
Dec 4, 2015
Merged

A proposed fix for issue 276 (https://github.com/appium/java-client/i…#278
Jonahss merged 2 commits into
appium:masterfrom
baechul:master

Conversation

@baechul

Copy link
Copy Markdown

…ssues/276)

@baechul

Copy link
Copy Markdown
Author

And here is the usage example:

publicclassHeaderInjectableHttpClientimplementsHttpClient {
privatefinalHttpClientactualClient;
privatefinalMap<String,String> extraHeaders;
publicHeaderInjectableHttpClient(HttpClientactualClient) {
this.actualClient = actualClient;
extraHeaders = newHashMap<>();
}
publicvoidaddHeader(Stringheader, Stringvalue) {
if(header != null) extraHeaders.put(header, value);
}
publicvoidaddHeaders(Map<String,String> headers) {
if(headers != null) extraHeaders.putAll(headers);
}
@OverridepublicHttpResponseexecute(HttpRequestrequest, booleanfollowRedirects) throwsIOException { // intercept and add the given extra headers.for(Stringheader : extraHeaders.keySet()) {
Stringvalue = extraHeaders.get(header);
if(value != null) {
request.addHeader(header, value);
}
}
returnactualClient.execute(request, followRedirects);
}
}
HttpClient.FactoryhttpClientFactory = newApacheHttpClient.Factory() {
@OverridepublicHttpClientcreateClient(URLurl) {
HeaderInjectableHttpClientclient = newHeaderInjectableHttpClient(super.createClient(url));
client.addHeader("name", "value");
}
};
AndroidDriverdriver = newAndroidDriver(url, httpClientFactory, desiredCapabilities);

@TikhomirovSergey

Copy link
Copy Markdown
Contributor

@baechul
Ok. I like this PR 👍 I think it is even better than the passing user's CommandExecutor through constructors because it could be incompatible with whole Appium ecosystem (with client or/and server).

But I have some remarks. My opinion is that proposed changes look bit incomplete. It would be better if you redesigned AppiumCommandExecutor and AppiumDriver the way below :

...
importorg.openqa.selenium.remote.internal.ApacheHttpClient;
...
publicclassAppiumCommandExecutorextendsHttpCommandExecutor{
privatefinalDriverServiceservice;
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URLaddressOfRemoteServer,
HttpClient.FactoryhttpClientFactory) {
super(additionalCommands, addressOfRemoteServer, httpClientFactory);
service = null;
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverServiceservice,
HttpClient.FactoryhttpClientFactory) {
super(additionalCommands, service.getUrl(), httpClientFactory);
this.service = service;
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URLaddressOfRemoteServer) {
this(additionalCommands, addressOfRemoteServer, newApacheHttpClient.Factory());
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverServiceservice) {
this(additionalCommands, service, newApacheHttpClient.Factory());
}
...

and

...
i@SuppressWarnings("unchecked")
publicabstractclassAppiumDriver<RequiredElementTypeextendsWebElement> extendsDefaultGenericMobileDriver<RequiredElementType> {
...
privateAppiumDriver(HttpCommandExecutorexecutor, Capabilitiescapabilities){
super(executor, capabilities);
this.executeMethod = newAppiumExecutionMethod(this);
locationContext = newRemoteLocationContext(executeMethod);
super.setErrorHandler(errorHandler);
this.remoteAddress = executor.getAddressOfRemoteServer();
}
publicAppiumDriver(URLremoteAddress, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), remoteAddress), desiredCapabilities);
}
publicAppiumDriver(URLremoteAddress, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), remoteAddress, httpClientFactory), desiredCapabilities);
}
publicAppiumDriver(AppiumDriverLocalServiceservice, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), service), desiredCapabilities);
}
publicAppiumDriver(AppiumDriverLocalServiceservice, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), service, httpClientFactory), desiredCapabilities);
}
publicAppiumDriver(AppiumServiceBuilderbuilder, CapabilitiesdesiredCapabilities) {
this(builder.build(), desiredCapabilities);
}
publicAppiumDriver(AppiumServiceBuilderbuilder, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(builder.build(), httpClientFactory, desiredCapabilities);
}
publicAppiumDriver(CapabilitiesdesiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);
}
publicAppiumDriver(HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, desiredCapabilities);
}
...

and add new public constructors to AndroidDriver/IOSDriver.

I just think that other users would like to use the new capability (you probably too) combined with the AppiumDriverLocalService.

I was managed to make this improvement locally. It works!

If you improve your PR the way above then there won't be necessity to cover the new capability with tests and the only way to shoot user's leg will be the implementation of a bad httpClientFactory (and only a user will be responsible) :)

@Jonahss@bootstraponline
Please look at this PR.

@TikhomirovSergey

Copy link
Copy Markdown
Contributor

#276

…builder parameters as suggested by Tikhomirov Sergey
@baechul

Copy link
Copy Markdown
Author

Makes sense. Added the same capability for the constructors with localservice and builder parameters as suggested.

BTW when is the next release? Can this be merged for the next release?

@TikhomirovSergey

Copy link
Copy Markdown
Contributor

I think this feature will be included to the new build. Let's wait for some time.

Jonahss added a commit that referenced this pull request Dec 4, 2015
@Jonahss
Jonahss merged commit 07fe6d4 into appium:masterDec 4, 2015
@Jonahss

Copy link
Copy Markdown
Member

merged.

Ok, let's see where we are on a release. I think there's some outstanding pull requests, and then we should publish.

@baechul

Copy link
Copy Markdown
Author

Great. Thanks.

Sign up for freeto 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.

3 participants

@baechul@TikhomirovSergey@Jonahss