-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from MADE-Apps/jamesmcroft/2-appbartogglebutto…
…n-web #2 - Added AppBarToggleButton element for Windows and Web
- Loading branch information
Showing
5 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
samples/UnoSampleAppTests/Tests/AppBarToggleButtonTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace UnoSampleAppTests.Tests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Legerity; | ||
using Legerity.Uno; | ||
using Legerity.Uno.Elements; | ||
using Legerity.Uno.Extensions; | ||
using Legerity.Web; | ||
using Legerity.Windows; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
[TestFixtureSource(nameof(TestPlatformOptions))] | ||
public class AppBarToggleButtonTests : BaseTestClass | ||
{ | ||
public AppBarToggleButtonTests(AppManagerOptions options) : base(options) | ||
{ | ||
} | ||
|
||
static IEnumerable<AppManagerOptions> TestPlatformOptions => new List<AppManagerOptions> | ||
{ | ||
new WebAppManagerOptions( | ||
WebAppDriverType.Edge, | ||
Path.Combine(Environment.CurrentDirectory, "Tools\\Edge")) | ||
{ | ||
Maximize = true, Url = "http://localhost:49247", ImplicitWait = TimeSpan.FromSeconds(10) | ||
}, | ||
new WindowsAppManagerOptions("com.madeapps.unosampleapp_7mzr475ysvhxg!App") | ||
{ | ||
DriverUri = "http://127.0.0.1:4723", LaunchWinAppDriver = true, Maximize = true | ||
} | ||
}; | ||
|
||
[Test] | ||
public void SetToggleSymbolIconButtonOn() | ||
{ | ||
// Arrange | ||
AppBarToggleButton toggle = UnoAppManager.App.FindElementByAutomationId("SampleAppBarToggleButton"); | ||
|
||
// Act | ||
toggle.ToggleOn(); | ||
|
||
// Assert | ||
toggle.IsOn.ShouldBeTrue(); | ||
} | ||
|
||
[Test] | ||
public void SetToggleSymbolIconButtonOff() | ||
{ | ||
// Arrange | ||
AppBarToggleButton toggle = UnoAppManager.App.FindElementByAutomationId("SampleAppBarToggleButton"); | ||
|
||
// Act | ||
toggle.ToggleOff(); | ||
|
||
// Assert | ||
toggle.IsOn.ShouldBeFalse(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
namespace Legerity.Uno.Elements | ||
{ | ||
using System; | ||
using Legerity.Uno.Extensions; | ||
using OpenQA.Selenium.Appium.Android; | ||
using OpenQA.Selenium.Appium.iOS; | ||
using OpenQA.Selenium.Appium.Windows; | ||
using OpenQA.Selenium.Remote; | ||
|
||
/// <summary> | ||
/// Defines a <see cref="RemoteWebElement"/> wrapper for the core AppBarToggleButton control. | ||
/// </summary> | ||
public class AppBarToggleButton : AppBarButton | ||
{ | ||
private const string ToggleOffValue = "0"; | ||
|
||
private const string ToggleOnValue = "1"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AppBarToggleButton"/> class. | ||
/// </summary> | ||
/// <param name="element"> | ||
/// The <see cref="RemoteWebElement"/> reference. | ||
/// </param> | ||
public AppBarToggleButton(RemoteWebElement element) | ||
: base(element) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the toggle button is in the on position. | ||
/// </summary> | ||
public bool IsOn => this.DetermineIsOn(); | ||
|
||
/// <summary> | ||
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="AppBarToggleButton"/> without direct casting. | ||
/// </summary> | ||
/// <param name="element"> | ||
/// The <see cref="RemoteWebElement"/>. | ||
/// </param> | ||
/// <returns> | ||
/// The <see cref="AppBarToggleButton"/>. | ||
/// </returns> | ||
public static implicit operator AppBarToggleButton(RemoteWebElement element) | ||
{ | ||
return new AppBarToggleButton(element); | ||
} | ||
|
||
/// <summary> | ||
/// Toggles the button on. | ||
/// </summary> | ||
public void ToggleOn() | ||
{ | ||
if (this.IsOn) | ||
{ | ||
return; | ||
} | ||
|
||
this.Click(); | ||
} | ||
|
||
/// <summary> | ||
/// Toggles the button off. | ||
/// </summary> | ||
public void ToggleOff() | ||
{ | ||
if (!this.IsOn) | ||
{ | ||
return; | ||
} | ||
|
||
this.Click(); | ||
} | ||
|
||
private bool DetermineIsOn() | ||
{ | ||
return this.Element switch | ||
{ | ||
AndroidElement _ => | ||
throw new PlatformNotSupportedException( | ||
"An implementation for Android has not been implemented yet."), | ||
IOSElement _ => | ||
throw new PlatformNotSupportedException( | ||
"An implementation for iOS has not been implemented yet."), | ||
WindowsElement _ => | ||
this.Element.GetAttribute("Toggle.ToggleState") == ToggleOnValue, | ||
_ => | ||
this.Element.FindElementByXamlName("CheckedHighlightBackground") | ||
.GetCssValue("opacity") != ToggleOffValue | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters