-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add directConnect feature (#627)
* add idea based on 5.0.0 * ok proto * define a class * add AppiumClientConfig * add tests * add more drivers * extract as a private method * fix type * tweak comment * Update DirectConnect.cs * Update AppiumCommandExecutor.cs
- Loading branch information
Showing
11 changed files
with
564 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//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. | ||
|
||
namespace OpenQA.Selenium.Appium.Service | ||
{ | ||
|
||
public class AppiumClientConfig | ||
{ | ||
/// <summary> | ||
/// Return the default Appium Client Config | ||
/// </summary> | ||
/// <returns>An AppiumClientConfig instance</returns> | ||
public static AppiumClientConfig DefaultConfig() | ||
{ | ||
return new AppiumClientConfig(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the directConnect feature availability. | ||
/// If this flag is true and the target server supports | ||
/// https://appiumpro.com/editions/86-connecting-directly-to-appium-hosts-in-distributed-environments, | ||
/// the AppiumCommandExecutor will follow the response directConnect direction. | ||
/// | ||
/// AppiumClientConfig clientConfig = AppiumClientConfig.DefaultConfig(); | ||
/// clientConfig.DirectConnect = true; | ||
/// | ||
/// </summary> | ||
public bool DirectConnect { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//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. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OpenQA.Selenium.Appium.Service | ||
{ | ||
public class DirectConnect | ||
{ | ||
private const string DIRECT_CONNECT_PROTOCOL = "directConnectProtocol"; | ||
private const string DIRECT_CONNECT_HOST = "directConnectHost"; | ||
private const string DIRECT_CONNECT_PORT = "directConnectPort"; | ||
private const string DIRECT_CONNECT_PATH = "directConnectPath"; | ||
|
||
private readonly string Protocol; | ||
private readonly string Host; | ||
private readonly string Port; | ||
private readonly string Path; | ||
|
||
|
||
/// <summary> | ||
/// Create a direct connect instance from the given received response. | ||
/// </summary> | ||
public DirectConnect(Response response) | ||
{ | ||
|
||
this.Protocol = GetDirectConnectValue((Dictionary<string, object>)response.Value, DIRECT_CONNECT_PROTOCOL); | ||
this.Host = GetDirectConnectValue((Dictionary<string, object>)response.Value, DIRECT_CONNECT_HOST); | ||
this.Port = GetDirectConnectValue((Dictionary<string, object>)response.Value, DIRECT_CONNECT_PORT); | ||
this.Path = GetDirectConnectValue((Dictionary<string, object>)response.Value, DIRECT_CONNECT_PATH); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a URL instance built with members in the DirectConnect instance. | ||
/// </summary> | ||
/// <returns>A Uri instance</returns> | ||
public Uri GetUri() { | ||
if (this.Protocol == null || this.Host == null || this.Port == null || this.Path == null) { | ||
return null; | ||
} | ||
|
||
if (this.Protocol != "https") | ||
{ | ||
return null; | ||
} | ||
|
||
return new Uri(this.Protocol + "://" + this.Host + ":" + this.Port + this.Path); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value of instance built with members in the DirectConnect instance. | ||
/// </summary> | ||
/// <param name="value">The value of the 'value' key in the response body.</param> | ||
/// <param name="keyName">The key name to get the value.</param> | ||
/// <returns>A string value or null</returns> | ||
private string GetDirectConnectValue(Dictionary<string, object> value, string keyName) | ||
{ | ||
if (value.ContainsKey("appium:" + keyName)) | ||
{ | ||
return value["appium:" + keyName].ToString(); | ||
} | ||
|
||
if (value.ContainsKey(keyName)) { | ||
return value[keyName].ToString(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.