Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ public static void InstallApp(
});
}

/// <summary>
/// Launch an app on the iOS device using mobile: launchApp script.
/// For documentation, see <see href="https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-launchapp">mobile: launchApp</see>.
/// </summary>
/// <param name="executeMethod">The execute method</param>
/// <param name="bundleId">The bundle identifier of the application.</param>
/// <param name="processArguments">Optional command line arguments for the app.</param>
/// <param name="environmentVariables">Optional environment variables for the app.</param>
public static void LaunchAppWithArguments(
IExecuteMethod executeMethod,
string bundleId,
IReadOnlyCollection<string> processArguments = null,
IDictionary<string, string> environmentVariables = null)
{
var args = new Dictionary<string, object> { { "bundleId", bundleId } };

if (processArguments != null && processArguments.Count > 0)
args["arguments"] = processArguments;

if (environmentVariables != null && environmentVariables.Count > 0)
args["environment"] = environmentVariables;

executeMethod.Execute(DriverCommand.ExecuteScript, new Dictionary<string, object>
{
["script"] = "mobile: launchApp",
["args"] = new object[] { args }
});
}

public static Dictionary<string, object> GetSettings(IExecuteMethod executeMethod) =>
(Dictionary<string, object>)executeMethod.Execute(AppiumDriverCommand.GetSettings).Value;

Expand All @@ -130,4 +159,4 @@ public static void SetSetting(IExecuteMethod executeMethod, string setting, obje
executeMethod.Execute(AppiumDriverCommand.UpdateSettings, parameters);
}
}
}
}
15 changes: 14 additions & 1 deletion src/Appium.Net/Appium/iOS/IOSDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ public Dictionary<string, object> Settings
public void InstallApp(string appPath, int? timeoutMs = null) =>
IOSCommandExecutionHelper.InstallApp(this, appPath, timeoutMs);

/// <summary>
/// Launch an app on the iOS device using mobile: launchApp script.
/// For documentation, see <see href="https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-launchapp">mobile: launchApp</see>.
/// </summary>
/// <param name="bundleId">The bundle identifier of the application.</param>
/// <param name="processArguments">Optional command line arguments for the app.</param>
/// <param name="environmentVariables">Optional environment variables for the app.</param>
public void LaunchAppWithArguments(
string bundleId,
IReadOnlyCollection<string> processArguments = null,
IDictionary<string, string> environmentVariables = null) =>
IOSCommandExecutionHelper.LaunchAppWithArguments(this, bundleId, processArguments, environmentVariables);

#endregion

/// <summary>
Expand Down Expand Up @@ -316,4 +329,4 @@ public AppState GetAppState(string bundleId) =>
).ToString()
);
}
}
}
30 changes: 29 additions & 1 deletion test/integration/IOS/Device/AppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,34 @@ public void CanActivateAppFromBackgroundTest()

#endregion

#region Launch App With Arguments

[Test]
public void CanLaunchAppWithArguments()
{
_driver.TerminateApp(UiCatalogAppTestAppBundleId);

var processArguments = new List<string>
{
"-AppleLanguages",
"(en)",
"-AppleLocale",
"en_US"
};
var environmentVariables = new Dictionary<string, string>
{
["UITEST_LAUNCH"] = "1"
};

Assert.DoesNotThrow(() =>
_driver.LaunchAppWithArguments(UiCatalogAppTestAppBundleId, processArguments, environmentVariables));

Assert.That(() => _driver.GetAppState(UiCatalogAppTestAppBundleId), Is.EqualTo(AppState.RunningInForeground));
Assert.DoesNotThrow(() => _driver.FindElement(MobileBy.AccessibilityId(UiCatalogTestAppElement)));
}

#endregion

#region Background App

[Test]
Expand Down Expand Up @@ -121,4 +149,4 @@ public void CanBackgroundAppToDeactivationUsingNegativeSecond()

#endregion
}
}
}
Loading