Skip to content
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

[Testing] Add Back method in the UITest lifecycle actions #19442

Merged
merged 1 commit into from
Dec 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AppiumLifecycleActions : ICommandExecutionGroup
const string BackgroundAppCommand = "backgroundApp";
const string ResetAppCommand = "resetApp";
const string CloseAppCommand = "closeApp";
const string BackCommand = "back";

protected readonly AppiumApp _app;

Expand All @@ -17,6 +18,7 @@ public class AppiumLifecycleActions : ICommandExecutionGroup
BackgroundAppCommand,
ResetAppCommand,
CloseAppCommand,
BackCommand
};

public AppiumLifecycleActions(AppiumApp app)
Expand All @@ -37,6 +39,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
BackgroundAppCommand => BackgroundApp(parameters),
ResetAppCommand => ResetApp(parameters),
CloseAppCommand => CloseApp(parameters),
BackCommand => Back(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}
Expand Down Expand Up @@ -80,5 +83,16 @@ CommandResponse CloseApp(IDictionary<string, object> parameters)

return CommandResponse.SuccessEmptyResponse;
}

CommandResponse Back(IDictionary<string, object> parameters)
{
if (_app?.Driver is null)
return CommandResponse.FailedEmptyResponse;

// Navigate backwards in the history, if possible.
_app.Driver.Navigate().Back();

return CommandResponse.SuccessEmptyResponse;
}
}
}
11 changes: 10 additions & 1 deletion src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,16 @@ public static void DragCoordinates(this IApp app, float fromX, float fromY, floa
});
}

static IUIElement Wait(Func<IUIElement> query,
/// <summary>
/// Navigate back on the device.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
public static void Back(this IApp app)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that we already have a Back method in the UtilExtensions class. However, this method try to find the visual back button and click it. This use the physical back button on Android etc.

{
app.CommandExecutor.Execute("back", ImmutableDictionary<string, object>.Empty);
}

static IUIElement Wait(Func<IUIElement> query,
Func<IUIElement, bool> satisfactory,
string? timeoutMessage = null,
TimeSpan? timeout = null, TimeSpan? retryFrequency = null)
Expand Down