示例#1
0
        public void ClassThatIsSelfValidating()
        {
            // Arrange
            var actual = new ClassThatIsSelfValidating();

            // Act
            var pageObjectSchema = new SelfValidatingPageObjectSchemaGenerator().ExtractSchema(actual);

            // Assert
            Assert.IsTrue(pageObjectSchema.SchemaValid);
            Assert.AreEqual(pageObjectSchema.PageName, "ClassThatIsSelfValidating");

            Assert.IsFalse(pageObjectSchema.HasChildObjects);
            Assert.AreEqual(pageObjectSchema.ChildPageObjectNames.Count, 0);

            Assert.AreEqual(pageObjectSchema.ExpectedElements.Count, 4); // 2 properties and 2 in the definition set
            Assert.AreEqual(pageObjectSchema.ExpectedElements[0].Id, "678");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[1].Id, "901");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[2].Id, "Property1");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[3].Id, "Property2");

            Assert.AreEqual(pageObjectSchema.KnownExclusionElements.Count, 2); // 2 from the definition set
            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[0].Id, "123");
            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[1].Id, "456");

            Assert.AreEqual(pageObjectSchema.ActualElements.Count, 0); // will be zero as no selenium is used in the unit tests
        }
示例#2
0
        /// <exception cref="InvalidPageDomStructureException">Thrown when DOM structure of the displayed page is invalid.</exception>
        public bool ValidateDisplayedPage <T>(T pageObject, List <string> elementIdsToExcludeFromDomComparison) where T : Interactable, ISelfValidatingPageObject
        {
            var pageObjectSchema = new SelfValidatingPageObjectSchemaGenerator().ExtractSchema(pageObject);

            if (!pageObjectSchema.SchemaValid)
            {
                // log each item which is missing an Id.
                LogX.Info.Write("One or more invalid DOM elements was detected during a ValidatePageObjectAgainstWebElementContents call.", pageObjectSchema.InvalidElementDetails);

                // throw an exception
                throw new InvalidPageDomStructureException(pageObject.Name, pageObjectSchema.InvalidElementDetails);
            }

            return(ValidateExpectedDomElementListAgainstActualDomElementList(pageObjectSchema, elementIdsToExcludeFromDomComparison));
        }
示例#3
0
        public void ClassThatIsSelfValidatingWithChildProperties()
        {
            // Arrange
            var actual = new ClassThatIsSelfValidatingWithChildSelfValidatingObject();

            // Act
            var pageObjectSchema = new SelfValidatingPageObjectSchemaGenerator().ExtractSchema(actual);

            // Assert
            Assert.IsTrue(pageObjectSchema.SchemaValid);
            Assert.AreEqual(pageObjectSchema.PageName, "ClassThatIsSelfValidatingWithChildSelfValidatingObject");

            Assert.AreEqual(pageObjectSchema.ChildPageObjectNames.Count, 2);
            Assert.AreEqual(pageObjectSchema.ChildPageObjectNames[0], "ClassThatIsSelfValidating");
            Assert.AreEqual(pageObjectSchema.ChildPageObjectNames[1], "ClassThatIsSelfValidatingButNotAsAChildElement");

            Assert.IsTrue(pageObjectSchema.HasChildObjects);
            Assert.AreEqual(pageObjectSchema.ExpectedElements.Count, 10); // 2 properties and 2 in the definition set
            Assert.AreEqual(pageObjectSchema.ExpectedElements[0].Id, "hij");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[1].Id, "klm");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[2].Id, "PropertyA");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[2].IsNonInteractableElement, false);

            Assert.AreEqual(pageObjectSchema.ExpectedElements[3].Id, "PropertyB");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[3].IsNonInteractableElement, true);

            Assert.AreEqual(pageObjectSchema.ExpectedElements[4].Id, "PropertyC");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[4].IsNonInteractableElement, true);

            Assert.AreEqual(pageObjectSchema.ExpectedElements[5].Id, "PropertyD");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[5].IsNonInteractableElement, false);

            Assert.AreEqual(pageObjectSchema.ExpectedElements[6].Id, "678");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[7].Id, "901");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[8].Id, "Property1");
            Assert.AreEqual(pageObjectSchema.ExpectedElements[9].Id, "Property2");

            Assert.AreEqual(pageObjectSchema.KnownExclusionElements.Count, 10); // 2 from the definition set
            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[0].Id, "abcd");
            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[1].Id, "efg");

            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[2].Id, "123");
            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[3].Id, "456");

            Assert.AreEqual(pageObjectSchema.KnownExclusionElements[4].Id, "987");

            Assert.AreEqual(pageObjectSchema.ActualElements.Count, 0); // will be zero as no selenium is used in the unit tests
        }