Skip to content

Commit

Permalink
Fix windows launchapp/closeapp for newer appium
Browse files Browse the repository at this point in the history
In Appium's dotnet driver in v5.0.0 they removed `LaunchApp` from the driver: appium/dotnet-client#766

The deprecation suggests using `ActivateApp` as an alternative, but that throws an error saying it's not implemented on the windows driver.

Curiously, `CloseApp` which was also marked as deprecated was _moved_ from the base appium driver to the `WindowsDriver` here: appium/dotnet-client#773

I think the same treatment should have been done to the `LaunchApp` method since there's no alternative in windows.

For now the workaround is to invoke the command manually:
`windowsDriver.ExecuteScript("windows: launchApp", [_app.GetAppId()]);`
  • Loading branch information
Redth committed Jun 18, 2024
1 parent 6632172 commit bfe57d8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ CommandResponse LaunchApp(IDictionary<string, object> parameters)
return CommandResponse.FailedEmptyResponse;

if (_app.GetTestDevice() == TestDevice.Mac)
{
{
_app.Driver.ExecuteScript("macos: activateApp", new Dictionary<string, object>
{
{ "bundleId", _app.GetAppId() },
});
}
else
else if (_app.Driver is WindowsDriver windowsDriver)
{
// Appium driver removed the LaunchApp method in 5.0.0, so we need to use the executeScript method instead
// Currently the appium-windows-driver reports the following commands as compatible:
// startRecordingScreen,stopRecordingScreen,launchApp,closeApp,deleteFile,deleteFolder,
// click,scroll,clickAndDrag,hover,keys,setClipboard,getClipboard
windowsDriver.ExecuteScript("windows: launchApp", [_app.GetAppId()]);
}
else
{
_app.Driver.ActivateApp(_app.GetAppId());
}
Expand Down Expand Up @@ -121,7 +129,7 @@ CommandResponse CloseApp(IDictionary<string, object> parameters)
}
catch (Exception)
{
// TODO Pass in logger so we can log these exceptions
// TODO: Pass in logger so we can log these exceptions

// Occasionally the app seems to get so locked up it can't
// even report back the appstate. In that case, we'll just
Expand All @@ -137,6 +145,13 @@ CommandResponse CloseApp(IDictionary<string, object> parameters)
{ "bundleId", _app.GetAppId() },
});
}
else if (_app.Driver is WindowsDriver windowsDriver)
{
// This is still here for now, but it looks like it will get removed just like
// LaunchApp was in 5.0.0, in which case we may need to use:
// windowsDriver.ExecuteScript("windows: closeApp", [_app.GetAppId()]);
windowsDriver.CloseApp();
}
else
{
_app.Driver.TerminateApp(_app.GetAppId());
Expand Down

0 comments on commit bfe57d8

Please sign in to comment.