UNit Test Project and XamarinUITest cross-plataform test project in the same solution do not work together Web / Android C #

0

Good morning / afternoon / evening.

I created a C# solution with a project using NUnit tests and another project using Xamarin Tests (in this order).

I'm trying to use a variável of projeto/classe NUnit within my projeto/classe Xamarin , but I can not.

If I run the tests NUnit without the Xamarin project, everything works fine.

If I run the tests Xamarin , commenting and not using anything from NUnit, everything goes well.

But if I run the tests of Xamarin by calling variável of NUnit , it breaks before even arriving at the method that uses variável .

This is the error message I get.

  

Message: OneTimeSetUp: System.ArgumentNullException: Value can not be   null.Parameter name: key

This is the code for my classe NUnit

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Configuration;


namespace UnitTestProject1
{
    [TestClass]
    class TC_TRACK_ADMIN_ENTITY_DEVICE
    {

        //Instanciate test conditions
        SetupTest setupTest = new SetupTest();
        public string deviceActivationCode;

        [TestMethod]
        [TestCategory("End-to-End")]
        public void GetDeviceActivationCode()
        {
            //Initialize test
            setupTest.Initialize();

            //Login to Application
            LoginPageObjects loginPage = new LoginPageObjects();
            HomePageObjects HomePage = loginPage.Login(UserRoles.SystemAdministrator);

            DevicesPageObjects DevicePage = HomePage.SelectDevicesOption();
            WebdriverExtensions.WaitForElementToBeDisplayed(DevicePage.DeviceListTable);

            //Select a Tracking Location
            HomePage.SelectTrackingLocationFromDropBox(ConfigurationManager.AppSettings["TrackingLocationCode_1"]);

            //Device Creation page
            DevicePage.NewDevice.Click();

            CreateDevicePageObjects CreateNewDevice = new CreateDevicePageObjects();
            WebdriverExtensions.WaitForElementToBeDisplayed(CreateNewDevice.SaveButton);

            //Random generator for creating new entries
            Random random = new Random();
            int i = random.Next(0, 10000);
            string DeviceCode = ConfigurationManager.AppSettings["DeviceForMobileAutomation"] + i;

            //Create a new device
            CreateNewDevice.NewDevice(DeviceCode);

            //Check all the  device roles
            CreateNewDevice.CheckAllNewDeviceRoles();
            WebdriverExtensions.WaitForElementToBeDisplayed(CreateNewDevice.DeviceActivation);

            deviceActivationCode = CreateNewDevice.DeviceActivationCode.Text;

            Console.WriteLine(deviceActivationCode);

            setupTest.Cleanup();

        }

    }
}

This is the code for my classe Xamarin

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using UnitTestProject1;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Anderson
{
    class XamarinTest
    {

        [TestFixture(Platform.Android)]
        //[TestFixture(Platform.iOS)]
        public class Tests
        {
            IApp app;
            Platform platform;
            TC_TRACK_ADMIN_ENTITY_DEVICE getCode = new TC_TRACK_ADMIN_ENTITY_DEVICE();

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

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

            [Test]
            public void CodeApplied()
            {

                if (app.Query("Welcome to").Any())
                {
                    Console.WriteLine("   STARTING ENROLLMENT FAILL AND PASS!   ");
                    Console.WriteLine("   Começando o Enrollment Falha e Passa!   ");
                    EnrollmentFaillAndPass();

                }
                else
                {
                    if (app.Equals("android.widget.TextView"))
                    {
                        Console.WriteLine("   STARTING REGULAR TESTS!   ");
                        Console.WriteLine("   Começando os testes regulares!   ");
                    }
                    else

                        Console.WriteLine("   WHERE AM I?   ");
                    Console.WriteLine("   Onde eu estou?   ");
                }
            }

            public void EnrollmentFaillAndPass()
            {
                EnrollmentFailedTest();
                EnrollmentSuccessfulTest();
            }

            [Test]
            public void EnrollmentFailedTest()
            {


                //Wait for enrollment screen
                app.WaitForElement(w => w.Text("INEXTEND"), timeout: TimeSpan.FromSeconds(30));
                app.Query("Welcome to").Any();
                Console.WriteLine("   Found WELCOME text   ");
                Console.WriteLine("   Encontrado o texto WELCOME   ");

                //Type enrollment code
                app.EnterText(x => x.Id("NoResourceEntry-8"), "1NV4L1DC0D3");
                app.Tap(x => x.Text("Enroll"));
                Console.WriteLine("   PUTING THE INVALID CODE   ");
                Console.WriteLine("   Colocando o código inválido   ");

                //Wait for enrollment process to finish
                app.WaitForNoElement(x => x.Text("Generating certificate..."), timeout: TimeSpan.FromSeconds(60));
                Console.WriteLine("   WAITING THE LOADING FINISH!   ");
                Console.WriteLine("   Esperando o Loading terminar!   ");

                //Assert
                AppResult[] results = app.WaitForElement(x => x.Text("Device enrollment failed"), timeout: TimeSpan.FromSeconds(30));
                Assert.IsTrue(results.Any());
                Console.WriteLine("   CHECKING THE ENROLLMENT FAIL MESSAGE!   ");
                Console.WriteLine("   Verificando a mensagem de ENROLLMENT FAIL!   ");

                app.Tap(x => x.Text("Back to menu"));
                Console.WriteLine("   BACKING TO THE MENU!   ");
                Console.WriteLine("   Voltando para o menu!   ");

            }

            [Test]
            public void EnrollmentSuccessfulTest()
            {

                Console.WriteLine("Checking Welcome text after invalid keycode");
                Console.WriteLine("Verificando o texto de Welcome depois do código inválido");

                app.WaitForElement(c => c.Text("Welcome to"));

                Console.WriteLine("Welcome text confirmed");
                Console.WriteLine("Texto Welcome confirmado");

                Console.WriteLine("Cleaning the Keycode field");
                Console.WriteLine("Limpando o campo Keycode");


                getCode.GetDeviceActivationCode();

                string validCode = getCode.deviceActivationCode;

                Console.WriteLine("VALIDATION CODE: " + validCode);
                Console.WriteLine("Código de validação: " + validCode);

                //Type enrollment code
                app.EnterText(x => x.Id("NoResourceEntry-8"), validCode);

                Console.WriteLine("   PUTING THE VALID CODE   ");
                Console.WriteLine("   Colocando o código válido   ");

                app.Tap(x => x.Text("Enroll"));

                Console.WriteLine("Tapping on Enroll with a valid Keycode");
                Console.WriteLine("Clicando no Enrool do código válido");

            }

        }
    }

This is the code for my classe AppInitializer

using System;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace Xamarin
{
    public class AppInitializer
    {
        public static IApp StartApp(Platform platform)
        {

            if (platform == Platform.Android)
            {
                return ConfigureApp
                    .Android
                    .PreferIdeSettings()
                    .DeviceSerial("SamsungS9")
                    .ApkFile(@"C:/MyApp/MyApp.apk")
                    .StartApp(Xamarin.UITest.Configuration.AppDataMode.DoNotClear);


            }

            return ConfigureApp.iOS.StartApp();

        }

    }
}

If anyone knows anything and can help me, I appreciate it.

    
asked by anonymous 11.10.2018 / 21:27

0 answers