public void ForAll_WhenFindAll_ShouldNotThrowException()
        {
            var uiObjectOne = _testHelper.CreateUiObject(With.Class("test"), 500);
            var uiObjectTwo = _testHelper.CreateUiObject(With.ResourceId("test"), 500);

            UiWait.ForAll(1, uiObjectOne.IsVisible, uiObjectTwo.IsVisible);
        }
        public void ForAll_WhenCantFindAll_ShouldThrowException()
        {
            var uiObjectOne = _testHelper.CreateUiObject(With.Class("test"), 500, true);
            var uiObjectTwo = _testHelper.CreateUiObject(With.ResourceId("test"), 500, true);

            Assert.Throws <UiNodeNotFoundException>(() => UiWait.ForAll(1, uiObjectOne.IsVisible, uiObjectTwo.IsVisible));
        }
Example #3
0
        public void NodeChecker_WhenGettingNodeWithClass_ShouldReturnNode()
        {
            var foundNode = _nodeFinder.FindNode(_nodes, With.Class("android.widget.TextView"));

            Assert.IsNotNull(foundNode);
            Assert.AreEqual("android.widget.TextView", foundNode.Class);
        }
        public void ForAny_WhenFindNodeOnFirst_ShouldReturnFirst()
        {
            var uiObjectOne = _testHelper.CreateUiObject(With.Class("test"), 0);
            var uiObjectTwo = _testHelper.CreateUiObject(With.ResourceId("test"), 2000);
            var foundObject = UiWait.ForAny(10, uiObjectOne.IsVisible, uiObjectTwo.IsHidden);

            Assert.AreEqual(uiObjectOne, foundObject);
        }
        public void ForAny_IfObjectLaterThrowsException_ShouldNotCrash()
        {
            var uiObjectOne = _testHelper.CreateUiObject(With.Class("test"), 0);
            var uiObjectTwo = _testHelper.CreateUiObject(With.ResourceId("test"), 500, true);
            var foundObject = UiWait.ForAny(10, uiObjectOne.IsVisible, uiObjectTwo.IsHidden);

            Assert.AreEqual(uiObjectOne, foundObject);
            Thread.Sleep(1000);
        }
        public void WaitForValue_WhenWaitingForValueAndValuesDontMatch_ShouldReturnFalse()
        {
            var uiObject = _testHelper.CreateUiObject(With.Class("testClass"), 0);

            _testHelper.UiServiceMock.Setup(u => u.FindNode(It.IsAny <int>(), It.IsAny <With[]>()))
            .Returns(new Node(new XElement("node", new XAttribute("clickable", "false")), null));

            Assert.IsFalse(uiObject.WaitForValue(n => n.Clickable, 1));
        }
        public void WaitForValue_WhenWaitingForValueAndValueChangeAfter2Second_ShouldReturnTrue()
        {
            var uiObject = _testHelper.CreateUiObject(With.Class("testClass"), 0);

            _testHelper.UiServiceMock.Setup(u => u.FindNode(It.IsAny <int>(), It.IsAny <With[]>()))
            .Returns(new Node(new XElement("node", new XAttribute("clickable", "false")), null));

            Task.Run(() =>
            {
                Thread.Sleep(2000);
                _testHelper.UiServiceMock.Setup(u => u.FindNode(It.IsAny <int>(), It.IsAny <With[]>()))
                .Returns(new Node(new XElement("node", new XAttribute("clickable", "true")), null));
            });

            Assert.IsTrue(uiObject.WaitForValue(n => n.Clickable));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateAttribute"/> class.
        /// </summary>
        /// <param name="with">Find node with this attribute tag.</param>
        /// <param name="value">Find node with this value on the wanted attribute tag.</param>
        public CreateAttribute(AttributeTags with, string value)
        {
            switch (with)
            {
            case AttributeTags.TextContains:
                With = With.ContainsText(value);
                break;

            case AttributeTags.Text:
                With = With.Text(value);
                break;

            case AttributeTags.ResourceId:
                With = With.ResourceId(value);
                break;

            case AttributeTags.ContentDesc:
                With = With.ContentDesc(value);
                break;

            case AttributeTags.Class:
                With = With.Class(value);
                break;

            case AttributeTags.Package:
                With = With.Package(value);
                break;

            case AttributeTags.Index:
                With = With.Index(int.Parse(value));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(with), with, null);
            }
        }
        public void ForAny_IfNoObjectIsFound_ShouldThrowException()
        {
            var uiObject = _testHelper.CreateUiObject(With.Class("hej"), 0, true);

            Assert.Throws <UiNodeNotFoundException>(() => UiWait.ForAny(10, uiObject.IsVisible));
        }