user3617723
user3617723

Reputation: 1395

Xamarin UI Test Determine Platform

I'm trying to write automated tests using Xamarin UI Test, within certain parts of those tests I need to know which platform they are running on i.e. Android or iOS.

I'm struggling to find a way of doing this, does anyone know of an API to do this or any other such trick?

Upvotes: 0

Views: 1133

Answers (1)

jzeferino
jzeferino

Reputation: 7850

Your tests class have a constructor like this:

[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
    IApp app;
    Platform platform;

    public Tests(Platform platform)
    {
        this.platform = platform;
    }

    [SetUp]
    public void BeforeEachTest()
    {
        app = AppInitializer.StartApp(platform);
    }
}

Later on, in you test method you could do this:

[Test]
public void MyTest()
{
    if (platform == Platform.Android) 
    {
        // Do specific code here.
    }
}   

Upvotes: 3

Related Questions