Skip to content

Commit

Permalink
Added tests for ITextBox (#5)
Browse files Browse the repository at this point in the history
Implemented tests for ITextBox interface
  • Loading branch information
hsuboch authored and mialeska committed Sep 17, 2019
1 parent 2a34f34 commit 9f83c20
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Aquality.Selenium.Core.Applications;
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ namespace Aquality.WinAppDriver.Tests.Applications
{
public class CalculatorTest : TestWithApplication
{
private readonly CalculatorWindow calculatorWindow = new CalculatorWindow();

[Test]
public void Should_WorkWithCalculator()
{
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.OneButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.PlusButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.TwoButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.EqualsButton).Click();
var result = ApplicationManager.Application.Driver.FindElement(CalculatorWindow.ResultsLabel).Text;
ApplicationManager.Application.Driver.FindElement(calculatorWindow.OneButton.Locator).Click();
ApplicationManager.Application.Driver.FindElement(calculatorWindow.PlusButton.Locator).Click();
ApplicationManager.Application.Driver.FindElement(calculatorWindow.TwoButton.Locator).Click();
ApplicationManager.Application.Driver.FindElement(calculatorWindow.EqualsButton.Locator).Click();
var result = ApplicationManager.Application.Driver.FindElement(calculatorWindow.ResultsLabel.Locator).Text;
StringAssert.Contains("3", result);
}

[Test]
public void Should_WorkWithCalculator_ViaElementFinder()
{
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(CalculatorWindow.OneButton).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(CalculatorWindow.PlusButton).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(CalculatorWindow.TwoButton).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(CalculatorWindow.EqualsButton).Click();
var result = ApplicationManager.GetRequiredService<IElementFinder>().FindElement(CalculatorWindow.ResultsLabel).Text;
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.OneButton.Locator).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.PlusButton.Locator).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.TwoButton.Locator).Click();
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.EqualsButton.Locator).Click();
var result = ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.ResultsLabel.Locator).Text;
StringAssert.Contains("3", result);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
using OpenQA.Selenium;
using Aquality.WinAppDriver.Elements.Interfaces;
using Aquality.WinAppDriver.Windows;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;

namespace Aquality.WinAppDriver.Tests.Applications.Locators
{
public static class CalculatorWindow
public class CalculatorWindow : Window
{
public static By WindowLocator => By.TagName("Window");
private static By WindowLocator => By.TagName("Window");

public static By OneButton => By.Name("1");
public ITextBox RightArgumentTextBox => ElementFactory.GetTextBox(By.XPath("//*[@AutomationId='49']"), "Right Argument");

public static By TwoButton => By.Name("2");
public IButton OneButton => ElementFactory.GetButton(By.Name("1"), "1");

public static By ThreeButton => By.Name("3");
public IButton TwoButton => ElementFactory.GetButton(By.Name("2"), "2");

public static By PlusButton => By.Name("+");
public IButton PlusButton => ElementFactory.GetButton(By.Name("+"), "+");

public static By EqualsButton => By.Name("=");
public IButton EqualsButton => ElementFactory.GetButton(By.Name("="), "=");

public static By ResultsLabel => MobileBy.AccessibilityId("48");
public ILabel ResultsLabel => ElementFactory.GetLabel(MobileBy.AccessibilityId("48"), "Results bar");

public IElement NumberPad => ElementFactory.GetButton(WindowLocator, "Number pad");

public CalculatorWindow() : base(WindowLocator, "Main Calculator Window")
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,29 @@ namespace Aquality.WinAppDriver.Tests.Elements
{
public class ElementFactoryTests : TestWithApplication
{
private static readonly CalculatorWindow calculatorWindow = new CalculatorWindow();
private IElementFactory Factory => ApplicationManager.GetRequiredService<IElementFactory>();

private IElement NumberPad => GetButton(Factory, CalculatorWindow.WindowLocator, "Number pad");

[Test]
public void Should_WorkWithCalculator_ViaElementFactory()
{
GetButton(Factory, CalculatorWindow.OneButton, "1").Click();
GetButton(Factory, CalculatorWindow.PlusButton, "+").Click();
GetButton(Factory, CalculatorWindow.TwoButton, "2").Click();
GetButton(Factory, CalculatorWindow.EqualsButton, "=").Click();
var result = GetButton(Factory, CalculatorWindow.ResultsLabel, "Results bar").Text;
StringAssert.Contains("3", result);
calculatorWindow.OneButton.Click();
calculatorWindow.PlusButton.Click();
calculatorWindow.TwoButton.Click();
calculatorWindow.EqualsButton.Click();
StringAssert.Contains("3", calculatorWindow.ResultsLabel.Text);
}

[Test]
public void Should_FindChildElements_ViaElementFactory()
{
Assert.IsNotNull(Factory.FindChildElement<Button>(NumberPad, CalculatorWindow.OneButton).GetElement(TimeSpan.Zero));
Assert.IsNotNull(Factory.FindChildElement<Button>(calculatorWindow.NumberPad, calculatorWindow.OneButton.Locator).GetElement(TimeSpan.Zero));
}

[Test]
public void Should_FindElements_ViaElementFactory()
{
Assert.IsTrue(Factory.FindElements<Button>(By.XPath("//*")).Count > 1);
}

public static IButton GetButton(IElementFactory coreFactory, By loc, string nam)
{
return coreFactory.GetButton(loc, nam);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Aquality.WinAppDriver.Elements.Interfaces;
using Aquality.WinAppDriver.Tests.Applications.Locators;
using NUnit.Framework;

namespace Aquality.WinAppDriver.Tests.Elements
{
public class TextBoxTests : TestWithApplication
{
private const string ExpectedValue = "1";
private readonly ITextBox rightArgumentTextBox = new CalculatorWindow().RightArgumentTextBox;

[Test]
public void Should_EnterValues()
{
rightArgumentTextBox.Type(ExpectedValue);
Assert.AreEqual(ExpectedValue, rightArgumentTextBox.Value);
}

[Test]
public void Should_EnterValues_WithoutCleaningTextbox()
{
rightArgumentTextBox.Type(ExpectedValue);
const string additionalExpectedValue = "23";
rightArgumentTextBox.Type(additionalExpectedValue);
Assert.AreEqual(ExpectedValue + additionalExpectedValue, rightArgumentTextBox.Value);
}

[Test]
public void Should_ClearTextBeforeEnteringValues_PrefilledTextbox()
{
rightArgumentTextBox.Type("123");
rightArgumentTextBox.ClearAndType(ExpectedValue);
Assert.AreEqual(ExpectedValue, rightArgumentTextBox.Value);
}

[Test]
public void Should_ClearTextBeforeEnteringValues_EmptyTextbox()
{
rightArgumentTextBox.ClearAndType(ExpectedValue);
Assert.AreEqual(ExpectedValue, rightArgumentTextBox.Value);
}
}
}

0 comments on commit 9f83c20

Please sign in to comment.