本文整理汇总了C#中Element.Ancestor方法的典型用法代码示例。如果您正苦于以下问题:C# Element.Ancestor方法的具体用法?C# Element.Ancestor怎么用?C# Element.Ancestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element.Ancestor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AncestorGenericType
public void AncestorGenericType()
{
var nativeElementMock = new Mock<INativeElement>();
var firstParentDivMock = new Mock<INativeElement>();
var secondParentDivMock = new Mock<INativeElement>();
var domContainerMock = new Mock<DomContainer>(new object[] { });
element = new Element(domContainerMock.Object, nativeElementMock.Object);
nativeElementMock.Expect(native => native.Parent).Returns(firstParentDivMock.Object);
firstParentDivMock.Expect(first => first.TagName).Returns("a");
firstParentDivMock.Expect(first => first.Parent).Returns(secondParentDivMock.Object);
secondParentDivMock.Expect(second => second.TagName).Returns("div");
Assert.That(element.Ancestor<Div>(), Is.Not.Null);
nativeElementMock.VerifyAll();
firstParentDivMock.VerifyAll();
secondParentDivMock.VerifyAll();
domContainerMock.VerifyAll();
}
示例2: AncestorTypeShouldOnlyExceptTypesInheritingElement
public void AncestorTypeShouldOnlyExceptTypesInheritingElement()
{
// GIVEN
var nativeElementMock = new Mock<INativeElement>();
nativeElementMock.Expect(x => x.IsElementReferenceStillValid()).Returns(true);
var element1 = new Element(new Mock<DomContainer>().Object, nativeElementMock.Object);
// WHEN
element1.Ancestor(typeof (String));
// THEN exception
}
示例3: AncestorTagNameAndAttributeConstraintShouldReturnTypedElement
public void AncestorTagNameAndAttributeConstraintShouldReturnTypedElement()
{
// GIVEN
var nativeElementMock = new Mock<INativeElement>();
var firstParentDivMock = new Mock<INativeElement>();
var secondParentDivMock = new Mock<INativeElement>();
var domContainerMock = new Mock<DomContainer> (new object[] { });
element = new Element(domContainerMock.Object, nativeElementMock.Object);
nativeElementMock.Expect(native => native.Parent).Returns(firstParentDivMock.Object);
firstParentDivMock.Expect(first => first.TagName).Returns("div");
firstParentDivMock.Expect(first => first.GetAttributeValue("tagName")).Returns("div");
firstParentDivMock.Expect(first => first.GetAttributeValue("innertext")).Returns("first ancestor");
firstParentDivMock.Expect(first => first.Parent).Returns(secondParentDivMock.Object);
secondParentDivMock.Expect(second => second.TagName).Returns("div");
secondParentDivMock.Expect(second => second.GetAttributeValue("tagName")).Returns("div");
secondParentDivMock.Expect(second => second.GetAttributeValue("innertext")).Returns("second ancestor");
// WHEN
var ancestor = element.Ancestor("Div", Find.ByText("second ancestor"));
// THEN
nativeElementMock.VerifyAll();
firstParentDivMock.VerifyAll();
secondParentDivMock.VerifyAll();
Assert.IsInstanceOfType(typeof (Div), ancestor);
Assert.That(ancestor.Text, Is.EqualTo("second ancestor"));
}