Skip to content

Commit

Permalink
Features/fieldrefactoring (#91)
Browse files Browse the repository at this point in the history
Updated EasyRepro to latest version.

Workaround for #78 implemented until EasyRepro provides a fix
Workaround for #88 implemented until EasyRepro provides a fix
Fixed #89. Dialogs working again.
  • Loading branch information
mVermaat authored May 31, 2020
1 parent 8d80af9 commit 3630cd8
Show file tree
Hide file tree
Showing 30 changed files with 1,052 additions and 442 deletions.
5 changes: 5 additions & 0 deletions Deployment/Scripts/AddScreenshotsToTestResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ $resultData = Invoke-RestMethod -Uri "$baseUrl/$testRunId/results?api-version=5.
Foreach ($result in $resultData.value) {

$testName = $result.testCaseTitle.Replace(' ', '_').Replace(':','')
$comma = $testName.LastIndexOf(',')
if($comma -ne -1) {
$testName = $testName.Substring(0, $comma)
}

$search = "$testResultFolder\error_*_$($testName)_*"
Write-Host "Processing $testName. Path: $search"

Expand Down
42 changes: 19 additions & 23 deletions Vermaat.Crm.Specflow/Commands/AssertFormStateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public class AssertFormStateCommand : BrowserOnlyCommand
private readonly EntityReference _crmRecord;
private readonly Table _visibilityCriteria;

private class ExpectedFormState
{
public FormVisibility? Visible { get; set; }
public bool? Locked { get; set; }
public RequiredState? Required { get; set; }
}

public AssertFormStateCommand(CrmTestingContext crmContext, SeleniumTestingContext seleniumContext, EntityReference crmRecord, Table visibilityCriteria) :
base(crmContext, seleniumContext)
{
Expand All @@ -22,31 +29,20 @@ public AssertFormStateCommand(CrmTestingContext crmContext, SeleniumTestingConte
public override void Execute()
{
var formData = _seleniumContext.GetBrowser().OpenRecord(new OpenFormOptions(_crmRecord));
var formState = new FormState(_seleniumContext.GetBrowser().App);
List<string> errors = new List<string>();

string currentTab = null;
foreach (TableRow row in _visibilityCriteria.Rows)
{
var expectedFormState = GetExpectedFormState(row[Constants.SpecFlow.TABLE_FORMSTATE]);
var isOnForm = formData.ContainsField(row[Constants.SpecFlow.TABLE_KEY]);

if (isOnForm)
{
var field = formData[row[Constants.SpecFlow.TABLE_KEY]];
var newTab = field.GetTabName();
if (string.IsNullOrWhiteSpace(currentTab) || currentTab != newTab)
{
formData.ExpandTab(field.GetTabLabel());
currentTab = newTab;
}
}

if (isOnForm || (!expectedFormState.Locked.HasValue && !expectedFormState.Required.HasValue))
{
// Assert
AssertVisibility(formData, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Visible, errors, isOnForm);
AssertReadOnly(formData, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Locked, errors);
AssertRequirement(formData, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Required, errors);
AssertVisibility(formData, formState, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Visible, errors, isOnForm);
AssertReadOnly(formData, formState, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Locked, errors);
AssertRequirement(formData, formState, row[Constants.SpecFlow.TABLE_KEY], expectedFormState.Required, errors);
}
else
{
Expand All @@ -57,11 +53,11 @@ public override void Execute()
Assert.AreEqual(0, errors.Count, string.Join(", ", errors));
}

private FormState GetExpectedFormState(string formStateString)
private ExpectedFormState GetExpectedFormState(string formStateString)
{
var splitted = formStateString.Split(',');

FormState result = new FormState();
ExpectedFormState result = new ExpectedFormState();
foreach(string state in splitted)
{
switch(state.Trim().ToLower())
Expand All @@ -80,14 +76,14 @@ private FormState GetExpectedFormState(string formStateString)
return result;
}

private void AssertVisibility(FormData formData, string fieldName, FormVisibility? expected, List<string> errors, bool isOnForm)
private void AssertVisibility(FormData formData, FormState formState, string fieldName, FormVisibility? expected, List<string> errors, bool isOnForm)
{
if (!expected.HasValue)
return;

if(isOnForm)
{
var isVisible = formData[fieldName].IsVisible();
var isVisible = formData[fieldName].IsVisible(formState);
if (expected == FormVisibility.Visible && !isVisible)
{
errors.Add($"{fieldName} was expected to be visible but it is invisible");
Expand All @@ -107,24 +103,24 @@ private void AssertVisibility(FormData formData, string fieldName, FormVisibilit
}
}

private void AssertReadOnly(FormData formData, string fieldName, bool? locked, List<string> errors)
private void AssertReadOnly(FormData formData, FormState formState, string fieldName, bool? locked, List<string> errors)
{
if (!locked.HasValue)
return;

if (formData[fieldName].IsLocked() != locked.Value)
if (formData[fieldName].IsLocked(formState) != locked.Value)
{
errors.Add(string.Format("{0} was expected to be {1}locked but it is {2}locked",
fieldName, locked.Value ? "" : "un", locked.Value ? "un" : ""));
}
}

private void AssertRequirement(FormData formData, string fieldName, RequiredState? expectedRequiredState, List<string> errors)
private void AssertRequirement(FormData formData, FormState formState, string fieldName, RequiredState? expectedRequiredState, List<string> errors)
{
if (!expectedRequiredState.HasValue)
return;

var actualRequiredState = formData[fieldName].GetRequiredState();
var actualRequiredState = formData[fieldName].GetRequiredState(formState);
if (actualRequiredState != expectedRequiredState)
{
errors.Add($"{fieldName} was expected to be {expectedRequiredState} but it is {actualRequiredState}");
Expand Down
2 changes: 1 addition & 1 deletion Vermaat.Crm.Specflow/Commands/ClickSubgridButtonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Execute()

var browser = _seleniumContext.GetBrowser();
var record = browser.OpenRecord(new OpenFormOptions(parentRecord));
record.ExpandTab(_tabName);
browser.App.App.Entity.SelectTab(_tabName);

Logger.WriteLine($"Clicking button '{_gridButtonId} in grid {_subgridName}");
record.ClickSubgridButton(_subgridName, _gridButtonId);
Expand Down
1 change: 1 addition & 0 deletions Vermaat.Crm.Specflow/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ErrorCodes
public const int ASYNC_TIMEOUT = 34;
public const int MULTIPLE_ATTRIBUTES_FOUND = 35;
public const int APPLICATIONUSER_CANNOT_LOGIN = 36;
public const int NO_CONTROL_FOUND = 37;
}
}
}
13 changes: 13 additions & 0 deletions Vermaat.Crm.Specflow/EasyRepro/ContainerType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vermaat.Crm.Specflow.EasyRepro
{
public enum ContainerType
{
Body, Header, Dialog
}
}
174 changes: 0 additions & 174 deletions Vermaat.Crm.Specflow/EasyRepro/Field.cs

This file was deleted.

27 changes: 27 additions & 0 deletions Vermaat.Crm.Specflow/EasyRepro/FieldTypes/BooleanValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vermaat.Crm.Specflow.EasyRepro.FieldTypes
{
public class BooleanValue
{
public BooleanValue(bool? value)
{
Value = value;
}

public bool? Value { get; }

public string TextValue => Value?.ToString(CultureInfo.InvariantCulture);

public BooleanItem ToBooleanItem(string logicalName)
{
return new BooleanItem { Name = logicalName, Value = Value.GetValueOrDefault() };
}
}
}
26 changes: 26 additions & 0 deletions Vermaat.Crm.Specflow/EasyRepro/FieldTypes/DateTimeValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Xrm.Sdk.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vermaat.Crm.Specflow.EasyRepro.FieldTypes
{
public class DateTimeValue
{
public DateTimeValue(DateTimeAttributeMetadata metadata, DateTime? value)
{
if (value.HasValue && metadata.DateTimeBehavior == DateTimeBehavior.UserLocal)
{
var offset = GlobalTestingContext.ConnectionManager.CurrentConnection.UserSettings.TimeZoneInfo.GetUtcOffset(value.Value);
Value = value.Value.Add(offset);
}
else
Value = value;
}

public DateTime? Value { get; }

}
}
Loading

0 comments on commit 3630cd8

Please sign in to comment.