Xamarin UI test - Can't tap button

223 views Asked by At

when I Start the debugging of the app, VS distribute the app on the folder: "android/data/com.myapk.android." When I start the app by tapping the icon or by debugging on my android device, the different buttons of my app works.

But when i launch the same app by XamarinUITest and i press the button by the UnitTest, the app closes. Instead the app is not closing when I insert a text in a textbox by the Unit Test. I don't understand the reason of this problem..

Below you can find the code of the AppInitializer class and the code of the Unit Test:

AppInitializer.cs:

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

namespace UITestSerio
{
    public class AppInitializer
    {
        public static IApp StartApp(Platform platform)
        {
            if (platform == Platform.Android)
            {
                return ConfigureApp
                    .Android
                    .InstalledApp("XamarinNoapelReader.Android")
                    //.ApkFile("C:/Users/a.butnaru/Documents/APK/XamarinNoapelReader.Android-Signed.apk")
                    //.ConnectToApp();
                    .DeviceSerial("18261B2271")
                    .StartApp();
            }

            return ConfigureApp
                .iOS
                .StartApp();
        }
    }
}

Tests.cs:

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace UITestSerio
{
    [TestFixture(Platform.Android)]
    public class Tests
    {
        IApp app;
        Platform platform;
        public Tests(Platform platform) //costruttore
        {
            this.platform = platform;
        }

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

        [Test]
        public void OpenRepl()
        {
            app.Repl();
        }

        [Test]
        public void PrintTextTest()
        {
            var device = app.Device;

            Assert.True(device.DeviceIdentifier == "18261B2271");

            app.Tap("entryTest");
            app.EnterText("lol asd asd");
            app.DismissKeyboard();

            app.WaitForElement(x => x.Marked("addLogo"));
            app.Tap(x => x.Marked("addLogo"));

            //app.TapCoordinates(360, 812);
            //app.TapCoordinates(360, 1136);

            app.Tap(x => x.Marked("addText"));

            /* app.Tap("addText");
             app.Tap("getPrinted"); */
        }
    }
}

thank you

0

There are 0 answers