Search code examples
androidiosvisual-studio-macxamarin.uitest

Xamarin UI Tests: Running both iOS & Android tests with one build config


So, I'm on a Mac, using Visual Studio and Xamarin UI Tests to run ui tests over a real iphone and a real android device.

I've got the classic test fixture setup with Android and IOS as different variants for tests.

    [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);
        }
    }
}

This is my device app config, where instead of using device IDs, I'm specifying the devices in my IDE at runtime:

 public static void StartApp()
        {

            if (Platform == Platform.Android)
            {
                _app = ConfigureApp
                    .Android
                    .InstalledApp(appBundleName)
                    .EnableLocalScreenshots()
                    .PreferIdeSettings()
                    .StartApp(AppDataMode.Clear);
            }

            if (Platform == Platform.iOS)
            {
                _app = ConfigureApp
                    .iOS

                    .InstalledApp(appBundleName)
                    .PreferIdeSettings()
                    .EnableLocalScreenshots()
                    .StartApp(AppDataMode.Clear);
            }
        }
    }

This works when I run the tests on a single platform -- ie, comment out the IOS platform fixture and run only Android tests, or vice versa. But if I have text fixtures for both platforms, and attempt to run all of the tests, I run into an issue where the tests can't find one of the devices. Finds, say, the android just fine and those tests run as expected, but all ios tests fail.

I suspect this is related to my build configuration, as preferring the IDE settings appears to rely on the build config to set the target device for an application. However, I'd like to check -- is it possible to run tests on both IOS and ANDROID platforms using the "prefer ide" settings? I've got the test apps set in my test pad, and both appear to be targeting the real devices.


Solution

  • I figured out my own question, thought I'd post it in case it's useful to anyone else.

    In sum, for whatever reason, you can't use .PreferIdeSettings() for both platforms. Visual Studio Mac appears to only know how to specify one build config per project per target device. Perhaps if someone else has a project set up where the different apps will share a build configuration, this could be worked around. As it is, I found that I had to specify at least the one platform's device id to get the tests to target devices for both platforms successfully.