-
Notifications
You must be signed in to change notification settings - Fork 20
/
ValidationElementHandlerFixture.cs
63 lines (56 loc) · 2.93 KB
/
ValidationElementHandlerFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Diagnostics;
using FubuCore;
using FubuMVC.Validation.Serenity;
using FubuMVC.Validation.StoryTeller.Endpoints.ValidationElementHandler;
using OpenQA.Selenium;
using Serenity.Fixtures;
using Serenity.Fixtures.Handlers;
using StoryTeller.Assertions;
using StoryTeller.Engine;
namespace FubuMVC.Validation.StoryTeller.Fixtures
{
public class ValidationElementHandlerFixture : ScreenFixture<ElementHandler>
{
public ValidationElementHandlerFixture()
{
Title = "The ValidationElementHandler test screen";
EditableElementsForAllImmediateProperties();
}
protected override void beforeRunning()
{
Navigation.NavigateTo(new ElementHandler());
}
[FormatAs("The validation element handler {name} matches {matches}")]
public bool ValidationElementHandlerMatches(string name, [SelectionValues("true", "false")] bool matches)
{
var element = Driver.FindElement(By.CssSelector("input[name=\"{0}\"]".ToFormat(name)));
var actualMatches = ElementHandlers.FindHandler(element) is ValidationElementHandler;
return actualMatches == matches;
}
[FormatAs("Entering text into validation field {name} waits at least {min} milliseconds but not more than {max} milliseconds for validation to complete")]
public void ValidationElementHandlerEnterDataWithWait(string name, int min, int max)
{
var element = Driver.FindElement(By.CssSelector("input[name=\"{0}\"]".ToFormat(name)));
var stopwatch = Stopwatch.StartNew();
ElementHandlers.FindHandler(element).EnterData(Driver, element, "Some text");
stopwatch.Stop();
StoryTellerAssert.Fail(stopwatch.ElapsedMilliseconds < min, "Handler was faster than expected actual elapsed milliseconds {0}".ToFormat(stopwatch.ElapsedMilliseconds));
StoryTellerAssert.Fail(stopwatch.ElapsedMilliseconds > max, "Handler was slower than expected actual elapsed milliseconds {0}".ToFormat(stopwatch.ElapsedMilliseconds));
}
[FormatAs("Entering text into validation field {name} waits so long that it times out and fails")]
public void ValidationElementHandlerEnterDataWithWaitFailsWithTimeout(string name)
{
try
{
var element = Driver.FindElement(By.CssSelector("input[name=\"{0}\"]".ToFormat(name)));
ElementHandlers.FindHandler(element).EnterData(Driver, element, "Some text");
}
catch (StorytellerAssertionException ex)
{
StoryTellerAssert.Fail(!ex.Message.Contains("took longer than expected"), "Failed to enter data for some reason other than a timeout") ;
return;
}
StoryTellerAssert.Fail("Did not timeout when waiting for validation (For some reason this will fail on the Storyteller UI but not in the st runner)");
}
}
}