public void IsHiddenShouldReturnTrueWhenElementIsNotDisplayed() { ElementMock.Setup(e => e.Size).Returns(new Size(100, 100)); ElementMock.Setup(e => e.Displayed).Returns(false); Assert.True(ElementMock.Object.IsHidden()); }
public void IsHiddenShoutReturnFalseWhenElementIsDisplayed() { ElementMock.Setup(e => e.Size).Returns(new Size(100, 100)); ElementMock.Setup(e => e.Displayed).Returns(true); Assert.That(ElementMock.Object.IsHidden(), Is.False); }
public void Element_GetElement_Test() { var element = new ElementMock(new TestHelpers.RootElement(), AssetManager); string elementName = "element2"; var expected = new ElementMock(element, AssetManager) { Name = elementName }; Assert.AreEqual(expected, element.GetElement(elementName)); Assert.IsNull(element.GetElement("invalidName")); }
public void Element_GetVisualTree_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager); var element2 = new ElementMock(element, AssetManager); var element3 = new ElementMock(element2, AssetManager); var expected = new Element[] { element, element2, element3 }; Assert.IsTrue(expected.SequenceEqual(element.GetVisualTree())); }
public void ShouldHandleNoSuchElementException( Action <IWebElement, TimeSpan, TimeSpan, String> waitUntilHidden, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Displayed).Returns(true); ExecuteAsync(() => ElementMock.Setup(e => e.Displayed).Throws <NoSuchElementException>(), TimeSpan.FromSeconds(2)); waitUntilHidden(ElementMock.Object, timeout, pollingInterval, errorMessage); }
public void ShouldReturnOnceElementBecameVisible( Func <IWebElement, TimeSpan, TimeSpan, String, IWebElement> waitForVisible, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Displayed).Returns(false); ExecuteAsync(() => ElementMock.Setup(e => e.Displayed).Returns(true), timeout.Subtract(TimeSpan.FromSeconds(2))); Assert.That(waitForVisible(ElementMock.Object, timeout, pollingInterval, errorMessage), Is.SameAs(ElementMock.Object)); }
public void ShouldHandleNoSuchElementException( Func <IWebElement, TimeSpan, TimeSpan, String, IWebElement> waitForVisible, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Displayed).Throws <NoSuchElementException>(); ExecuteAsync(() => ElementMock.Setup(e => e.Displayed).Returns(true), TimeSpan.FromSeconds(2)); Assert.That(waitForVisible(ElementMock.Object, timeout, pollingInterval, errorMessage), Is.SameAs(ElementMock.Object)); }
public void ShouldHandleStaleElementReferenceException( Func <IWebElement, TimeSpan, TimeSpan, String, IWebElement> waitForPresent, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Size).Throws <StaleElementReferenceException>(); ExecuteAsync(() => ElementMock.Setup(e => e.Size).Returns(new Size(1, 1)), TimeSpan.FromSeconds(2)); Assert.That(waitForPresent(ElementMock.Object, timeout, pollingInterval, errorMessage), Is.SameAs(ElementMock.Object)); }
public void ShouldReturnOnceElementBecameAddedToDocument( Func <IWebElement, TimeSpan, TimeSpan, String, IWebElement> waitForPresent, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Size).Throws <NoSuchElementException>(); ExecuteAsync(() => ElementMock.Setup(e => e.Size).Returns(new Size(1, 1)), timeout.Subtract(TimeSpan.FromSeconds(2))); Assert.That(waitForPresent(ElementMock.Object, timeout, pollingInterval, errorMessage), Is.SameAs(ElementMock.Object)); }
public void ShouldHandleStaleElementReferenceException( Action <IWebElement, TimeSpan, TimeSpan, string> waitUntilHidden, TimeSpan timeout, TimeSpan pollingInterval, string errorMessage ) { ElementMock.Setup(e => e.Displayed).Throws <StaleElementReferenceException>(); ExecuteAsync(() => ElementMock.Setup(e => e.Displayed).Returns(false), TimeSpan.FromSeconds(2)); waitUntilHidden(ElementMock.Object, timeout, pollingInterval, errorMessage); }
public void ShouldThrowWebDriverTimeoutExceptionWithGivenMessage( Action <IWebElement, TimeSpan, TimeSpan, string> waitUntilHidden, TimeSpan timeout, TimeSpan pollingInterval, string errorMessage ) { ElementMock.Setup(e => e.Displayed).Returns(true); Assert.That( () => waitUntilHidden(ElementMock.Object, timeout, pollingInterval, errorMessage), Throws.InstanceOf <WebDriverTimeoutException>().With.Message.Contains(errorMessage) ); }
public void ShouldThrowWebDriverTimeoutExceptionWithGivenMessage( Func <IWebElement, TimeSpan, TimeSpan, String, IWebElement> waitForVisible, TimeSpan timeout, TimeSpan pollingInterval, String errorMessage ) { ElementMock.Setup(e => e.Displayed).Returns(false); Assert.That( () => waitForVisible(ElementMock.Object, timeout, pollingInterval, errorMessage), Throws.InstanceOf <WebDriverTimeoutException>().With.Message.Contains(errorMessage) ); }
public void ShouldThrowWebDriverTimeoutExceptionWithGivenMessage( Func <IWebElement, TimeSpan, TimeSpan, string, IWebElement> waitForPresent, TimeSpan timeout, TimeSpan pollingInterval, string errorMessage ) { ElementMock.Setup(e => e.Size).Throws <NoSuchElementException>(); Assert.That( () => waitForPresent(ElementMock.Object, timeout, pollingInterval, errorMessage), Throws.InstanceOf <WebDriverTimeoutException>().With.Message.Contains(errorMessage) ); }
public void Element_DefaultValues_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager) { Name = "ElementMock" }; Assert.AreEqual("ElementMock", element.Name); Assert.AreEqual(new Rectangle(0.0f, 0.0f, 1.0f, 1.0f), element.DestRect); var expectedAbsRect = new Rectangle(parent.AbsRect.Left + parent.AbsRect.Width * element.DestRect.Left, parent.AbsRect.Top + parent.AbsRect.Height * element.DestRect.Top, parent.AbsRect.Width * element.DestRect.Width, parent.AbsRect.Height * element.DestRect.Height); Assert.AreEqual(expectedAbsRect, element.AbsRect); Assert.IsTrue(element.IsLogical); }
public void ShouldReturnOnceElementBecameHidden( Action <IWebElement, TimeSpan, TimeSpan, string> waitUntilHidden, TimeSpan timeout, TimeSpan pollingInterval, string errorMessage ) { ElementMock.Setup(e => e.Displayed).Returns(true); ExecuteAsync( () => ElementMock.Setup(e => e.Displayed).Returns(false), timeout.Subtract(TimeSpan.FromSeconds(2)) ); waitUntilHidden(ElementMock.Object, timeout, pollingInterval, errorMessage); }
public void Element_IsVisible_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager); var element2 = new ElementMock(element, AssetManager); Assert.IsTrue(element.IsVisible); element.IsVisible = false; Assert.IsFalse(element2.IsVisible); TestHelpers.RenderSprite(Device, s => Assert.IsFalse((element as ISprite).Render(s))); var element3 = new ElementMock(element2, AssetManager); Assert.IsFalse(element3.IsVisible); }
public void Element_OnlyLastestChildFiresEvent_Test() { // Direct routing strategy bool parentFired = false; var element = new ElementMock(new TestHelpers.RootElement(), AssetManager); element.MouseDown += ((o, e) => parentFired = true); bool childFired = false; var child = new ElementMock(element, AssetManager); child.MouseDown += (o, e) => { childFired = true; e.Handled = true; }; element.InjectMouseDownEvent(0.0f, 0.0f, MouseButton.Left); Assert.IsFalse(parentFired); Assert.IsTrue(childFired); }
public void IsPresentShouldYieldFalseWhenElementDoesNotExist() { ElementMock.Setup(e => e.Size).Throws <NoSuchElementException>(); Assert.False(ElementMock.Object.IsPresent()); }
public void IsHiddenShouldYieldTrueWhenThereIsNoSuchElement() { ElementMock.Setup(e => e.Size).Throws <NoSuchElementException>(); Assert.That(ElementMock.Object.IsHidden(), Is.True); }
public void Element_RemoveFromParent_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager); var element2 = new ElementMock(element, AssetManager); // Element whose parent is root cannot be removed Assert.IsFalse(element.RemoveFromParent()); Assert.IsTrue(element2.RemoveFromParent()); }
public void IsPresentShouldYieldTrueWhenElementExist() { ElementMock.Setup(e => e.Size).Returns(new Size(100, 100)); Assert.True(ElementMock.Object.IsPresent()); }
public void Element_TopMost_Test() { var element = new ElementMock(new TestHelpers.RootElement(), AssetManager); }
public void Element_MouseMove_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager) { DestRect = new Rectangle(0.5f, 0.5f, 0.5f, 0.5f) }; var elementPos = new Vector2(); // element-relative position var parentPos = new Vector2(); // parent(root)-relative position element.MouseMove += (o, e) => { elementPos = e.GetPosition(element); parentPos = e.GetPosition(parent); }; float moveX = 0.6f * parent.AbsRect.Width, moveY = 0.7f * parent.AbsRect.Height; element.InjectMouseMoveEvent(moveX, moveY); Assert.AreEqual(moveX, parentPos.x); Assert.AreEqual(moveY, parentPos.y); Assert.AreEqual(moveX - element.AbsRect.Left, elementPos.x); Assert.AreEqual(moveY - element.AbsRect.Top, elementPos.y); }
public void Element_MouseEnterLeave_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager) { DestRect = new Rectangle(0.5f, 0.5f, 0.5f, 0.5f) }; bool entered = false, left = false; element.MouseEnter += ((o, e) => entered = true); element.MouseLeave += ((o, e) => left = true); element.InjectMouseMoveEvent(0.0f, 0.0f); Assert.IsFalse(entered); element.InjectMouseMoveEvent(element.AbsRect.Left + 1, element.AbsRect.Top + 1); Assert.IsTrue(entered); Assert.IsFalse(left); element.InjectMouseMoveEvent(0.0f, 0.0f); Assert.IsTrue(left); }
public void Element_MouseButtonDown_Test() { var element = new ElementMock(new TestHelpers.RootElement(), AssetManager) { DestRect = new Rectangle(0.5f, 0.5f, 0.5f, 0.5f) }; bool leftDown = false, rightDown = false, middleDown = false; element.MouseDown += ((o, e) => { switch (e.ChangedButton) { case MouseButton.Left: leftDown = true; break; case MouseButton.Right: rightDown = true; break; case MouseButton.Middle: middleDown = true; break; } e.Handled = true; }); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Left); Assert.IsFalse(leftDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Left); Assert.IsTrue(leftDown); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Right); Assert.IsFalse(rightDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Right); Assert.IsTrue(rightDown); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Middle); Assert.IsFalse(middleDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Middle); Assert.IsTrue(middleDown); }
public void Element_ParentChangesPositionAndSize_Test() { var parent = new TestHelpers.RootElement(); var element = new ElementMock(parent, AssetManager) { Name = "ElementMock" }; parent.AbsRect = new Rectangle(10.0f, 20.0f, 110.0f, 120.0f); var expectedAbsRect = new Rectangle(parent.AbsRect.Left + parent.AbsRect.Width * element.DestRect.Left, parent.AbsRect.Top + parent.AbsRect.Height * element.DestRect.Top, parent.AbsRect.Width * element.DestRect.Width, parent.AbsRect.Height * element.DestRect.Height); Assert.AreEqual(expectedAbsRect, element.AbsRect); }