0

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?

user3617723
  • 1,355
  • 3
  • 17
  • 37

1 Answers1

3

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.
    }
}   
jzeferino
  • 7,700
  • 1
  • 39
  • 59