Keeping tests cross-platform with On
Using On
The most common platform-specific differences within tests are variations between queries. On
makes it much simpler to quickly choose a value depending on the current platform:
// Choose the login button query based on current platform:
Query LoginButton => On(
iOS: Button["#login"],
Android: Button["Sign In"]
);
[Test]
void LoginTest()
{
...
// The test remains very easy to read, and looks cross-platform
Tap(LoginButton);
}
OnAndroid
and OniOS
Another kind of platform-specialization required for tests involves extra steps that are taken on one platform but not another. To make executing extra platform-specific steps within a test simpler, OnAndroid
and OniOS
were added as helpers. They simply take an Action
and run it only on the appropriate platform:
[Test]
void LoginTest()
{
Entry["Username"].EnterText("david");
Entry["Password"].EnterText("s3cr3t");
// We require T&C on Android only:
OnAndroid(Switch["#termsAndConditions"].Tap);
// On iOS we press Enter, but on android we tap Login
OniOS(PressEnter);
OnAndroid("Login".Tap);
}