-
-
Notifications
You must be signed in to change notification settings - Fork 768
feat: add directConnect feature #1747
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
Changes from all commits
51d7c1e
65e494f
05d0976
5c3f950
a5c3baa
48b42e8
55ad185
d0ff28a
16dd824
0125a97
138fbd4
03833d7
2a89299
97e8b62
821c89d
08a4d01
0afaf50
e6ea969
9ee52cb
11c54b5
e7a751a
790857d
fc96519
1751304
160cf8e
8862d75
d923503
139161b
3b576aa
5358125
ca93f6e
bd1f78c
bab6830
8d9b785
839df21
ec63fb1
0460169
6db723c
c2676ee
7326811
397f596
9cc5e4a
f2dc84a
c00697d
b1a9413
9ab8547
e455f52
f6570d2
69ff238
7b2ff2a
bd0395b
0a11b8a
bfdd997
6d3d3ec
26ded53
1961a1d
35547b5
c31226e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client; | ||
|
||
import org.openqa.selenium.Credentials; | ||
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.remote.http.AddSeleniumUserAgent; | ||
import org.openqa.selenium.remote.http.ClientConfig; | ||
import org.openqa.selenium.remote.http.Filter; | ||
|
||
import java.net.Proxy; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.time.Duration; | ||
|
||
/** | ||
* A class to store the appium http client configuration. | ||
*/ | ||
public class AppiumClientConfig extends ClientConfig { | ||
private final boolean directConnect; | ||
|
||
private static final Filter DEFAULT_FILTER = new AddSeleniumUserAgent(); | ||
|
||
private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofMinutes(10); | ||
|
||
private static final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ofSeconds(10); | ||
|
||
/** | ||
* Client side configuration. | ||
* | ||
* @param baseUri Base URL the client sends HTTP request to. | ||
* @param connectionTimeout The client connection timeout. | ||
* @param readTimeout The client read timeout. | ||
* @param filters Filters to modify incoming {@link org.openqa.selenium.remote.http.HttpRequest} or outgoing | ||
* {@link org.openqa.selenium.remote.http.HttpResponse}. | ||
* @param proxy The client proxy preference. | ||
* @param credentials Credentials used for authenticating http requests | ||
* @param directConnect If directConnect is enabled. | ||
*/ | ||
protected AppiumClientConfig( | ||
URI baseUri, | ||
Duration connectionTimeout, | ||
Duration readTimeout, | ||
Filter filters, | ||
Proxy proxy, | ||
Credentials credentials, | ||
Boolean directConnect) { | ||
super(baseUri, connectionTimeout, readTimeout, filters, proxy, credentials); | ||
|
||
this.directConnect = Require.nonNull("Direct Connect", directConnect); | ||
KazuCocoa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Return the instance of {@link AppiumClientConfig} with a default config. | ||
* @return the instance of {@link AppiumClientConfig}. | ||
*/ | ||
public static AppiumClientConfig defaultConfig() { | ||
return new AppiumClientConfig( | ||
null, | ||
DEFAULT_CONNECTION_TIMEOUT, | ||
DEFAULT_READ_TIMEOUT, | ||
DEFAULT_FILTER, | ||
null, | ||
null, | ||
false); | ||
} | ||
|
||
/** | ||
* Return the instance of {@link AppiumClientConfig} from the given {@link ClientConfig} parameters. | ||
* @param clientConfig take a look at {@link ClientConfig} | ||
* @return the instance of {@link AppiumClientConfig}. | ||
*/ | ||
public static AppiumClientConfig fromClientConfig(ClientConfig clientConfig) { | ||
return new AppiumClientConfig( | ||
clientConfig.baseUri(), | ||
clientConfig.connectionTimeout(), | ||
clientConfig.readTimeout(), | ||
clientConfig.filter(), | ||
clientConfig.proxy(), | ||
clientConfig.credentials(), | ||
false); | ||
} | ||
|
||
private AppiumClientConfig buildAppiumClientConfig(ClientConfig clientConfig, Boolean directConnect) { | ||
return new AppiumClientConfig( | ||
clientConfig.baseUri(), | ||
clientConfig.connectionTimeout(), | ||
clientConfig.readTimeout(), | ||
clientConfig.filter(), | ||
clientConfig.proxy(), | ||
clientConfig.credentials(), | ||
directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig baseUri(URI baseUri) { | ||
ClientConfig clientConfig = super.baseUri(baseUri); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig baseUrl(URL baseUrl) { | ||
try { | ||
return baseUri(Require.nonNull("Base URL", baseUrl).toURI()); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig connectionTimeout(Duration timeout) { | ||
ClientConfig clientConfig = super.connectionTimeout(timeout); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig readTimeout(Duration timeout) { | ||
ClientConfig clientConfig = super.connectionTimeout(timeout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should call super.readTimeout(timeout) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, fixed in #1959 |
||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig withFilter(Filter filter) { | ||
ClientConfig clientConfig = super.withFilter(filter); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig withRetries() { | ||
ClientConfig clientConfig = super.withRetries(); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
|
||
@Override | ||
public ClientConfig proxy(Proxy proxy) { | ||
ClientConfig clientConfig = super.proxy(proxy); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
@Override | ||
public AppiumClientConfig authenticateAs(Credentials credentials) { | ||
ClientConfig clientConfig = super.authenticateAs(credentials); | ||
return buildAppiumClientConfig(clientConfig, directConnect); | ||
} | ||
|
||
/** | ||
* Whether enable directConnect feature described in | ||
* <a href="https://appiumpro.com/editions/86-connecting-directly-to-appium-hosts-in-distributed-environments"> | ||
* Connecting Directly to Appium Hosts in Distributed Environments</a>. | ||
* | ||
* @param directConnect if enable the directConnect feature | ||
* @return A new instance of AppiumClientConfig | ||
*/ | ||
public AppiumClientConfig directConnect(boolean directConnect) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets use a common approach and have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if here should follow e.g.
Still not decided yet to inherit, or just keep the clientconfig as a variable so that users can define their subclass of clientconfig as their clientconfig. |
||
// follows ClientConfig's design | ||
return new AppiumClientConfig( | ||
this.baseUri(), | ||
this.connectionTimeout(), | ||
this.readTimeout(), | ||
this.filter(), | ||
this.proxy(), | ||
this.credentials(), | ||
directConnect | ||
); | ||
} | ||
|
||
/** | ||
* Whether enable directConnect feature is enabled. | ||
* | ||
* @return If the directConnect is enabled. Defaults false. | ||
*/ | ||
public boolean isDirectConnectEnabled() { | ||
return directConnect; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.