Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

I am trying to execute droid automation script on Appcenter but I am getting below error.

I am using app.config file where providing .apk file path and then calling .apkfile before startapp.

System.NullReferenceException : Object reference not set to an instance of an objectTearDown : System.NullReferenceException : Object reference not set to an instance of an object

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Do you install the apk file on your emulator or device? If you get teh same exception, if you get the same exception, please share related code for this issue.

  • sarilsethiasarilsethia Member ✭✭

    @LeonLu Hi , its working fine in real device and emulator , I am getting this error while executing it on appcenter

  • NicoleLuNicoleLu Member, Xamarin Team Xamurai

    @sarilsethia Hi, the error info is quite broad, please provide more info if it's convenient, e.g. details of your script/which line is throwing the exception and how you're providing your .apk path...

    Moreover, it can be related to AppCenter configuration, you can also ask for AppCenter support in AppCenter portal.

  • sarilsethiasarilsethia Member ✭✭

    @LeonLu Hi Please find the below details

    **1. Initially its calling this class **

    namespace CF.Hooks
    {
    [Binding]
    public class TestInitialize : BasePage
    {

        [BeforeTestRun]
        //[SetUp]
        public static void Testsetup()
        {
            AppInitializer.InitializeSettings();
            ApplicationContext = AppInitializer.StartApp(Settings.Platform);
            //ApplicationContext.Repl();
    
        }
    
        [AfterScenario]
        [Obsolete]
        public static void ScreenshotsForFailed()
        {
            if (ScenarioContext.Current.TestError != null)
            {
                ApplicationContext.Screenshot("Failed");
            }
    
        }
    }
    

    }

    1. Second class where we are calling initialise method and startapp

    namespace CF.Base
    {
    public class AppInitializer
    {
    public static IApp StartApp(Platform platform)
    {

            if (platform == Settings.Platform)
            {
                Console.WriteLine("####################");
                return ConfigureApp
                    .Android
                    .ApkFile(Settings.AUTPath)
                    .StartApp();
            }
    
    
    
        }
        public static void InitializeSettings()
        {
            Settings.Platform = (Platform)Enum.Parse(typeof(Platform),CFTestConfiguration.ClientConfiguration.TestSettings["staging"].Platform);
            Settings.AUTPath= CFTestConfiguration.ClientConfiguration.TestSettings["staging"].AUTPath;
            Settings.AUTPackageName = CFTestConfiguration.ClientConfiguration.TestSettings["staging"].AUTPackageName;
        }
    }
    

    }

    1. App.config file

    <?xml version="1.0" encoding="utf-8"?>


    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" /></configSections>
    
    <CFTestConfiguration>
        <testSettings>
    
            <testSetting name="staging" autpath="/Users/baps/Documents/CF/demo.apk" autpkgname="" platform="Android" /> 
            </testSettings>
        </CFTestConfiguration>
    
    
    <specFlow>
    
         <!-- unitTestProvider name="MsTest" >>>-->
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    

      <!-- This attribute is required in order to use StepArgument Transformation as described here; 
    https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Step-argument-transformations  -->
      <stepAssembly assembly="SpecFlow.Assist.Dynamic" />
    
    </stepAssemblies></specFlow></configuration>
    
  • NicoleLuNicoleLu Member, Xamarin Team Xamurai

    @sarilsethia and could you show the whole exception stacktrace? Can't locate where the exception was thrown with these info

  • sarilsethiasarilsethia Member ✭✭

    @NicoleLu Hi , Please find the full error stacktrace on appcenter

    System.NullReferenceException : Object reference not set to an instance of an objectTearDown : System.NullReferenceException : Object reference not set to an instance of an object at CF.Base.AppInitializer.InitializeSettings () [0x00010] in <4fea9e8d037f4f519f62f933d6ca0966>:0 at CF.Hooks.TestInitialize.Testsetup () [0x00001] in <4fea9e8d037f4f519f62f933d6ca0966>:0 at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,TechTalk.SpecFlow.Infrastructure.IContextManager) at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding (TechTalk.SpecFlow.Bindings.IBinding binding, TechTalk.SpecFlow.Infrastructure.IContextManager contextManager, System.Object[] arguments, TechTalk.SpecFlow.Tracing.ITestTracer testTracer, System.TimeSpan& duration) [0x000e6] in :0 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook (TechTalk.SpecFlow.Bindings.IBindingInvoker invoker, TechTalk.SpecFlow.Bindings.IHookBinding hookBinding, TechTalk.SpecFlow.Bindings.HookType hookType) [0x00011] in :0 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents (TechTalk.SpecFlow.Bindings.HookType hookType) [0x000af] in :0 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnTestRunStart () [0x00000] in :0 at TechTalk.SpecFlow.TestRunner.OnTestRunStart () [0x00000] in :0 at TechTalk.SpecFlow.TestRunnerManager.InitializeBindingRegistry (TechTalk.SpecFlow.ITestRunner testRunner) [0x00018] in :0 at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner (System.Int32 threadId) [0x00022] in :0 at TechTalk.SpecFlow.TestRunnerManager.GetTestRunnerWithoutExceptionHandling (System.Int32 threadId) [0x00031] in :0 at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner (System.Int32 threadId) [0x00017] in :0 at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner (System.Reflection.Assembly testAssembly, System.Nullable`1[T] managedThreadId) [0x00028] in :0 at CF.Features.Feature1HomePageFeature.FeatureSetup () [0x00001] in <4fea9e8d037f4f519f62f933d6ca0966>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0 --TearDown at CF.Features.Feature1HomePageFeature.FeatureTearDown () [0x00001] in <4fea9e8d037f4f519f62f933d6ca0966>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0

  • NicoleLuNicoleLu Member, Xamarin Team Xamurai

    @sarilsethia From the code snippet and stacktrace you provided, we can know that CFTestConfiguration is not loaded properly, so the question now becomes: how are you invoking the App.config file?

  • sarilsethiasarilsethia Member ✭✭

    @NicoleLu HI I am using config element folder where three file are there

    1.CFCollection.cs

    using System;
    using System.Configuration;

    namespace CF.ConfigElement
    {
    [ConfigurationCollection(typeof(CFElement), AddItemName = "testSetting", CollectionType = ConfigurationElementCollectionType.BasicMap)]

    public class CFCollection:ConfigurationElementCollection
    {
        public CFCollection()
        {
        }
    
        protected override ConfigurationElement CreateNewElement()
        {
            return new CFElement();
        }
    
        protected override object GetElementKey(ConfigurationElement element)
        {
    
            return (element as CFElement).name;
    
    
        }
    
        public new CFElement this[string type] => (CFElement)base.BaseGet(type);
    }
    

    }

    2.CFElement.cs

    using System;
    using System.Configuration;

    namespace CF.ConfigElement
    {
    public class CFElement:ConfigurationElement

    {
    
       [ConfigurationProperty("name", IsRequired = true)]
        public string name => (string)base["name"];
    
        [ConfigurationProperty("autpath", IsRequired = true)]
        public string AUTPath => (string)base["autpath"];
    
        [ConfigurationProperty("autpkgname", IsRequired = true)]
        public string AUTPackageName => (string)base["autpkgname"];
    
        [ConfigurationProperty("platform", IsRequired = true)]
        public string Platform => (string)base["platform"];
    
    
        public CFElement()
        {
        }
    }
    

    }

    3.CFTestConfiguration.cs

    using System;
    using System.Configuration;

    namespace CF.ConfigElement
    {
    public class CFTestConfiguration:ConfigurationSection
    {

        public static CFTestConfiguration ClientConfiguration => (CFTestConfiguration)ConfigurationManager.GetSection("CFTestConfiguration");
        [ConfigurationProperty("testSettings")]
        public CFCollection TestSettings => (CFCollection)base["testSettings"];
    
    }
    

    }

    4.SETTINGS.cs

    using System;
    using Xamarin.UITest;

    namespace CFFramework.Base
    {
    public class Settings
    {

        public static string AUTPath
        {
            get;
            set;
        }
    
    
        public static string AUTPackageName
        {
            get;
            set;
        }
    
    
        public static Platform Platform
        {
            get;
            set;
        }
    
    }
    

    }

  • NicoleLuNicoleLu Member, Xamarin Team Xamurai

    @sarilsethia thank you for your information, after checking the official doc, we know that the name and location of the application configuration file depend on the application's host, details can be found here: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps.

    This might be a bit more complicated with App Center, we're not sure what the right path for the config file in AppCenter, and if you have put your config file to the right place. Please consider asking for help with AppCenter support in it's portal.

  • sarilsethiasarilsethia Member ✭✭

    @NicoleLu Thanks for your answer but How can i check the right place for config file , is there any way to check it???

  • sarilsethiasarilsethia Member ✭✭

    @NicoleLu Hi , I added logs and reviewed it so its not calling the even first method before that its getting failed so issue with app center commands may be ,from there we are not able to call project
    I am using below commands

    appcenter test run uitest --app "demo/demo.Client.Droid" --devices 4a123ff5 --app-path /Users/baps/downloads/com.demo.client-Signed.apk --test-series "uat-tests" --locale "en_US" --build-dir '/Users/baps/documents/demo Android client automation/demo-testing/demo/bin/Debug' --uitest-tools-dir '/Users/baps/documents/demo Android client automation/demo-testing/packages/Xamarin.UITest.3.0.5/tools/'

  • NicoleLuNicoleLu Member, Xamarin Team Xamurai

    For AppCenter command, here's what I found: https://docs.microsoft.com/en-us/appcenter/test-cloud/frameworks/uitest/android/#generating-an-upload-command

    You may need to specify the UITest package you're using, if the CLI can't automatically find it: --uitest-tools-dir /Users/{your username}/.nuget/packages/xamarin.uitest/{UITest version}/tools

    Looks like the UITest package is different with what the AppCenter suggested.

  • sarilsethiasarilsethia Member ✭✭

    okay let me try this one @NicoleLu , thanks :)

Sign In or Register to comment.