Skip to content

Commit c58b5c1

Browse files
authored
Merge pull request #102 from MADE-Apps/feature/conditions
Added WaitUntil conditions
2 parents 39ba7c9 + 6751bb1 commit c58b5c1

File tree

78 files changed

+1067
-571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1067
-571
lines changed

samples/W3SchoolsWebTests/Tests/FileInputTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public class FileInputTests : BaseTestClass
1717
[Test]
1818
public void ShouldSetAbsoluteFilePath()
1919
{
20-
string filePath = Path.Combine(Environment.CurrentDirectory, @"Tools\Edge\MicrosoftWebDriver.exe");
20+
string filePath = Path.Combine(Environment.CurrentDirectory, @"msedgedriver.exe");
2121

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

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

2929
[Test]
3030
public void ShouldClearFile()
3131
{
32-
string filePath = Path.Combine(Environment.CurrentDirectory, @"Tools\Edge\MicrosoftWebDriver.exe");
32+
string filePath = Path.Combine(Environment.CurrentDirectory, @"msedgedriver.exe");
3333

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

samples/W3SchoolsWebTests/Tests/RadioButtonTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class RadioButtonTests : BaseTestClass
1515
{
1616
public override string Url => "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio";
1717

18-
[TestCase("male")]
19-
[TestCase("female")]
20-
[TestCase("other")]
18+
[TestCase("html")]
19+
[TestCase("css")]
20+
[TestCase("javascript")]
2121
[TestCase("age1")]
2222
[TestCase("age2")]
2323
[TestCase("age3")]
@@ -28,7 +28,7 @@ public void ShouldSelect(string radioId)
2828
radioButton.IsSelected.ShouldBeTrue();
2929
}
3030

31-
[TestCase("gender", "male", "female")]
31+
[TestCase("fav_language", "html", "javascript")]
3232
[TestCase("age", "age3", "age2")]
3333
public void ShouldOnlySelectOneInGroup(string groupName, string initialRadioId, string expectedRadioId)
3434
{

samples/WebTests/Pages/HomePage.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace WebTests.Pages
1111
/// </summary>
1212
public class HomePage : BasePage
1313
{
14-
private readonly By heroPostsQuery = By.ClassName("nectar-recent-posts-single_featured");
14+
private readonly By heroPostsLocator = By.ClassName("nectar-recent-posts-single_featured");
1515

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

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

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

2525
public HomePage VerifyHeroPostsShown()
2626
{
27-
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsQuery);
27+
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsLocator);
2828

29-
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostItemQuery);
29+
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostLocator);
3030

3131
Assert.AreEqual(3, heroPosts.Count);
3232

@@ -35,12 +35,12 @@ public HomePage VerifyHeroPostsShown()
3535

3636
public PostPage NavigateToHeroPost()
3737
{
38-
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsQuery);
38+
IWebElement heroPostsContainer = this.WebApp.FindElement(this.heroPostsLocator);
3939

40-
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostItemQuery);
40+
ReadOnlyCollection<IWebElement> heroPosts = heroPostsContainer.FindElements(this.heroPostLocator);
4141

4242
IWebElement heroPost = heroPosts.FirstOrDefault(p => p.Displayed);
43-
IWebElement readButton = heroPost.FindElement(this.readArticleButtonQuery);
43+
IWebElement readButton = heroPost.FindElement(this.readPostButtonLocator);
4444

4545
readButton.Click();
4646

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
namespace WindowsAlarmsAndClock.Elements
2+
{
3+
using System;
4+
using Legerity.Windows.Elements;
5+
using Legerity.Windows.Elements.Core;
6+
using Legerity.Windows.Extensions;
7+
using OpenQA.Selenium;
8+
using OpenQA.Selenium.Appium;
9+
using OpenQA.Selenium.Appium.Windows;
10+
using OpenQA.Selenium.Remote;
11+
12+
/// <summary>
13+
/// Defines a <see cref="WindowsElement"/> wrapper for the AlarmPopup control.
14+
/// </summary>
15+
public class AlarmPopup : WindowsElementWrapper
16+
{
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="AlarmPopup"/> class.
19+
/// </summary>
20+
/// <param name="element">
21+
/// The <see cref="WindowsElement"/> reference.
22+
/// </param>
23+
public AlarmPopup(WindowsElement element)
24+
: base(element)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Allows conversion of a <see cref="WindowsElement"/> to the <see cref="AlarmPopup"/> without direct casting.
30+
/// </summary>
31+
/// <param name="element">
32+
/// The <see cref="WindowsElement"/>.
33+
/// </param>
34+
/// <returns>
35+
/// The <see cref="DurationPicker"/>.
36+
/// </returns>
37+
public static implicit operator AlarmPopup(WindowsElement element)
38+
{
39+
return new AlarmPopup(element);
40+
}
41+
42+
/// <summary>
43+
/// Allows conversion of a <see cref="AppiumWebElement"/> to the <see cref="AlarmPopup"/> without direct casting.
44+
/// </summary>
45+
/// <param name="element">
46+
/// The <see cref="AppiumWebElement"/>.
47+
/// </param>
48+
/// <returns>
49+
/// The <see cref="AlarmPopup"/>.
50+
/// </returns>
51+
public static implicit operator AlarmPopup(AppiumWebElement element)
52+
{
53+
return new AlarmPopup(element as WindowsElement);
54+
}
55+
56+
/// <summary>
57+
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="AlarmPopup"/> without direct casting.
58+
/// </summary>
59+
/// <param name="element">
60+
/// The <see cref="AppiumWebElement"/>.
61+
/// </param>
62+
/// <returns>
63+
/// The <see cref="AlarmPopup"/>.
64+
/// </returns>
65+
public static implicit operator AlarmPopup(RemoteWebElement element)
66+
{
67+
return new AlarmPopup(element as WindowsElement);
68+
}
69+
70+
public CustomTimePicker DurationPicker => this.FindElement(ByExtensions.AutomationId("DurationPicker"));
71+
72+
public TextBox AlarmNameInput => this.FindElement(By.Name("Alarm name"));
73+
74+
public Button SaveButton => this.Element.FindElement(ByExtensions.AutomationId("PrimaryButton"));
75+
76+
public void SetTime(TimeSpan time)
77+
{
78+
this.DurationPicker.SetTime(time);
79+
}
80+
81+
public void SetName(string name)
82+
{
83+
this.AlarmNameInput.SetText(name);
84+
}
85+
86+
public void SaveAlarm()
87+
{
88+
this.SaveButton.Click();
89+
}
90+
}
91+
}

samples/WindowsAlarmsAndClock/Elements/CustomTimePicker.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ namespace WindowsAlarmsAndClock.Elements
44

55
using Legerity.Windows.Elements;
66
using Legerity.Windows.Extensions;
7-
8-
using OpenQA.Selenium;
97
using OpenQA.Selenium.Appium;
108
using OpenQA.Selenium.Appium.Windows;
9+
using OpenQA.Selenium.Remote;
1110

1211
/// <summary>
1312
/// Defines a <see cref="WindowsElement"/> wrapper for the custom TimePicker control.
1413
/// </summary>
1514
public class CustomTimePicker : WindowsElementWrapper
1615
{
17-
private readonly By hourSelectorQuery = ByExtensions.AutomationId("HourLoopingSelector");
18-
19-
private readonly By minuteSelectorQuery = ByExtensions.AutomationId("MinuteLoopingSelector");
20-
2116
/// <summary>
2217
/// Initializes a new instance of the <see cref="CustomTimePicker"/> class.
2318
/// </summary>
@@ -57,6 +52,20 @@ public static implicit operator CustomTimePicker(AppiumWebElement element)
5752
return new CustomTimePicker(element as WindowsElement);
5853
}
5954

55+
/// <summary>
56+
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="CustomTimePicker"/> without direct casting.
57+
/// </summary>
58+
/// <param name="element">
59+
/// The <see cref="AppiumWebElement"/>.
60+
/// </param>
61+
/// <returns>
62+
/// The <see cref="CustomTimePicker"/>.
63+
/// </returns>
64+
public static implicit operator CustomTimePicker(RemoteWebElement element)
65+
{
66+
return new CustomTimePicker(element as WindowsElement);
67+
}
68+
6069
/// <summary>
6170
/// Sets the time to the specified time.
6271
/// </summary>
@@ -65,8 +74,8 @@ public static implicit operator CustomTimePicker(AppiumWebElement element)
6574
/// </param>
6675
public void SetTime(TimeSpan time)
6776
{
68-
this.Element.FindElement(this.hourSelectorQuery).FindElementByName(time.ToString("%h")).Click();
69-
this.Element.FindElement(this.minuteSelectorQuery).FindElementByName(time.ToString("mm")).Click();
77+
this.Element.FindElement(ByExtensions.AutomationId("HourPicker")).FindElementByName(time.ToString("%h")).Click();
78+
this.Element.FindElement(ByExtensions.AutomationId("MinutePicker")).FindElementByName(time.ToString("mm")).Click();
7079
}
7180
}
7281
}

samples/WindowsAlarmsAndClock/Pages/AlarmPage.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ namespace WindowsAlarmsAndClock.Pages
33
using System;
44
using System.Collections.ObjectModel;
55
using System.Linq;
6-
6+
using Elements;
7+
using Legerity.Extensions;
78
using Legerity.Pages;
89
using Legerity.Windows.Extensions;
910

1011
using Microsoft.VisualStudio.TestTools.UnitTesting;
1112

1213
using OpenQA.Selenium;
1314
using OpenQA.Selenium.Appium;
15+
using OpenQA.Selenium.Remote;
1416

1517
/// <summary>
1618
/// Defines the alarm page of the Windows Alarms &amp; Clock application.
1719
/// </summary>
18-
public class AlarmPage : BasePage
20+
public class AlarmPage : AppPage
1921
{
2022
private readonly By addAlarmButton;
2123

22-
private readonly By selectAlarmsButton;
23-
2424
private readonly By alarmList;
2525

2626
/// <summary>
@@ -29,10 +29,11 @@ public class AlarmPage : BasePage
2929
public AlarmPage()
3030
{
3131
this.addAlarmButton = ByExtensions.AutomationId("AddAlarmButton");
32-
this.selectAlarmsButton = ByExtensions.AutomationId("SelectAlarmsButton");
3332
this.alarmList = ByExtensions.AutomationId("AlarmListView");
3433
}
3534

35+
public AlarmPopup AlarmPopup => this.WindowsApp.FindElement(ByExtensions.AutomationId("EditFlyout"));
36+
3637
/// <summary>
3738
/// Gets a given trait of the page to verify that the page is in view.
3839
/// </summary>
@@ -42,12 +43,12 @@ public AlarmPage()
4243
/// Navigates to adding an alarm.
4344
/// </summary>
4445
/// <returns>
45-
/// The <see cref="EditAlarmPage"/>.
46+
/// The <see cref="AlarmPage"/>.
4647
/// </returns>
47-
public EditAlarmPage GoToAddAlarm()
48+
public AlarmPage GoToAddAlarm()
4849
{
4950
this.WindowsApp.FindElement(this.addAlarmButton).Click();
50-
return new EditAlarmPage();
51+
return this;
5152
}
5253

5354
/// <summary>
@@ -57,12 +58,30 @@ public EditAlarmPage GoToAddAlarm()
5758
/// The name of the alarm to edit.
5859
/// </param>
5960
/// <returns>
60-
/// The <see cref="EditAlarmPage"/>.
61+
/// The <see cref="AlarmPage"/>.
6162
/// </returns>
62-
public EditAlarmPage GoToEditAlarm(string alarmName)
63+
public AlarmPage GoToEditAlarm(string alarmName)
6364
{
6465
this.GetListAlarmElement(alarmName).Click();
65-
return new EditAlarmPage();
66+
return this;
67+
}
68+
69+
public AlarmPage SetAlarmTime(TimeSpan time)
70+
{
71+
this.AlarmPopup.SetTime(time);
72+
return this;
73+
}
74+
75+
public AlarmPage SetAlarmName(string name)
76+
{
77+
this.AlarmPopup.SetName(name);
78+
return this;
79+
}
80+
81+
public AlarmPage SaveAlarm()
82+
{
83+
this.AlarmPopup.SaveAlarm();
84+
return this;
6685
}
6786

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

103122
return listElements.FirstOrDefault(
104-
element => element.GetAttribute("Name").Contains(name, StringComparison.CurrentCulture));
123+
element => element.GetName().Contains(name, StringComparison.CurrentCulture));
105124
}
106125
}
107126
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace WindowsAlarmsAndClock.Pages
2+
{
3+
using System;
4+
using Legerity.Pages;
5+
using Legerity.Windows.Elements.WinUI;
6+
using Legerity.Windows.Extensions;
7+
using OpenQA.Selenium;
8+
9+
public class AppPage : BasePage
10+
{
11+
public NavigationView NavigationView => this.WindowsApp.FindElement(this.Trait);
12+
13+
/// <summary>
14+
/// Gets a given trait of the page to verify that the page is in view.
15+
/// </summary>
16+
protected override By Trait => ByExtensions.AutomationId("NavView");
17+
18+
/// <summary>
19+
/// Selects a sample from the available options with the given name.
20+
/// </summary>
21+
/// <typeparam name="TPage">The type of page to return.</typeparam>
22+
/// <param name="name">The name of the sample to click.</param>
23+
/// <returns>The <see cref="TPage"/> instance.</returns>
24+
public TPage SelectPage<TPage>(string name) where TPage : BasePage
25+
{
26+
this.NavigationView.ClickMenuOption(name);
27+
return Activator.CreateInstance<TPage>();
28+
}
29+
}
30+
}

samples/WindowsAlarmsAndClock/Tests/AlarmTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void AddAlarm()
1616
const string ExpectedAlarmName = "Test Add Alarm";
1717
var expectedAlarmTime = new TimeSpan(7, 5, 0);
1818

19-
var alarmPage = new AlarmPage();
19+
AlarmPage alarmPage = new AppPage().SelectPage<AlarmPage>("Alarm");
2020

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

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

3838
// Act

samples/WindowsAlarmsAndClock/WindowsAlarmsAndClock.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<ItemGroup>
1818
<ProjectReference Include="..\..\src\Legerity.Windows\Legerity.Windows.csproj" />
19+
<ProjectReference Include="..\..\src\Legerity.WinUI\Legerity.WinUI.csproj" />
1920
</ItemGroup>
2021

2122
</Project>

0 commit comments

Comments
 (0)