Forum Xamarin Test Cloud (Read Only)

Detecting if test is running on test cloud

Hi all,

We have some code that we only want to execute if it is not running on Xamarin Test Cloud. The code installs our app on to an ios device. That doesn't need to run in the cloud as the cloud will take care of that for us.

Is there any way of detecting weather or not our code is running on the cloud?

i.e.

if(code for checking xamarin test cloud == false){
Run device specific code.
}

Thanks for your suggestions.

Answers

  • mallibonemallibone USUniversity ✭✭

    Hey Chris, I am not aware of a check that will tell you if you are running on the cloud. But In my test projects I generally perform those task(s) in the AppInitializer class which is only executed locally and ahead of all tests you are running:

    public class AppInitializer
    {
        private const string appFilePath = "Path/To/APK_OR_IPA_OR_APP_FILE";
    
        public static IApp StartApp(Platform platform)
        {
            // Only run locally and not on the test cloud
    
            if (platform == Platform.Android)
            {
                return ConfigureApp
                    .Android
                    .PreferIdeSettings()
                    //.ApkFile(appFilePath)
                    .StartApp();
            }
    
            return ConfigureApp
                .iOS
                //.AppBundle(appFilePath)
                .StartApp();
        }
    }
    
  • ChrisGungalooChrisGungaloo USUniversity
    edited July 2016

    Thanks for your suggestion Mark. I already have a check like this in my code. If nothing that checks if Im on Xamarin cloud exists, Ill have to find another way.

  • valdeterovaldetero USInsider, University ✭✭

    This is what I have in my code:

    public static IApp StartApp(Platform platform)
    {
        IApp _app = null;
    
        switch (TestEnvironment.Platform)
        {
            case TestPlatform.Local:
                if (platform == Platform.Android)
                    _app = ConfigureApp.Android.StartApp();
                else
                    _app = ConfigureApp.iOS.Debug().StartApp();
                break;
            case TestPlatform.TestCloudiOS:
                _app = ConfigureApp.iOS.StartApp();
                break;
            case TestPlatform.TestCloudAndroid:
                _app = ConfigureApp.Android.StartApp();
                break;
        }
        return _app;
    }
    

    You could also check the TestEnvironment.IsTestCloud property.

    I'm not sure what version it was added in, but it is currently in Xamarin.UITest 1.3.11.0.

Sign In or Register to comment.