Skip to content

Commit

Permalink
Tests for Window class (#18)
Browse files Browse the repository at this point in the history
* added tests for IElement

* fixed element type

* started implementing tests for IElementStateProvider

* implemented IElementStateProvider tests

* renamed test

* implemented tests for public properties

* added tests

* refactored test methods

* fixed test name

* fixed test. added Should_ReturnCorrectElementType(), moved TestWindow class

* moved property in class
  • Loading branch information
hsuboch authored and mialeska committed Oct 11, 2019
1 parent f59575c commit 5a0bb8d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Aquality.WinAppDriver.Windows;
using OpenQA.Selenium;

namespace Aquality.WinAppDriver.Tests.Windows
{
public class TestWindow : Window
{
public TestWindow(By locator, string name) : base(locator, name)
{
}

public new string ElementType => base.ElementType;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,82 @@
using NUnit.Framework;
using OpenQA.Selenium;

namespace Aquality.WinAppDriver.Tests.Windows
{
public class WindowTests : TestWithApplication
{
private static readonly CalculatorWindowWithRelativeElements calculatorWindow = new CalculatorWindowWithRelativeElements();
private const int ExpectedHeight = 500;
private const int ExpectedWidth = 709;
private static readonly By Locator = By.XPath("//*[@id='111111']");
private const string PageName = "Not present page";
private const string ExpectedElementType = "Акно";

private static readonly CalculatorWindowWithRelativeElements CalculatorWindowWithRelativeElements =
new CalculatorWindowWithRelativeElements();

private static readonly CalculatorWindow CalculatorWindow = new CalculatorWindow();

private static TestWindow TestWindow => new TestWindow(Locator, PageName);

[Test]
public void Should_WorkWithCalculator_ViaRelativeElements()
{
calculatorWindow.OneButton.Click();
calculatorWindow.PlusButton.Click();
calculatorWindow.TwoButton.Click();
calculatorWindow.EqualsButton.Click();
StringAssert.Contains("3", calculatorWindow.ResultsLabel.Text);
CalculatorWindowWithRelativeElements.OneButton.Click();
CalculatorWindowWithRelativeElements.PlusButton.Click();
CalculatorWindowWithRelativeElements.TwoButton.Click();
CalculatorWindowWithRelativeElements.EqualsButton.Click();
StringAssert.Contains("3", CalculatorWindowWithRelativeElements.ResultsLabel.Text);
}

[Test]
public void Should_GetSizeCorrectly_WhenWindowIsPresent()
{
var windowSize = CalculatorWindow.Size;
Assert.Multiple(() =>
{
Assert.IsFalse(windowSize.IsEmpty, "Window is not empty");
Assert.AreEqual(ExpectedHeight, windowSize.Height, "Height");
Assert.AreEqual(ExpectedWidth, windowSize.Width, "Width");
});
}

[Test]
public void Should_ThrowException_InGetSize_WhenWindowIsNotPresent()
{
Assert.Throws<NoSuchElementException>(() =>
{
var testWindowSize = TestWindow.Size;
});
}

[Test]
public void Should_ReturnTrue_IfWindowIsDisplayed()
{
Assert.IsTrue(CalculatorWindow.IsDisplayed);
}

[Test]
public void Should_ReturnFalse_IfWindowIsNotDisplayed()
{
Assert.IsFalse(TestWindow.IsDisplayed);
}

[Test]
public void Should_SetCorrectLocatorInConstructor()
{
Assert.AreEqual(Locator, TestWindow.Locator, "Locator");
}

[Test]
public void Should_SetCorrectPageNameInConstructor()
{
Assert.AreEqual(PageName, TestWindow.Name, "Name");
}

[Test]
public void Should_ReturnCorrectElementType()
{
Assert.AreEqual(ExpectedElementType, TestWindow.ElementType);
}
}
}
}

0 comments on commit 5a0bb8d

Please sign in to comment.