Snippets

Sebastian Seidel TestCloud Tests

Created by Sebastian Seidel
using NUnit.Framework;
using System;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace TelematicsUITests
{
    [TestFixture]
    public class TelematicsDroidTest
    {
        const string _droidPath = "telematics.apk";
        IApp _app;

        [TestFixtureSetUp]
        public void Setup()
        {

            _app = ConfigureApp.Android.ApkFile(_droidPath).StartApp();

            Func<AppQuery,AppQuery> demoLoginButton = e => e.Id("Logon_LoginDemo_Button");
            Func<AppQuery, AppQuery> mainFragmentContainer = e => e.Id("Main_FragmentContainer");

            _app.WaitForElement(demoLoginButton, "Timed out waiting for the Login_LoginDemo_Button to appear.");
            _app.Tap(demoLoginButton);
            _app.WaitForElement(mainFragmentContainer, "Timed out waiting for the Main_FragmentContainer to appear.");
        }

        [TestFixtureTearDown]
        public void TestCleanUp()
        {
            _app.Tap(e => e.Id("Main_Settings"));
            _app.Tap(e => e.Class("TextView").Index(1));
        }

        [Test]
        public void EnablingLoggingShouldBeSavedOnLeavingSettings()
        {
            Setup();
            
            _app.Tap(e => e.Id("Main_Settings"));
            _app.Tap(e => e.Id("checkbox"));
            _app.Tap(e => e.Id("checkbox"));
            _app.Back();
            _app.Tap(e => e.Id("Main_Settings"));
            _app.WaitForElement(e => e.Id("checkbox"), "Timed out waiting for Setting activity Title", TimeSpan.FromSeconds(2));
            
            var result = _app.Query(e => e.Id("checkbox"));
            Assert.IsTrue(result.Length == 1); 
        }

        [Test]
        public void DisableLoggingShouldBeSavedOnLeavingSettings()
        {
            Setup();

            _app.Tap(e => e.Id("Main_Settings"));
            _app.Tap(e => e.Id("checkbox"));
            _app.Back();
            _app.Tap(e => e.Id("Main_Settings"));
            _app.WaitForElement(e => e.Id("checkbox"), "Timed out waiting for Setting activity Title", TimeSpan.FromSeconds(2));

            var result = _app.Query(e => e.Id("checkbox"));
           
            Assert.IsTrue(result.Length == 1); 
        }

        [Test]
        public void AfterSuccessfullLoginMachineListIsVisible()
        {
            Func<AppQuery, AppQuery> mainFragmentContainer = e => e.Id("Main_FragmentContainer");
            Func<AppQuery, AppQuery> machineList = e => e.Id("list");

            _app.WaitForElement(mainFragmentContainer, "Timed out waiting for the Main_FragmentContainer to appear.");

            Assert.IsTrue(_app.Query(machineList).Length == 1);
        }

        [Test]
        public void SwitchIntoMachineDetail()
        {
            Setup();

            _app.Tap(e => e.Id("MaschineListItem_Title").Index(0));
            _app.WaitForElement(e => e.Id("MachineDetails_Navigate"), "Timed out waiting for navigate element");

            var queryResult = _app.Query(e => e.Id("MachineDetails_Navigate"));
            Assert.IsTrue(queryResult.Length == 1);
        }

        [Test]
        public void SwitchToCardViewFromMachineDetail()
        {   
            Setup();

            _app.Tap(e => e.Class("TextView").Index(1));
            _app.Tap(e => e.Id("detailmap"));
            _app.Tap(e => e.Class("View").Index(1));

            Assert.IsTrue(_app.Query(e => e.Class("View")).Length > 1);  
        }

        [Test]
        public void ShowImpressum()
        {
            Setup();

            _app.Tap(e => e.Id("Main_Settings"));
            _app.Tap(e => e.Class("TextView").Index(7));
            _app.WaitForElement(e => e.Class("WebView"), "Timed out waiting for Impress webview", TimeSpan.FromSeconds(2));
          
            Assert.IsTrue(_app.Query(e => e.Class("WebView")).Length == 1);
        }

        [Test]
        public void ShowSettings()
        {
            Setup();

            _app.Tap(e => e.Id("Main_Settings"));
            _app.WaitForElement(e => e.Text("Settings"), "Timed out waiting for Settings activity title", TimeSpan.FromSeconds(2));

            Assert.IsTrue(_app.Query(e => e.Id("checkbox")).Length == 1);         
        }

        [Test]
        public void ZoomOutInCard()
        {
            Setup();
            
            _app.Tap(e => e.Class("TextView").Index(1));
            _app.Tap(e => e.Id("detailmap"));
            _app.Tap(e => e.Class("View").Index(1));
            _app.Tap(e => e.Class("View").Index(1));

            Assert.IsTrue(_app.Query(e => e.Class("View")).Length > 1);  
        }

        [Test]
        public void CheckMachineListAfterDisableFirstMachine()
        {
            Setup();

            var firstListItemName = _app.Query(e => e.Id("MaschineListItem_Title").Index(0));     

            _app.Tap(e => e.Id("Main_Filter"));
            _app.Tap(e => e.Class("CheckedTextView").Index(0));
            _app.Back();
            var result = _app.Query(e => e.Id("MaschineListItem_Title").Index(0));

            Assert.AreNotEqual(result[0].Text, firstListItemName[0].Text);
        }

        [Test]
        public void CheckMachineListAfterDisableThirdMachine()
        {
            Setup();
            
            var firstListItemName = _app.Query(e => e.Id("MaschineListItem_Title").Index(2));

            _app.Tap(e => e.Id("Main_Filter"));
            _app.Tap(e => e.Class("CheckedTextView").Index(2));
            _app.Back();
            var result = _app.Query(e => e.Id("MaschineListItem_Title").Index(2));
    
            Assert.AreNotEqual(result[0].Text, firstListItemName[0].Text);
        }

        [Test]
        public void SwitchToAnalysis()
        {
            Setup();

            _app.Tap(e => e.Class("TabView").Index(3));

            var result = _app.Query(e => e.Class("TextView"));
            var isexists = false;
            foreach (var item in result)
            {
                if (item.Text == "Analysis")
                {
                    isexists = true;
                    break;
                }
                else
                {
                    isexists = false;
                }
            }
            
            Assert.IsTrue(isexists);
        }

        [Test]
        public void ShowAnalysisDetailsFromTheFirstMachineCombine1()
        {
            Setup();

            _app.Tap(e => e.Class("TabView").Index(3));
            var listresult = _app.Query(e => e.Class("TextView").Index(0));
            _app.Tap(e => e.Class("TextView").Index(0));

            _app.WaitForElement(e => e.Text("Detail analysis"), "Timed out waiting for Settings activity title", TimeSpan.FromSeconds(2));
            var selectedmaschineCombine1 = _app.Query(e => e.Id("AnalyseDetail_MachineName"));

            Assert.AreEqual(listresult[0].Text, selectedmaschineCombine1[0].Text);
        }

        [Test]
        public void SwitchToMapTab()
        {
            Setup();
            // Act
            _app.Tap(e => e.Class("TabView").Index(2));
            _app.Tap(e => e.Class("View").Index(1));
            
            Assert.IsTrue(_app.Query(e => e.Class("View")).Length > 1);  
        }

        [Test]
        public void SwitchTabMessages()
        {
            Setup();
            
            _app.Tap(e => e.Class("TabView").Index(1));

            var result = _app.Query(e => e.Id("action_bar_title").Text("Messages"));
            Assert.IsTrue(result.Length == 1);
        }

        [Test]
        public void SelectFirstMessageFromTheListAndConfirm()
        {
            Setup();

            _app.Tap(e => e.Class("TabView").Index(1));
            var selectedTextFromItem = _app.Query(e => e.Id("EventListItem_Title").Index(0));
            
            _app.Tap(e => e.Id("EventListItem_Title").Index(0));

            var alertmessagetext = _app.Query(e => e.Id("alertTitle"));
            var isconfirmclicked = false;
            var result = _app.Query(e => e.Class("button").Index(1));
            if (selectedTextFromItem[0].Text == alertmessagetext[0].Text)
            {
                if (result.Length == 1)
                {
                    _app.Tap(e => e.Class("button").Index(1));
                    isconfirmclicked = true;
                }
            }

            Assert.IsTrue(isconfirmclicked);
        }

        [Test]
        public void SelectSecondMessageFromTheListAndConfirm()
        {
            Setup();
            
            _app.Tap(e => e.Class("TabView").Index(1));
            var selectedTextFromItem = _app.Query(e => e.Id("EventListItem_Title").Index(1));
            
            _app.Tap(e => e.Id("EventListItem_Title").Index(1));

            var alertmessagetext = _app.Query(e => e.Id("alertTitle"));
            var isconfirmclicked = false;
            var result = _app.Query(e => e.Class("button").Index(1));
            if (selectedTextFromItem[0].Text == alertmessagetext[0].Text)
            {
                if (result.Length == 1)
                {
                    _app.Tap(e => e.Class("button").Index(1));
                    isconfirmclicked = true;
                }
            }

            Assert.IsTrue(isconfirmclicked);
        }

        [Test]
        public void SelectSecondMessageFromTheListAndConfirmAndWithdraw()
        {
            Setup();

            _app.Tap(e => e.Class("TabView").Index(1));
            var selectedTextFromItem = _app.Query(e => e.Id("EventListItem_Title").Index(1));

            _app.Tap(e => e.Id("EventListItem_Title").Index(1));

            var alertmessagetext = _app.Query(e => e.Id("alertTitle"));
            var isWithdrawclicked = false;
            var result = _app.Query(e => e.Class("button").Index(1));
            if (selectedTextFromItem[0].Text == alertmessagetext[0].Text)
            {
                if (result.Length == 1)
                {
                    _app.Tap(e => e.Class("button").Index(1));
                    _app.Tap(e => e.Id("EventListItem_Title").Index(1));
                    _app.Tap(e => e.Class("button").Index(1));
                    
                    isWithdrawclicked = true;
                }
            }

            Assert.IsTrue(isWithdrawclicked);
        }
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.