Skip to content

Commit

Permalink
test: full test coverage (#55)
Browse files Browse the repository at this point in the history
Also included:

- Migrated to SDK-style project and PackageReferences
- A number fixes in order to bring the test pass rate up to 100%
- CI pipeline changes to rerun flaky tests
  • Loading branch information
ewingjm authored Jan 4, 2021
1 parent 5272ee1 commit c8dc3f0
Show file tree
Hide file tree
Showing 149 changed files with 13,350 additions and 761 deletions.
4 changes: 2 additions & 2 deletions bindings/Capgemini.PowerApps.SpecFlowBindings.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1BA90815-A570-44B9-96C8-1D087FF8A060}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capgemini.PowerApps.SpecFlowBindings", "src\Capgemini.PowerApps.SpecFlowBindings\Capgemini.PowerApps.SpecFlowBindings.csproj", "{88DD21C5-5EE8-4023-847E-2A87E434AD22}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capgemini.PowerApps.SpecFlowBindings", "src\Capgemini.PowerApps.SpecFlowBindings\Capgemini.PowerApps.SpecFlowBindings.csproj", "{88DD21C5-5EE8-4023-847E-2A87E434AD22}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8F8FAAAA-5C66-4ECC-BC4A-1127C1E7FFC8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capgemini.PowerApps.SpecFlowBindings.UiTests", "tests\Capgemini.PowerApps.SpecFlowBindings.UiTests\Capgemini.PowerApps.SpecFlowBindings.UiTests.csproj", "{EFDA0239-5116-4DFA-90AA-644DD7509017}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capgemini.PowerApps.SpecFlowBindings.UiTests", "tests\Capgemini.PowerApps.SpecFlowBindings.UiTests\Capgemini.PowerApps.SpecFlowBindings.UiTests.csproj", "{EFDA0239-5116-4DFA-90AA-644DD7509017}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FileDataRepository : ITestDataRepository
/// <inheritdoc cref="ITestDataRepository"/>
public string GetTestData(string identifier)
{
return File.ReadAllText(Path.Combine(RootDirectory, FileDirectory, Path.HasExtension(identifier) ? identifier : $"{identifier}.json"));
return File.ReadAllText(Path.Combine(RootDirectory, FileDirectory, Path.GetExtension(identifier) == ".json" ? identifier : $"{identifier}.json"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static void TestCleanup()
{
TestDriver.DeleteTestData();
}
catch (WebDriverException)
{
// Ignore - tests might have failed before driver was initialised.
}
finally
{
Quit();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public static void ThenICanSeeAValueOfInTheOptionSetFieldOnTheBusinessProcessFlo
/// <param name="expectedValue">The expected value.</param>
/// <param name="field">The field name.</param>
[Then("I can see a value of '(true|false)' in the '(.*)' boolean field on the business process flow")]
public static void ThenICanSeeAValueOfInTheBooleanFieldOnTheBusinessProcessFlow(bool expectedValue, string field)
public static void ThenICanSeeAValueOfInTheBooleanFieldOnTheBusinessProcessFlow(bool expectedValue, BooleanItem field)
{
bool.Parse(XrmApp.BusinessProcessFlow.GetValue(field)).Should().Be(expectedValue);
XrmApp.BusinessProcessFlow.GetValue(field).Should().Be(expectedValue);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Capgemini.PowerApps.SpecFlowBindings.Extensions;
using FluentAssertions;
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using Microsoft.Dynamics365.UIAutomation.Api.UCI.DTO;
using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using TechTalk.SpecFlow;
Expand Down Expand Up @@ -99,7 +100,7 @@ public static void WhenIClearTheField(string field)
}

/// <summary>
/// Clears the value for the optionset field.
/// Clears the value for the option set field.
/// </summary>
/// <param name="field">The field.</param>
[When(@"I clear the '(.*)' optionset field")]
Expand All @@ -108,6 +109,16 @@ public static void WhenIClearTheOptionSetField(OptionSet field)
XrmApp.Entity.ClearValue(field);
}

/// <summary>
/// Clears the value for the multi-select option set field.
/// </summary>
/// <param name="field">The field.</param>
[When(@"I clear the '(.*)' multioptionset field")]
public static void WhenIClearTheOptionSetField(MultiValueOptionSet field)
{
XrmApp.Entity.ClearValue(field);
}

/// <summary>
/// Clears the value for the boolean field.
/// </summary>
Expand Down Expand Up @@ -181,7 +192,14 @@ public static void WhenISelectLookup(string fieldName)
[When(@"I save the record")]
public static void WhenISaveTheRecord()
{
XrmApp.Entity.Save();
try
{
XrmApp.Entity.Save();
}
catch (InvalidOperationException)
{
// Ignore business process errors on save to allow assertions against these if required.
}
}

/// <summary>
Expand Down Expand Up @@ -230,14 +248,25 @@ public static void ThenICanSeeAValueOfInTheOptionSetField(string expectedValue,
actualValue.Should().Be(expectedValue);
}

/// <summary>
/// Asserts that a value is shown in a multi-select option set field.
/// </summary>
/// <param name="expectedValue">The expected value.</param>
/// <param name="field">The field name.</param>
[Then("I can see a value of '(.*)' in the '(.*)' multioptionset field")]
public static void ThenICanSeeAValueOfInTheOptionSetField(string[] expectedValue, MultiValueOptionSet field)
{
XrmApp.Entity.GetValue(field).Values.Should().Equal(expectedValue);
}

/// <summary>
/// Asserts that a value is shown in a lookup field.
/// </summary>
/// <param name="expectedValue">The expected value.</param>
/// <param name="field">The field name.</param>
/// <param name="fieldLocation">Where the field is located.</param>
[Then("I can see a value of '(.*)' in the '(.*)' lookup (field|header field)")]
public static void ThenICanSeeAValueOfInTheOptionSetField(string expectedValue, LookupItem field, string fieldLocation)
public static void ThenICanSeeAValueOfInTheLookupField(string expectedValue, LookupItem field, string fieldLocation)
{
string actualValue = fieldLocation == "field" ? XrmApp.Entity.GetValue(field) : XrmApp.Entity.GetHeaderValue(field);
actualValue.Should().Be(expectedValue);
Expand Down Expand Up @@ -278,8 +307,8 @@ public static void ThenICanSeeAValueOfInTheBooleanField(bool expectedValue, Bool
/// <param name="expectedValue">The expected value.</param>
/// <param name="field">The field name.</param>
/// <param name="fieldLocation">Where the field is located.</param>
[Then(@"I can see a value of '((?:0?[1-9]|[12][0-9]|3[01])[\/\-](?:0?[1-9]|1[012])[\/\-]\d{4}(?: \d{1,2}[:-]\d{2}(?:[:-]\d{2,3})*)?)' in the '(.*)' datetime (field|header field)")]
public static void ThenICanSeeAValueOfInTheDateTimeField(DateTime expectedValue, DateTimeControl field, string fieldLocation)
[Then(@"I can see a value of '(.*)' in the '(.*)' datetime (field|header field)")]
public static void ThenICanSeeAValueOfInTheDateTimeField(DateTime? expectedValue, DateTimeControl field, string fieldLocation)
{
var actualValue = fieldLocation == "field" ? XrmApp.Entity.GetValue(field) : XrmApp.Entity.GetHeaderValue(field);
actualValue.Should().Be(expectedValue);
Expand Down Expand Up @@ -308,13 +337,33 @@ public static void ThenIAmPresentedWithANewFormForTheEntity(string formName, str
}

/// <summary>
/// Asserts that a form notification can be seen with the given message.
/// Asserts that an info form notification can be seen with the given message.
/// </summary>
/// <param name="message">The message of the notification.</param>
[Then(@"I can see an info form notification stating '(.*)'")]
public static void ThenICanSeeAnInfoFormNotificationStating(string message)
{
XrmApp.Entity.GetFormNotifications().Should().Contain(formNotification => formNotification.Type == FormNotificationType.Information && formNotification.Message == message);
}

/// <summary>
/// Asserts that a warning form notification can be seen with the given message.
/// </summary>
/// <param name="message">The message of the notification.</param>
[Then(@"I can see a warning form notification stating '(.*)'")]
public static void ThenICanSeeAWarningFormNotificationStating(string message)
{
XrmApp.Entity.GetFormNotifications().Should().Contain(formNotification => formNotification.Type == FormNotificationType.Warning && formNotification.Message == message);
}

/// <summary>
/// Asserts that an error form notification can be seen with the given message.
/// </summary>
/// <param name="message">The message of the notification.</param>
[Then(@"I can see a form notification stating '(.*)'")]
public static void ThenICanSeeAFormNotificationStating(string message)
[Then(@"I can see an error form notification stating '(.*)'")]
public static void ThenICanSeeAnErrorFormNotificationStating(string message)
{
XrmApp.Entity.GetFormNotifications().Should().Contain(message);
XrmApp.Entity.GetFormNotifications().Should().Contain(formNotification => formNotification.Type == FormNotificationType.Error && formNotification.Message == message);
}

/// <summary>
Expand Down Expand Up @@ -447,6 +496,18 @@ private static void SetFieldValue(string fieldName, string fieldValue, string fi
{
switch (fieldType)
{
case "multioptionset":
XrmApp.Entity.SetValue(
new MultiValueOptionSet()
{
Name = fieldName,
Values = fieldValue
.Split(',')
.Select(v => v.Trim())
.ToArray(),
},
true);
break;
case "optionset":
XrmApp.Entity.SetValue(new OptionSet()
{
Expand Down Expand Up @@ -487,19 +548,6 @@ private static void SetHeaderFieldValue(string fieldName, string fieldValue, str
{
switch (fieldType)
{
case "multioptionset":
XrmApp.Entity.SetMultiSelectOptionSetValue(
Driver,
new MultiValueOptionSet()
{
Name = fieldName,
Values = fieldValue
.Split(',')
.Select(v => v.Trim())
.ToArray(),
},
true);
break;
case "optionset":
XrmApp.Entity.SetHeaderValue(new OptionSet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static void ThenTheSubgridContainsRecordsWithTheFollowingInTheLookup(stri
/// <param name="subGridName">The name of the subgrid.</param>
/// <param name="fieldValue">The expected value of the field.</param>
/// <param name="fieldName">The name of the field.</param>
[Then(@"the '(.*)' subgrid contains a record with '(.*)' in the '(.*)' (?:text|numeric|currency|lookup|datetime|optionset) field")]
[Then(@"the '(.*)' subgrid contains a record with '(.*)' in the '(.*)' (?:text|numeric|currency|lookup|datetime|optionset|multioptionset|boolean) field")]
public static void ThenTheSubgridContainsRecordsWithInTheField(string subGridName, string fieldValue, string fieldName)
{
XrmApp.Entity.SubGrid
Expand Down Expand Up @@ -245,12 +245,10 @@ public static void WhenIClickTheFlyoutOnTheSubgrid(string flyoutName, string sub
[Then(@"I can not see the '(.*)' command on the '(.*)' subgrid")]
public static void ThenICanNotSeeTheCommandOnTheSubgrid(string commandName, string subGridName)
{
Driver
.Invoking(d => d.WaitUntilVisible(
Driver.WaitUntilVisible(
By.CssSelector($"div#dataSetRoot_{subGridName} button[aria-label=\"{commandName}\"]"),
new TimeSpan(0, 0, 5)))
.Should()
.Throw<Exception>();
new TimeSpan(0, 0, 5))
.Should().BeNull();
}

/// <summary>
Expand All @@ -261,8 +259,8 @@ public static void ThenICanNotSeeTheCommandOnTheSubgrid(string commandName, stri
public static void ThenICanSeeTheCommandOnTheFlyoutOfTheSubgrid(string commandName)
{
Driver.WaitUntilVisible(
By.CssSelector($"div[data-id*=\"flyoutRootNode\"] button[aria-label='{commandName}']"),
new TimeSpan(0, 0, 1),
By.CssSelector($"#__flyoutRootNode button[aria-label$='{commandName}']"),
new TimeSpan(0, 0, 10),
$"Could not find the {commandName} command on the flyout of the subgrid.");
}

Expand All @@ -275,7 +273,7 @@ public static void ThenICanNotSeeTheCommandOnTheFlyoutOfTheSubgrid(string comman
{
Driver
.Invoking(d => d.WaitUntilVisible(
By.CssSelector($"div[data-id*=\"flyoutRootNode\"] button[aria-label=\"{commandName}\"]"),
By.CssSelector($"#__flyoutRootNode button[aria-label$=\"{commandName}\"]"),
new TimeSpan(0, 0, 1),
$"Could not find the {commandName} command on the flyout of the subgrid."))
.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,7 @@ public static void WhenISearchForInTheLookup(string searchCriteria, LookupItem c
input.Click();
input.SendKeys(searchCriteria);
input.SendKeys(Keys.Enter);
}

/// <summary>
/// Changes the view in the lookup field away from the default view.
/// </summary>
/// <param name="viewName">The name of the view to switch to.</param>
[When(@"I select the '(.*)' view in the lookup")]
public static void WhenISwitchLookupView(string viewName)
{
// TODO: When bug is resolved revert back to XrmApp.Lookup.SwitchView(viewName); : https://github.com/microsoft/EasyRepro/issues/948.

// XrmApp.Lookup.SwitchView(viewName);
Driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Lookup.ChangeViewButton])).Click(true);
Driver.WaitUntilAvailable(By.XPath("//li[contains(@role,'treeitem') and contains(@class,'bu')]"));
Driver.WaitUntilAvailable(By.CssSelector($"li[aria-label='{viewName}']")).Click();
Driver.WaitForTransaction();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Capgemini.PowerApps.SpecFlowBindings.Steps
{
using FluentAssertions;
using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using TechTalk.SpecFlow;

/// <summary>
Expand Down Expand Up @@ -67,5 +70,46 @@ public static void WhenISignOut()
{
XrmApp.Navigation.SignOut();
}

/// <summary>
/// Gets the area.
/// </summary>
/// <param name="area">The area name.</param>
[Then(@"I see the '(.*)' area")]
public static void ThenICanSeeTheArea(string area)
{
Driver
.WaitUntilAvailable(By.Id("areaSwitcherContainer"))
.Text
.Should().Contain(area);
}

/// <summary>
/// Gets the sub-area.
/// </summary>
/// <param name="subArea">The area name.</param>
[Then(@"I see the '(.*)' subarea")]
public static void ThenICanSeeTheSubArea(string subArea)
{
Driver
.WaitUntilAvailable(By.XPath($"//img[@title='{subArea}']"))
.Text
.Should().NotBeNull();
}

/// <summary>
/// Gets the sub-area.
/// </summary>
/// <param name="groupName">The group.</param>
[Then(@"I see the '(.*)' group")]
public static void ThenICanSeeTheGroup(string groupName)
{
var groupNameWithoutWhitespace = groupName?.Replace(" ", string.Empty);

Driver
.WaitUntilAvailable(By.XPath($"//span[@data-id='sitemap-sitemapAreaGroup-{groupNameWithoutWhitespace}']"))
.Text
.Should().Contain(groupName);
}
}
}
Loading

0 comments on commit c8dc3f0

Please sign in to comment.