Skip to content

Commit

Permalink
Merge pull request #126 from TikhomirovSergey/#106-fix
Browse files Browse the repository at this point in the history
#106 fix: The ability to start appium server programmatically
  • Loading branch information
TikhomirovSergey committed Dec 21, 2015
2 parents 48d4c07 + eb41da9 commit ce02439
Show file tree
Hide file tree
Showing 63 changed files with 3,481 additions and 684 deletions.
65 changes: 59 additions & 6 deletions appium-dotnet-driver/Appium/Android/AndroidDriver.cs
Expand Up @@ -14,6 +14,7 @@
using OpenQA.Selenium.Appium.Android.Interfaces;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.Service;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
Expand All @@ -35,10 +36,10 @@ public class AndroidDriver<W> : AppiumDriver<W>, IFindByAndroidUIAutomator<W>, I
private const string CONNECTION_NAME_VALUE = "network_connection";
private const string DATA_PARAM = "data";
private const string INTENT_PARAM = "intent";


/// <summary>
/// Initializes a new instance of the AndroidDriver class. This constructor defaults proxy to http://127.0.0.1:4723/wd/hub
/// Initializes a new instance of the AndroidDriver class using desired capabilities
/// </summary>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities of the browser.</param>
public AndroidDriver(DesiredCapabilities desiredCapabilities)
Expand All @@ -47,26 +48,78 @@ public AndroidDriver(DesiredCapabilities desiredCapabilities)
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class
/// Initializes a new instance of the AndroidDriver class using desired capabilities and command timeout
/// </summary>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public AndroidDriver(DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the AppiumServiceBuilder instance and desired capabilities
/// </summary>
/// <param name="builder"> object containing settings of the Appium local service which is going to be started</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
public AndroidDriver(AppiumServiceBuilder builder, DesiredCapabilities desiredCapabilities)
: base(builder, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the AppiumServiceBuilder instance, desired capabilities and command timeout
/// </summary>
/// <param name="builder"> object containing settings of the Appium local service which is going to be started</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public AndroidDriver(AppiumServiceBuilder builder, DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(builder, SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the specified remote address and desired capabilities
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub).</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities of the browser.</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities.</param>
public AndroidDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities)
: base(remoteAddress, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the specified Appium local service and desired capabilities
/// </summary>
/// <param name="service">the specified Appium local service</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
public AndroidDriver(AppiumLocalService service, DesiredCapabilities desiredCapabilities)
: base(service, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the specified remote address, desired capabilities, and command timeout.
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub).</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities of the browser.</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public AndroidDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(remoteAddress, SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the AndroidDriver class using the specified Appium local service, desired capabilities, and command timeout.
/// </summary>
/// <param name="service">the specified Appium local service</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public AndroidDriver(AppiumLocalService service, DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(service, SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

#region IFindByAndroidUIAutomator Members

public W FindElementByAndroidUIAutomator(string selector)
Expand Down
131 changes: 131 additions & 0 deletions appium-dotnet-driver/Appium/AppiumCommand.cs
@@ -0,0 +1,131 @@
//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 OpenQA.Selenium.Remote;
using System.Collections.Generic;

namespace OpenQA.Selenium.Appium
{
/// <summary>
/// Container class for the command tuple
/// </summary>
internal class AppiumCommand
{

private static List<AppiumCommand> CommandList = new List<AppiumCommand>(){
#region Context Commands
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.Contexts, "/session/{sessionId}/contexts" ),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetContext, "/session/{sessionId}/context" ),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetContext, "/session/{sessionId}/context" ),
#endregion Context Commands
#region Appium Commands
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ShakeDevice, "/session/{sessionId}/appium/device/shake"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.LockDevice, "/session/{sessionId}/appium/device/lock"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.IsLocked, "/session/{sessionId}/appium/device/is_locked"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleAirplaneMode, "/session/{sessionId}/appium/device/toggle_airplane_mode"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.KeyEvent, "/session/{sessionId}/appium/device/keyevent"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.Rotate, "/session/{sessionId}/appium/device/rotate"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetCurrentActivity, "/session/{sessionId}/appium/device/current_activity"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.InstallApp, "/session/{sessionId}/appium/device/install_app"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.RemoveApp, "/session/{sessionId}/appium/device/remove_app"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.IsAppInstalled, "/session/{sessionId}/appium/device/app_installed"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.PushFile, "/session/{sessionId}/appium/device/push_file"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.PullFile, "/session/{sessionId}/appium/device/pull_file"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.PullFolder, "/session/{sessionId}/appium/device/pull_folder"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleWiFi, "/session/{sessionId}/appium/device/toggle_wifi"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleLocationServices, "/session/{sessionId}/appium/device/toggle_location_services"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.LaunchApp, "/session/{sessionId}/appium/app/launch"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.CloseApp, "/session/{sessionId}/appium/app/close"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ResetApp, "/session/{sessionId}/appium/app/reset"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.BackgroundApp, "/session/{sessionId}/appium/app/background"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.EndTestCoverage, "/session/{sessionId}/appium/app/end_test_coverage"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.GetAppStrings, "/session/{sessionId}/appium/app/strings"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetImmediateValue, "/session/{sessionId}/appium/element/{id}/value"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.HideKeyboard, "/session/{sessionId}/appium/device/hide_keyboard"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.OpenNotifications, "/session/{sessionId}/appium/device/open_notifications"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.StartActivity, "/session/{sessionId}/appium/device/start_activity"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetSettings, "/session/{sessionId}/appium/settings"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.UpdateSettings, "/session/{sessionId}/appium/settings"),
#endregion Appium Commands
#region Touch Commands
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.MultiActionV2Perform, "/session/{sessionId}/touch/multi/perform"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.TouchActionV2Perform, "/session/{sessionId}/touch/perform"),
#endregion Touch Commands

#region JSON Wire Protocol Commands
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetOrientation, "/session/{sessionId}/orientation"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetOrientation, "/session/{sessionId}/orientation"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetConnectionType, "/session/{sessionId}/network_connection"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetConnectionType, "/session/{sessionId}/network_connection"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetLocation, "/session/{sessionId}/location"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetLocation, "/session/{sessionId}/location"),

#region Input Method (IME)
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetAvailableEngines, "/session/{sessionId}/ime/available_engines"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetActiveEngine, "/session/{sessionId}/ime/active_engine"),
new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.IsIMEActive, "/session/{sessionId}/ime/activated"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ActivateEngine, "/session/{sessionId}/ime/activate"),
new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.DeactivateEngine, "/session/{sessionId}/ime/deactivate"),
#endregion Input Method (IME)

#endregion JSON Wire Protocol Commands

};

/// <summary>
/// This method adds Appium-specific commands to the given
/// CommandInfoRepository
/// </summary>
/// <param name="repo">is a CommandInfoRepository instance which is used</param>
/// <returns>The given CommandInfoRepository instance with added Appium-specific commands</returns>
internal static CommandInfoRepository Merge(CommandInfoRepository repo)
{
foreach (AppiumCommand entry in CommandList)
{
var commandInfo = new CommandInfo(entry.CommandType, entry.ApiEndpoint);
repo.TryAddCommand(entry.CommandName, commandInfo);
}
return repo;
}

/// <summary>
/// command type
/// </summary>
internal readonly string CommandType;

/// <summary>
/// Command
/// </summary>
internal readonly string CommandName;

/// <summary>
/// API Endpoint
/// </summary>
internal readonly string ApiEndpoint;

/// <summary>
/// Constructor
/// </summary>
/// <param name="commandType">type of command (get/post/delete)</param>
/// <param name="command">Command</param>
/// <param name="apiEndpoint">api endpoint</param>
/// <summary>
internal AppiumCommand(string commandType, string command, string apiEndpoint)
{
CommandType = commandType;
CommandName = command;
ApiEndpoint = apiEndpoint;
}
}
}

0 comments on commit ce02439

Please sign in to comment.