How to perform the navigation to the page by dynamic/parameterized URL.
Let’s use Google search page as example.
For example we need to get to search results page by passing query text into URL.
To make it work we need to build URL in such format:
https://www.google.com/search?q={QUERY}
.
Assume that
https://www.google.com/
is the BaseUrl
of AtataContext
.
using Atata;
namespace SampleApp.UITests
{
using _ = GoogleSearchPage;
[Url(DefaultUrl)] // The default URL that will be used when no query is provided. Can be omitted.
public class GoogleSearchPage : Page<_>
{
private const string DefaultUrl = "/search";
private readonly string urlQueryString;
public GoogleSearchPage(string urlQueryString = null)
{
this.urlQueryString = urlQueryString;
}
protected override void Navigate()
{
if (urlQueryString != null)
Go.ToUrl($"{DefaultUrl}?{urlQueryString}");
else
base.Navigate();
}
public static _ ByQuery(string query)
{
return new _($"q={query}");
}
}
}
Go.To(GoogleSearchPage.ByQuery("test"));
Go.To<GoogleSearchPage>();