Skip to content

Commit

Permalink
Merge pull request #102 from MADE-Apps/feature/conditions
Browse files Browse the repository at this point in the history
Added WaitUntil conditions
  • Loading branch information
jamesmcroft authored Nov 12, 2021
2 parents 39ba7c9 + 6751bb1 commit c58b5c1
Show file tree
Hide file tree
Showing 78 changed files with 1,067 additions and 571 deletions.
6 changes: 3 additions & 3 deletions samples/W3SchoolsWebTests/Tests/FileInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public class FileInputTests : BaseTestClass
[Test]
public void ShouldSetAbsoluteFilePath()
{
string filePath = Path.Combine(Environment.CurrentDirectory, @"Tools\Edge\MicrosoftWebDriver.exe");
string filePath = Path.Combine(Environment.CurrentDirectory, @"msedgedriver.exe");

FileInput fileInput = AppManager.WebApp.FindElementById("myfile") as RemoteWebElement;
fileInput.SetAbsoluteFilePath(filePath);

// Cannot check absolute file path as browser security feature prevents seeing full URI.
fileInput.FilePath.ShouldContain("MicrosoftWebDriver.exe");
fileInput.FilePath.ShouldContain("msedgedriver.exe");
}

[Test]
public void ShouldClearFile()
{
string filePath = Path.Combine(Environment.CurrentDirectory, @"Tools\Edge\MicrosoftWebDriver.exe");
string filePath = Path.Combine(Environment.CurrentDirectory, @"msedgedriver.exe");

FileInput fileInput = AppManager.WebApp.FindElementById("myfile") as RemoteWebElement;
fileInput.SetAbsoluteFilePath(filePath);
Expand Down
8 changes: 4 additions & 4 deletions samples/W3SchoolsWebTests/Tests/RadioButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class RadioButtonTests : BaseTestClass
{
public override string Url => "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio";

[TestCase("male")]
[TestCase("female")]
[TestCase("other")]
[TestCase("html")]
[TestCase("css")]
[TestCase("javascript")]
[TestCase("age1")]
[TestCase("age2")]
[TestCase("age3")]
Expand All @@ -28,7 +28,7 @@ public void ShouldSelect(string radioId)
radioButton.IsSelected.ShouldBeTrue();
}

[TestCase("gender", "male", "female")]
[TestCase("fav_language", "html", "javascript")]
[TestCase("age", "age3", "age2")]
public void ShouldOnlySelectOneInGroup(string groupName, string initialRadioId, string expectedRadioId)
{
Expand Down
16 changes: 8 additions & 8 deletions samples/WebTests/Pages/HomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace WebTests.Pages
/// </summary>
public class HomePage : BasePage
{
private readonly By heroPostsQuery = By.ClassName("nectar-recent-posts-single_featured");
private readonly By heroPostsLocator = By.ClassName("nectar-recent-posts-single_featured");

private readonly By heroPostItemQuery = By.ClassName("nectar-recent-post-slide");
private readonly By heroPostLocator = By.ClassName("nectar-recent-post-slide");

private readonly By readArticleButtonQuery = By.ClassName("nectar-button");
private readonly By readPostButtonLocator = By.ClassName("nectar-button");

/// <summary>
/// Gets a given trait of the page to verify that the page is in view.
Expand All @@ -24,9 +24,9 @@ public class HomePage : BasePage

public HomePage VerifyHeroPostsShown()
{
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsQuery);
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsLocator);

ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostItemQuery);
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostLocator);

Assert.AreEqual(3, heroPosts.Count);

Expand All @@ -35,12 +35,12 @@ public HomePage VerifyHeroPostsShown()

public PostPage NavigateToHeroPost()
{
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsQuery);
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsLocator);

ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostItemQuery);
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostLocator);

IWebElement heroPost = heroPosts.FirstOrDefault(p => p.Displayed);
IWebElement readButton = heroPost.FindElement(this.readArticleButtonQuery);
IWebElement readButton = heroPost.FindElement(this.readPostButtonLocator);

readButton.Click();

Expand Down
91 changes: 91 additions & 0 deletions samples/WindowsAlarmsAndClock/Elements/AlarmPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
namespace WindowsAlarmsAndClock.Elements
{
using System;
using Legerity.Windows.Elements;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Extensions;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;

/// <summary>
/// Defines a <see cref="WindowsElement"/> wrapper for the AlarmPopup control.
/// </summary>
public class AlarmPopup : WindowsElementWrapper
{
/// <summary>
/// Initializes a new instance of the <see cref="AlarmPopup"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="WindowsElement"/> reference.
/// </param>
public AlarmPopup(WindowsElement element)
: base(element)
{
}

/// <summary>
/// Allows conversion of a <see cref="WindowsElement"/> to the <see cref="AlarmPopup"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="WindowsElement"/>.
/// </param>
/// <returns>
/// The <see cref="DurationPicker"/>.
/// </returns>
public static implicit operator AlarmPopup(WindowsElement element)
{
return new AlarmPopup(element);
}

/// <summary>
/// Allows conversion of a <see cref="AppiumWebElement"/> to the <see cref="AlarmPopup"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="AlarmPopup"/>.
/// </returns>
public static implicit operator AlarmPopup(AppiumWebElement element)
{
return new AlarmPopup(element as WindowsElement);
}

/// <summary>
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="AlarmPopup"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="AlarmPopup"/>.
/// </returns>
public static implicit operator AlarmPopup(RemoteWebElement element)
{
return new AlarmPopup(element as WindowsElement);
}

public CustomTimePicker DurationPicker => this.FindElement(ByExtensions.AutomationId("DurationPicker"));

public TextBox AlarmNameInput => this.FindElement(By.Name("Alarm name"));

public Button SaveButton => this.Element.FindElement(ByExtensions.AutomationId("PrimaryButton"));

public void SetTime(TimeSpan time)
{
this.DurationPicker.SetTime(time);
}

public void SetName(string name)
{
this.AlarmNameInput.SetText(name);
}

public void SaveAlarm()
{
this.SaveButton.Click();
}
}
}
25 changes: 17 additions & 8 deletions samples/WindowsAlarmsAndClock/Elements/CustomTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ namespace WindowsAlarmsAndClock.Elements

using Legerity.Windows.Elements;
using Legerity.Windows.Extensions;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;

/// <summary>
/// Defines a <see cref="WindowsElement"/> wrapper for the custom TimePicker control.
/// </summary>
public class CustomTimePicker : WindowsElementWrapper
{
private readonly By hourSelectorQuery = ByExtensions.AutomationId("HourLoopingSelector");

private readonly By minuteSelectorQuery = ByExtensions.AutomationId("MinuteLoopingSelector");

/// <summary>
/// Initializes a new instance of the <see cref="CustomTimePicker"/> class.
/// </summary>
Expand Down Expand Up @@ -57,6 +52,20 @@ public static implicit operator CustomTimePicker(AppiumWebElement element)
return new CustomTimePicker(element as WindowsElement);
}

/// <summary>
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="CustomTimePicker"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="CustomTimePicker"/>.
/// </returns>
public static implicit operator CustomTimePicker(RemoteWebElement element)
{
return new CustomTimePicker(element as WindowsElement);
}

/// <summary>
/// Sets the time to the specified time.
/// </summary>
Expand All @@ -65,8 +74,8 @@ public static implicit operator CustomTimePicker(AppiumWebElement element)
/// </param>
public void SetTime(TimeSpan time)
{
this.Element.FindElement(this.hourSelectorQuery).FindElementByName(time.ToString("%h")).Click();
this.Element.FindElement(this.minuteSelectorQuery).FindElementByName(time.ToString("mm")).Click();
this.Element.FindElement(ByExtensions.AutomationId("HourPicker")).FindElementByName(time.ToString("%h")).Click();
this.Element.FindElement(ByExtensions.AutomationId("MinutePicker")).FindElementByName(time.ToString("mm")).Click();
}
}
}
43 changes: 31 additions & 12 deletions samples/WindowsAlarmsAndClock/Pages/AlarmPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ namespace WindowsAlarmsAndClock.Pages
using System;
using System.Collections.ObjectModel;
using System.Linq;

using Elements;
using Legerity.Extensions;
using Legerity.Pages;
using Legerity.Windows.Extensions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Remote;

/// <summary>
/// Defines the alarm page of the Windows Alarms &amp; Clock application.
/// </summary>
public class AlarmPage : BasePage
public class AlarmPage : AppPage
{
private readonly By addAlarmButton;

private readonly By selectAlarmsButton;

private readonly By alarmList;

/// <summary>
Expand All @@ -29,10 +29,11 @@ public class AlarmPage : BasePage
public AlarmPage()
{
this.addAlarmButton = ByExtensions.AutomationId("AddAlarmButton");
this.selectAlarmsButton = ByExtensions.AutomationId("SelectAlarmsButton");
this.alarmList = ByExtensions.AutomationId("AlarmListView");
}

public AlarmPopup AlarmPopup => this.WindowsApp.FindElement(ByExtensions.AutomationId("EditFlyout"));

/// <summary>
/// Gets a given trait of the page to verify that the page is in view.
/// </summary>
Expand All @@ -42,12 +43,12 @@ public AlarmPage()
/// Navigates to adding an alarm.
/// </summary>
/// <returns>
/// The <see cref="EditAlarmPage"/>.
/// The <see cref="AlarmPage"/>.
/// </returns>
public EditAlarmPage GoToAddAlarm()
public AlarmPage GoToAddAlarm()
{
this.WindowsApp.FindElement(this.addAlarmButton).Click();
return new EditAlarmPage();
return this;
}

/// <summary>
Expand All @@ -57,12 +58,30 @@ public EditAlarmPage GoToAddAlarm()
/// The name of the alarm to edit.
/// </param>
/// <returns>
/// The <see cref="EditAlarmPage"/>.
/// The <see cref="AlarmPage"/>.
/// </returns>
public EditAlarmPage GoToEditAlarm(string alarmName)
public AlarmPage GoToEditAlarm(string alarmName)
{
this.GetListAlarmElement(alarmName).Click();
return new EditAlarmPage();
return this;
}

public AlarmPage SetAlarmTime(TimeSpan time)
{
this.AlarmPopup.SetTime(time);
return this;
}

public AlarmPage SetAlarmName(string name)
{
this.AlarmPopup.SetName(name);
return this;
}

public AlarmPage SaveAlarm()
{
this.AlarmPopup.SaveAlarm();
return this;
}

/// <summary>
Expand Down Expand Up @@ -101,7 +120,7 @@ private AppiumWebElement GetListAlarmElement(string name)
this.WindowsApp.FindElement(this.alarmList).FindElements(By.ClassName("ListViewItem"));

return listElements.FirstOrDefault(
element => element.GetAttribute("Name").Contains(name, StringComparison.CurrentCulture));
element => element.GetName().Contains(name, StringComparison.CurrentCulture));
}
}
}
30 changes: 30 additions & 0 deletions samples/WindowsAlarmsAndClock/Pages/AppPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace WindowsAlarmsAndClock.Pages
{
using System;
using Legerity.Pages;
using Legerity.Windows.Elements.WinUI;
using Legerity.Windows.Extensions;
using OpenQA.Selenium;

public class AppPage : BasePage
{
public NavigationView NavigationView => this.WindowsApp.FindElement(this.Trait);

/// <summary>
/// Gets a given trait of the page to verify that the page is in view.
/// </summary>
protected override By Trait => ByExtensions.AutomationId("NavView");

/// <summary>
/// Selects a sample from the available options with the given name.
/// </summary>
/// <typeparam name="TPage">The type of page to return.</typeparam>
/// <param name="name">The name of the sample to click.</param>
/// <returns>The <see cref="TPage"/> instance.</returns>
public TPage SelectPage<TPage>(string name) where TPage : BasePage
{
this.NavigationView.ClickMenuOption(name);
return Activator.CreateInstance<TPage>();
}
}
}
4 changes: 2 additions & 2 deletions samples/WindowsAlarmsAndClock/Tests/AlarmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void AddAlarm()
const string ExpectedAlarmName = "Test Add Alarm";
var expectedAlarmTime = new TimeSpan(7, 5, 0);

var alarmPage = new AlarmPage();
AlarmPage alarmPage = new AppPage().SelectPage<AlarmPage>("Alarm");

// Act
alarmPage.GoToAddAlarm().SetAlarmTime(expectedAlarmTime).SetAlarmName(ExpectedAlarmName).SaveAlarm();
Expand All @@ -32,7 +32,7 @@ public void EditAlarm()
const string ExpectedAlarmName = "Test Edit Alarm";
var expectedAlarmTime = new TimeSpan(12, 30, 0);

var alarmPage = new AlarmPage();
AlarmPage alarmPage = new AppPage().SelectPage<AlarmPage>("Alarm");
alarmPage.GoToAddAlarm().SetAlarmTime(new TimeSpan(7, 5, 0)).SetAlarmName(ExpectedAlarmName).SaveAlarm();

// Act
Expand Down
1 change: 1 addition & 0 deletions samples/WindowsAlarmsAndClock/WindowsAlarmsAndClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Legerity.Windows\Legerity.Windows.csproj" />
<ProjectReference Include="..\..\src\Legerity.WinUI\Legerity.WinUI.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit c58b5c1

Please sign in to comment.