Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Added UI Test for manual test G5 #18622

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/Controls/samples/Controls.Sample.UITests/IssueAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ namespace Maui.Controls.Sample
AllowMultiple = true)]
public class IssueAttribute : Attribute
{
//bool _modal;

public IssueAttribute(IssueTracker issueTracker, int issueNumber, string description,
NavigationBehavior navigationBehavior = NavigationBehavior.Default, int issueTestNumber = 0)
{
IssueTracker = issueTracker;
IssueNumber = issueNumber.ToString();
Description = description;
PlatformsAffected = PlatformAffected.Default;
NavigationBehavior = navigationBehavior;
IssueTestNumber = issueTestNumber;
}

public IssueAttribute(IssueTracker issueTracker, string issueNumber, string description,
NavigationBehavior navigationBehavior = NavigationBehavior.Default, int issueTestNumber = 0)
{
IssueTracker = issueTracker;
IssueNumber = issueNumber;
Expand All @@ -24,6 +33,18 @@ public class IssueAttribute : Attribute
public IssueAttribute(IssueTracker issueTracker, int issueNumber, string description,
PlatformAffected platformsAffected, NavigationBehavior navigationBehavior = NavigationBehavior.Default,
int issueTestNumber = 0)
{
IssueTracker = issueTracker;
IssueNumber = issueNumber.ToString();
Description = description;
PlatformsAffected = platformsAffected;
NavigationBehavior = navigationBehavior;
IssueTestNumber = issueTestNumber;
}

public IssueAttribute(IssueTracker issueTracker, string issueNumber, string description,
PlatformAffected platformsAffected, NavigationBehavior navigationBehavior = NavigationBehavior.Default,
int issueTestNumber = 0)
{
IssueTracker = issueTracker;
IssueNumber = issueNumber;
Expand All @@ -35,7 +56,7 @@ public class IssueAttribute : Attribute

public IssueTracker IssueTracker { get; }

public int IssueNumber { get; }
public string IssueNumber { get; }

public int IssueTestNumber { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum IssueTracker
{
Github,
Bugzilla,
ManualTest,
None
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue18617">
<VerticalStackLayout>
<Label
AutomationId="WaitForStubControl"
Text="1. Press the 'On' button." />
<Label
Text="2. The test fails if the 'On' button is still enabled or the 'Off' button is not enabled." />
<Label
Text="3. Press the 'Off' button." />
<Label
Text="4. The test fails if the 'Off' button is still enabled or the 'On' button is not enabled." />
<Label
Text="5. Repeat the steps above 2 more times." />
<Button
AutomationId="OnButton"
Command="{Binding OnCommand}"
Text="On" />
<Button
AutomationId="OffButton"
Command="{Binding OffCommand}"
Text="Off" />
<Label
AutomationId="StatusLabel"
Text="{Binding Status}"/>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.ManualTest, "G5", "Button Command CanExecute can disable the control", PlatformAffected.All)]
public partial class Issue18617 : ContentPage
{
string _status;

public Issue18617()
{
InitializeComponent();

OnCommand = new Command(execute: HandleCommand, canExecute: () => !Toggle);
OffCommand = new Command(execute: HandleCommand, canExecute: () => Toggle);

BindingContext = this;
}

void HandleCommand()
{
Toggle = !Toggle;
Status = !Toggle ? "OnButton enabled OffButton disabled" : "OnButton disabled OffButton enabled";

((Command)OnCommand).ChangeCanExecute();
((Command)OffCommand).ChangeCanExecute();
}

public bool Toggle { get; set; } = false;

public ICommand OnCommand { get; set; }

public ICommand OffCommand { get; set; }

public string Status
{
get { return _status; }
set
{
_status = value;
OnPropertyChanged();
}
}
}
}
28 changes: 24 additions & 4 deletions src/Controls/samples/Controls.Sample.UITests/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TestCaseScreen : TableView
bool _filterBugzilla;
bool _filterNone;
bool _filterGitHub;
bool _filterManual;
string _filter;

static TextCell MakeIssueCell(string text, string detail, Action tapped)
Expand Down Expand Up @@ -107,7 +108,7 @@ Page ActivatePage(Type type)
class IssueModel
{
public IssueTracker IssueTracker { get; set; }
public int IssueNumber { get; set; }
public string IssueNumber { get; set; }
public int IssueTestNumber { get; set; }
public string Name { get; set; }
public string Description { get; set; }
Expand Down Expand Up @@ -196,6 +197,9 @@ public void FilterTracker(IssueTracker tracker)
case IssueTracker.Bugzilla:
_filterBugzilla = !_filterBugzilla;
break;
case IssueTracker.ManualTest:
_filterManual = !_filterManual;
break;
case IssueTracker.None:
_filterNone = !_filterNone;
break;
Expand Down Expand Up @@ -253,6 +257,17 @@ public async void FilterIssues(string filter = null)
issueCells = issueCells.Concat(githubIssueCells);
}

if (!_filterManual)
{
var manualIssueCells =
from issueModel in _issues
where issueModel.IssueTracker == IssueTracker.ManualTest && issueModel.Matches(filter)
orderby issueModel.IssueNumber descending
select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action);

issueCells = issueCells.Concat(manualIssueCells);
}

if (!_filterNone)
{
var untrackedIssueCells =
Expand Down Expand Up @@ -373,17 +388,22 @@ static Layout CreateTrackerFilter(TestCaseScreen testCaseScreen)
};

var bzSwitch = new Switch { IsToggled = true };
trackerFilterLayout.Children.Add(new Label { Text = "Bugzilla" });
trackerFilterLayout.Children.Add(new Label { Text = "Bugzilla", VerticalOptions = LayoutOptions.Center });
trackerFilterLayout.Children.Add(bzSwitch);
bzSwitch.Toggled += (sender, args) => testCaseScreen.FilterTracker(IssueTracker.Bugzilla);

var ghSwitch = new Switch { IsToggled = true };
trackerFilterLayout.Children.Add(new Label { Text = "GitHub" });
trackerFilterLayout.Children.Add(new Label { Text = "GitHub", VerticalOptions = LayoutOptions.Center });
trackerFilterLayout.Children.Add(ghSwitch);
ghSwitch.Toggled += (sender, args) => testCaseScreen.FilterTracker(IssueTracker.Github);

var manualSwitch = new Switch { IsToggled = true };
trackerFilterLayout.Children.Add(new Label { Text = "Manual", VerticalOptions = LayoutOptions.Center });
trackerFilterLayout.Children.Add(manualSwitch);
manualSwitch.Toggled += (sender, args) => testCaseScreen.FilterTracker(IssueTracker.ManualTest);

var noneSwitch = new Switch { IsToggled = true };
trackerFilterLayout.Children.Add(new Label { Text = "None" });
trackerFilterLayout.Children.Add(new Label { Text = "None", VerticalOptions = LayoutOptions.Center });
trackerFilterLayout.Children.Add(noneSwitch);
noneSwitch.Toggled += (sender, args) => testCaseScreen.FilterTracker(IssueTracker.None);

Expand Down
37 changes: 37 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue18617.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue18617 : _IssuesUITest
{
public Issue18617(TestDevice device)
: base(device)
{ }

public override string Issue => "Button Command CanExecute can disable the control";

[Test]
public void CommandCanExecuteDisableButton()
{
App.WaitForElement("WaitForStubControl");

// 1. Press the 'On' button.
App.Click("OnButton");

// 2. The test fails if the 'On' button is still enabled or the 'Off' button is not enabled.
var status1 = App.FindElement("StatusLabel").GetText();
Assert.AreEqual("OnButton disabled OffButton enabled", status1);

// 3.Press the 'Off' button.
App.Click("OffButton");

// 4. The test fails if the 'Off' button is still enabled or the 'On' button is not enabled.
var status2 = App.FindElement("StatusLabel").GetText();
Assert.AreEqual("OnButton enabled OffButton disabled", status2);

// NOTE: We do not verify snapshots because we already did it in G1.
}
}
}