コード例 #1
0
        public void CanAddAndRemoveChildComponentsDynamically()
        {
            // Initially there are zero child components
            var appElement   = MountTestComponent <AddRemoveChildComponents>();
            var addButton    = appElement.FindElement(By.ClassName("addChild"));
            var removeButton = appElement.FindElement(By.ClassName("removeChild"));
            Func <IEnumerable <IWebElement> > childComponentWrappers = () => appElement.FindElements(By.TagName("p"));

            Assert.Empty(childComponentWrappers());

            // Click to add/remove some child components
            addButton.Click();
            WaitAssert.Collection(childComponentWrappers,
                                  elem => Assert.Equal("Child 1", elem.FindElement(By.ClassName("message")).Text));

            addButton.Click();
            WaitAssert.Collection(childComponentWrappers,
                                  elem => Assert.Equal("Child 1", elem.FindElement(By.ClassName("message")).Text),
                                  elem => Assert.Equal("Child 2", elem.FindElement(By.ClassName("message")).Text));

            removeButton.Click();
            WaitAssert.Collection(childComponentWrappers,
                                  elem => Assert.Equal("Child 1", elem.FindElement(By.ClassName("message")).Text));

            addButton.Click();
            WaitAssert.Collection(childComponentWrappers,
                                  elem => Assert.Equal("Child 1", elem.FindElement(By.ClassName("message")).Text),
                                  elem => Assert.Equal("Child 3", elem.FindElement(By.ClassName("message")).Text));
        }
コード例 #2
0
        public void CanRenderMultipleChildContent()
        {
            var appElement = MountTestComponent <MultipleChildContent>();

            var table = appElement.FindElement(By.TagName("table"));

            var thead = table.FindElement(By.TagName("thead"));

            Assert.Collection(
                thead.FindElements(By.TagName("th")),
                e => Assert.Equal("Col1", e.Text),
                e => Assert.Equal("Col2", e.Text),
                e => Assert.Equal("Col3", e.Text));

            var tfoot = table.FindElement(By.TagName("tfoot"));

            Assert.Empty(tfoot.FindElements(By.TagName("td")));

            var toggle = appElement.FindElement(By.Id("toggle"));

            toggle.Click();

            WaitAssert.Collection(
                () => tfoot.FindElements(By.TagName("td")),
                e => Assert.Equal("The", e.Text),
                e => Assert.Equal("", e.Text),
                e => Assert.Equal("End", e.Text));
        }
コード例 #3
0
        public void CanTriggerKeyPressEvents()
        {
            // List is initially empty
            var appElement   = MountTestComponent <KeyPressEventComponent>();
            var inputElement = appElement.FindElement(By.TagName("input"));
            Func <IEnumerable <IWebElement> > liElements =
                () => appElement.FindElements(By.TagName("li"));

            Assert.Empty(liElements());

            // Typing adds element
            inputElement.SendKeys("a");
            WaitAssert.Collection(liElements,
                                  li => Assert.Equal("a", li.Text));

            // Typing again adds another element
            inputElement.SendKeys("b");
            WaitAssert.Collection(liElements,
                                  li => Assert.Equal("a", li.Text),
                                  li => Assert.Equal("b", li.Text));

            // Textbox contains typed text
            Assert.Equal("ab", inputElement.GetAttribute("value"));
        }