Skip to content

Commit

Permalink
add Thread sleep in SimpleWebServer to let it start before trying to …
Browse files Browse the repository at this point in the history
…hit it with the browser

add bat file to update lib 
update FluentWebUITesting.dll to latest
support Set().To() for dropdownlists
  • Loading branch information
handcraftsman committed Feb 28, 2010
1 parent 467f599 commit ae186e6
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 67 deletions.
8 changes: 4 additions & 4 deletions decuit.Tests.Integration/IntegrationTestRunner.cs
Expand Up @@ -29,10 +29,10 @@ public class IntegrationTestRunner
public void Run(IEnumerable<Action<Browser>> browserActions, IEnumerable<Action<HttpMessage, ISocketProxy>> webServerResponses, string initialPage) public void Run(IEnumerable<Action<Browser>> browserActions, IEnumerable<Action<HttpMessage, ISocketProxy>> webServerResponses, string initialPage)
{ {
UITestRunner.InitializeBrowsers(x => UITestRunner.InitializeBrowsers(x =>
{ {
x.CloseBrowserAfterEachTest = true; x.CloseBrowserAfterEachTest = true;
x.UseInternetExplorer = true; x.UseInternetExplorer = true;
}); });


var webServer = new SimpleWebServer(webServerResponses); var webServer = new SimpleWebServer(webServerResponses);
try try
Expand Down
15 changes: 15 additions & 0 deletions decuit.Tests.Integration/Pages/SetDropDownList.html
@@ -0,0 +1,15 @@
<html>
<body>

<label>Label without for</label>
<label for="missing">Label with incorrect for</label>

<label for="ddlState">State</label>
<select id="ddlState">
<option value="">(Select)</option>
<option value="NM">New Mexico</option>
<option value="TX">Texas</option>
</select>

</body>
</html>
3 changes: 3 additions & 0 deletions decuit.Tests.Integration/Pages/SetTextBox.html
@@ -1,6 +1,9 @@
<html> <html>
<body> <body>


<label>Label without for</label>
<label for="missing">Label with incorrect for</label>

<label for="txtFirstName">First Name</label> <label for="txtFirstName">First Name</label>
<input type="text" id="txtFirstName" /> <input type="text" id="txtFirstName" />


Expand Down

This file was deleted.

This file was deleted.

125 changes: 125 additions & 0 deletions decuit.Tests.Integration/SetTests_DropDownList.cs
@@ -0,0 +1,125 @@
// Copyright 2010 Clinton Sheppard <sheppard@cs.unm.edu>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using FluentAssert;

using FluentWebUITesting;
using FluentWebUITesting.Extensions;

using gar3t.decuit;

using NUnit.Framework;

namespace decuit.Tests.Integration
{
public partial class SetTests
{
[TestFixture]
public class When_asked_to_Set_the_value_of_a_DropDownList
{
private const string Expected = "Texas";
private const string LabelText = "State";
private const string PageName = "SetDropDownList.html";

[Test]
public void Should_fail_if_the_drop_down_does_not_have_a_matching_option_by_text_or_value()
{
const string badOption = "Ontario";
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(LabelText).To(badOption)
);

var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName));

exception.Message.Contains(badOption).ShouldBeTrue();
}

[Test]
public void Should_fail_if_the_label_text_does_not_exist()
{
const string textOfBadLabel = "Country";
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(textOfBadLabel).To(Expected)
);

var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName));
exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
}

[Test]
public void Should_fail_if_the_matching_label_does_not_have_a_For_attribute()
{
const string textOfBadLabel = "Label without for";
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(textOfBadLabel).To(Expected)
);

var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName));
exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
}

[Test]
public void Should_fail_if_the_matching_labels_For_attribute_refers_to_a_missing_control()
{
const string textOfBadLabel = "Label with incorrect for";
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(textOfBadLabel).To(Expected)
);

var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName));
exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
}

[Test]
public void Should_succeed_if_drop_down_has_an_option_with_matching_text()
{
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(LabelText).To(Expected),
b => b.DropDownListWithId("ddlState").GetSelectedText().ShouldBeEqualTo(Expected)
);

new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName);
}

[Test]
public void Should_succeed_if_drop_down_has_an_option_with_matching_value()
{
var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set(LabelText).To("NM"),
b => b.DropDownListWithId("ddlState").GetSelectedText().ShouldBeEqualTo("New Mexico")
);

new IntegrationTestRunner().Run(
browserActions,
SimpleWebServer.InitializeServerResponsesContainer(),
PageName);
}
}
}
}
Expand Up @@ -15,71 +15,80 @@
using FluentAssert; using FluentAssert;


using FluentWebUITesting; using FluentWebUITesting;
using FluentWebUITesting.Extensions;


using gar3t.decuit; using gar3t.decuit;


using NUnit.Framework; using NUnit.Framework;


namespace decuit.Tests.Integration namespace decuit.Tests.Integration
{ {
public class SetTests public partial class SetTests
{ {
[TestFixture] [TestFixture]
public class When_asked_to_Set_the_value_of_a_TextBox public class When_asked_to_Set_the_value_of_a_TextBox
{ {
private const string Expected = "James";
private const string LabelText = "First Name";
private const string PageName = "SetTextBox.html";

[Test] [Test]
public void Should_fail_if_the_label_text_does_not_exist() public void Should_fail_if_the_label_text_does_not_exist()
{ {
const string textOfBadLabel = "Last Name";
var browserActions = UITestRunner.InitializeWorkFlowContainer( var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set("Last Name").To("James") b => b.Set(textOfBadLabel).To(Expected)
); );


var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run( var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions, browserActions,
SimpleWebServer.InitializeServerResponsesContainer(), SimpleWebServer.InitializeServerResponsesContainer(),
"SetTextBox.html")); PageName));
exception.Message.Contains("Last Name").ShouldBeTrue(); exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
} }


[Test] [Test]
public void Should_fail_if_the_matching_label_does_not_have_a_For_attribute() public void Should_fail_if_the_matching_label_does_not_have_a_For_attribute()
{ {
const string textOfBadLabel = "Label without for";
var browserActions = UITestRunner.InitializeWorkFlowContainer( var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set("Last Name").To("James") b => b.Set(textOfBadLabel).To(Expected)
); );


var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run( var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions, browserActions,
SimpleWebServer.InitializeServerResponsesContainer(), SimpleWebServer.InitializeServerResponsesContainer(),
"SetTextbox_LabelWithoutFor.html")); PageName));
exception.Message.Contains("Last Name").ShouldBeTrue(); exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
} }


[Test] [Test]
public void Should_fail_if_the_matching_labels_For_attribute_refers_to_a_missing_control() public void Should_fail_if_the_matching_labels_For_attribute_refers_to_a_missing_control()
{ {
const string textOfBadLabel = "Label with incorrect for";
var browserActions = UITestRunner.InitializeWorkFlowContainer( var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set("Last Name").To("James") b => b.Set(textOfBadLabel).To(Expected)
); );


var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run( var exception = Assert.Throws<AssertionException>(() => new IntegrationTestRunner().Run(
browserActions, browserActions,
SimpleWebServer.InitializeServerResponsesContainer(), SimpleWebServer.InitializeServerResponsesContainer(),
"SetTextbox_LabelWithForPointedToMissingControl.html")); PageName));
exception.Message.Contains("Last Name").ShouldBeTrue(); exception.Message.Contains(textOfBadLabel).ShouldBeTrue();
} }


[Test] [Test]
public void Should_succeed_if_the_label_text_and_for_attribute_match() public void Should_succeed_if_the_label_text_and_for_attribute_match()
{ {
var browserActions = UITestRunner.InitializeWorkFlowContainer( var browserActions = UITestRunner.InitializeWorkFlowContainer(
b => b.Set("First Name").To("James") b => b.Set(LabelText).To(Expected),
b => b.TextBoxWithId("txtFirstName").Text().ShouldBeEqualTo(Expected)
); );


new IntegrationTestRunner().Run( new IntegrationTestRunner().Run(
browserActions, browserActions,
SimpleWebServer.InitializeServerResponsesContainer(), SimpleWebServer.InitializeServerResponsesContainer(),
"SetTextBox.html"); PageName);
} }
} }
} }
Expand Down
2 changes: 2 additions & 0 deletions decuit.Tests.Integration/SimpleWebServer.cs
Expand Up @@ -17,6 +17,7 @@
using System.Linq; using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading;


using gar3t.Common; using gar3t.Common;
using gar3t.Common.Extensions; using gar3t.Common.Extensions;
Expand Down Expand Up @@ -74,6 +75,7 @@ public void Run()
_stepIndex = 0; _stepIndex = 0;
_tcp = new Tcp(); _tcp = new Tcp();
_tcp.Listen(Port, ProcessClientRequest); _tcp.Listen(Port, ProcessClientRequest);
Thread.Sleep(100); // let server start
} }


public void Stop() public void Stop()
Expand Down
8 changes: 3 additions & 5 deletions decuit.Tests.Integration/decuit.Tests.Integration.csproj
Expand Up @@ -69,10 +69,11 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="SetTests_DropDownList.cs" />
<Compile Include="InsufficientHttpMessageHandlingStepsException.cs" /> <Compile Include="InsufficientHttpMessageHandlingStepsException.cs" />
<EmbeddedResource Include="Pages\SetTextBox.html" /> <EmbeddedResource Include="Pages\SetTextBox.html" />
<Compile Include="IntegrationTestRunner.cs" /> <Compile Include="IntegrationTestRunner.cs" />
<Compile Include="SetTests.cs" /> <Compile Include="SetTests_TextBox.cs" />
<Compile Include="SimpleWebServer.cs" /> <Compile Include="SimpleWebServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
Expand All @@ -83,10 +84,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Pages\SetTextbox_LabelWithoutFor.html" /> <EmbeddedResource Include="Pages\SetDropDownList.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\SetTextbox_LabelWithForPointedToMissingControl.html" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit ae186e6

Please sign in to comment.