Skip to content

Commit 93ebd94

Browse files
committed
Merge branch 'release/0.3.3' into production
2 parents 3b3548c + 4150ec8 commit 93ebd94

30 files changed

Lines changed: 721 additions & 65 deletions

CSF.WebDriverExtras.Tests/Flags/BrowserIdentificationFactoryTests.cs renamed to CSF.WebDriverExtras.Tests/BrowserId/BrowserIdentificationFactoryTests.cs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
2-
using CSF.WebDriverExtras.Flags;
2+
using CSF.WebDriverExtras;
3+
using CSF.WebDriverExtras.BrowserId;
34
using NUnit.Framework;
45
using OpenQA.Selenium;
56
using Moq;
7+
using System.Collections.Generic;
8+
using OpenQA.Selenium.Remote;
69

7-
namespace CSF.WebDriverExtras.Tests.Flags
10+
namespace CSF.WebDriverExtras.Tests.BrowserId
811
{
912
[TestFixture,Parallelizable(ParallelScope.All)]
1013
public class BrowserIdentificationFactoryTests
@@ -118,5 +121,95 @@ public void GetIdentification_integration_test_gets_correct_platform_name(IHasCa
118121
// Assert
119122
Assert.That(result.Platform, Is.EqualTo(platformType.ToString()));
120123
}
124+
125+
/// <summary>
126+
/// Integration test which uses a real Web Driver to verify that every supported web driver may be identified.
127+
/// </summary>
128+
/// <remarks>
129+
/// <para>
130+
/// This test method (and the many scenarios it executes) connects to a Remote Web Driver (usually Sauce Labs)
131+
/// and spins up a browser instance, then gets its identification, sends the browser a single simple command
132+
/// and then closes the web driver.
133+
/// </para>
134+
/// <para>
135+
/// The single command sent is required, because Sauce Labs (but perhaps other remote web driver providers) counts
136+
/// the test as an error if no commands are sent. The command itself is not important.
137+
/// </para>
138+
/// <para>
139+
/// In regular operation this test is not required though. The things that it verifies are covered by the test
140+
/// <see cref="VersionFactoryTests.CreateVersion_can_create_versions_for_all_supported_browsers"/>, because
141+
/// the information from this test has been collected and compiled into this assembly.
142+
/// </para>
143+
/// <para>
144+
/// The only reason for wanting to run THIS scenario again would be to detect newly-released browser versions
145+
/// (and this should be done periodically, but not on every build).
146+
/// </para>
147+
/// </remarks>
148+
/// <param name="platform">Platform.</param>
149+
/// <param name="browserName">Browser name.</param>
150+
/// <param name="browserVersion">Browser version.</param>
151+
[NonParallelizable]
152+
[Category("Browser")]
153+
[Explicit("This can only be executed with configuration for a remote web browser, and often isn't neccesary. See the comments on the test for more info.")]
154+
[TestCaseSource(typeof(SupportedBrowserConfigurations), nameof(SupportedBrowserConfigurations.AsTestCaseData))]
155+
public void GetIdentification_integration_successfully_identifies_supported_web_drivers(string platform,
156+
string browserName,
157+
string browserVersion)
158+
{
159+
// Arrange
160+
var scenarioName = nameof(GetIdentification_integration_successfully_identifies_supported_web_drivers);
161+
var caps = GetCapabilities(platform, browserName, browserVersion);
162+
var factory = GetWebDriverFactory.FromConfiguration();
163+
164+
BrowserIdentification result;
165+
166+
// Act
167+
using(var webDriver = factory.CreateWebDriver(caps, scenarioName: scenarioName))
168+
{
169+
result = webDriver.GetIdentification();
170+
webDriver.Navigate().GoToUrl("http://google.com/");
171+
172+
SendScenarioStatus(webDriver, !(result.Version is UnrecognisedVersion));
173+
}
174+
175+
// Assert
176+
Assert.That(result.Version,
177+
Is.Not.InstanceOf<UnrecognisedVersion>(),
178+
"Browser was not recognised:{0}",
179+
result);
180+
}
181+
182+
IDictionary<string,object> GetCapabilities(string platform,
183+
string browserName,
184+
string browserVersion)
185+
{
186+
if(platform == null)
187+
throw new ArgumentNullException(nameof(platform));
188+
if(browserName == null)
189+
throw new ArgumentNullException(nameof(browserName));
190+
191+
var caps = new Dictionary<string,object>();
192+
193+
caps.Add(CapabilityType.Platform, platform);
194+
caps.Add(CapabilityType.BrowserName, browserName);
195+
196+
if(!String.IsNullOrEmpty(browserVersion))
197+
caps.Add(CapabilityType.Version, browserVersion);
198+
199+
return caps;
200+
}
201+
202+
void SendScenarioStatus(IWebDriver driver, bool isSuccess)
203+
{
204+
if(driver is ICanReceiveScenarioStatus)
205+
{
206+
var statusDriver = (ICanReceiveScenarioStatus) driver;
207+
208+
if(isSuccess)
209+
statusDriver.MarkScenarioAsSuccess();
210+
else
211+
statusDriver.MarkScenarioAsFailure();
212+
}
213+
}
121214
}
122215
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using CSF.WebDriverExtras.BrowserId;
3+
using NUnit.Framework;
4+
5+
namespace CSF.WebDriverExtras.Tests.BrowserId
6+
{
7+
[TestFixture,Parallelizable(ParallelScope.All)]
8+
public class BrowserIdentificationTests
9+
{
10+
[Test]
11+
public void ToString_returns_appropriately_formatted_string()
12+
{
13+
// Arrange
14+
var id = new BrowserIdentification("FooBrowser", new SimpleStringVersion("123"), "BarPlatform");
15+
16+
// Act
17+
var result = id.ToString();
18+
19+
// Assert
20+
Assert.That(result, Is.EqualTo("FooBrowser 123 (BarPlatform)"));
21+
}
22+
23+
[Test]
24+
public void ToString_returns_correct_string_for_unidentified_browser()
25+
{
26+
// Arrange
27+
var id = BrowserIdentification.UnidentifiedBrowser;
28+
29+
// Act
30+
var result = id.ToString();
31+
32+
// Assert
33+
Assert.That(result, Is.EqualTo("Unidentified browser"));
34+
}
35+
}
36+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using CSF.WebDriverExtras.BrowserId;
2+
using NUnit.Framework;
3+
using System;
4+
5+
namespace CSF.WebDriverExtras.Tests.BrowserId
6+
{
7+
[TestFixture,Parallelizable(ParallelScope.All)]
8+
public class DottedNumericVersionTests
9+
{
10+
[TestCase("0.1.2")]
11+
[TestCase("1.0.0")]
12+
[TestCase("111.222.333")]
13+
[TestCase("0.1")]
14+
[TestCase("5")]
15+
[TestCase("0.1.2.3.4.5")]
16+
public void Parse_can_roundtrip_a_valid_string(string versionString)
17+
{
18+
// Act
19+
var result = DottedNumericVersion.Parse(versionString);
20+
21+
// Assert
22+
Assert.That(result, Is.Not.Null);
23+
var roundtripped = result.ToString();
24+
Assert.That(roundtripped, Is.EqualTo(versionString));
25+
}
26+
27+
[Test]
28+
public void Parse_returns_null_for_a_version_with_an_alphabetic_component()
29+
{
30+
// Act
31+
var result = DottedNumericVersion.Parse("0.a.2");
32+
33+
// Assert
34+
Assert.That(result, Is.Null);
35+
}
36+
37+
[Test]
38+
public void Parse_returns_null_for_empty_string()
39+
{
40+
// Act
41+
var result = DottedNumericVersion.Parse(String.Empty);
42+
43+
// Assert
44+
Assert.That(result, Is.Null);
45+
}
46+
47+
[Test]
48+
public void Parse_returns_null_for_a_version_which_includes_a_space()
49+
{
50+
// Act
51+
var result = DottedNumericVersion.Parse("0.1 1.2");
52+
53+
// Assert
54+
Assert.That(result, Is.Null);
55+
}
56+
57+
[TestCase("5", "10")]
58+
[TestCase("0.1.2", "1.2.3")]
59+
[TestCase("0.1.0", "0.1.1")]
60+
[TestCase("0.1.5", "0.1.10")]
61+
[TestCase("0.1", "0.1.2")]
62+
[TestCase("0.1.2.4", "0.1.2.4.0")]
63+
public void CompareTo_returns_minus_one_when_first_version_is_smaller_than_second_version(string first, string second)
64+
{
65+
// Arrange
66+
var firstVersion = DottedNumericVersion.Parse(first);
67+
var secondVersion = DottedNumericVersion.Parse(second);
68+
69+
// Act
70+
var result = firstVersion.CompareTo(secondVersion);
71+
72+
// Assert
73+
Assert.That(result, Is.EqualTo(-1));
74+
}
75+
76+
[TestCase("10", "5")]
77+
[TestCase("5.1.2", "1.2.3")]
78+
[TestCase("0.1.1", "0.1.0")]
79+
[TestCase("0.1.10", "0.1.5")]
80+
[TestCase("0.1.2", "0.1")]
81+
[TestCase("0.1.2.4.15", "0.1.2.4")]
82+
public void CompareTo_returns_one_when_first_version_is_greater_than_second_version(string first, string second)
83+
{
84+
// Arrange
85+
var firstVersion = DottedNumericVersion.Parse(first);
86+
var secondVersion = DottedNumericVersion.Parse(second);
87+
88+
// Act
89+
var result = firstVersion.CompareTo(secondVersion);
90+
91+
// Assert
92+
Assert.That(result, Is.EqualTo(1));
93+
}
94+
95+
[TestCase("10", "10")]
96+
[TestCase("5.1.2", "5.1.2")]
97+
[TestCase("0.1.1", "0.1.1")]
98+
[TestCase("0.1.10", "0.1.10")]
99+
[TestCase("0.1.2", "0.1.2")]
100+
[TestCase("0.1.2.4.15", "0.1.2.4.15")]
101+
public void CompareTo_returns_zero_when_first_version_is_same_as_second_version(string first, string second)
102+
{
103+
// Arrange
104+
var firstVersion = DottedNumericVersion.Parse(first);
105+
var secondVersion = DottedNumericVersion.Parse(second);
106+
107+
// Act
108+
var result = firstVersion.CompareTo(secondVersion);
109+
110+
// Assert
111+
Assert.That(result, Is.EqualTo(0));
112+
}
113+
}
114+
}

CSF.WebDriverExtras.Tests/Flags/SemanticVersionTests.cs renamed to CSF.WebDriverExtras.Tests/BrowserId/SemanticVersionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
2-
using CSF.WebDriverExtras.Flags;
2+
using CSF.WebDriverExtras.BrowserId;
33
using NUnit.Framework;
44

5-
namespace CSF.WebDriverExtras.Tests.Flags
5+
namespace CSF.WebDriverExtras.Tests.BrowserId
66
{
77
[TestFixture,Parallelizable(ParallelScope.All)]
88
public class SemanticVersionTests

CSF.WebDriverExtras.Tests/Flags/SimpleStringVersion.cs renamed to CSF.WebDriverExtras.Tests/BrowserId/SimpleStringVersion.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
2-
using CSF.WebDriverExtras.Flags;
2+
using CSF.WebDriverExtras.BrowserId;
33

4-
namespace CSF.WebDriverExtras.Tests.Flags
4+
namespace CSF.WebDriverExtras.Tests.BrowserId
55
{
66
public class SimpleStringVersion : BrowserVersion
77
{
@@ -27,6 +27,8 @@ public override bool Equals(BrowserVersion other)
2727

2828
public override int GetHashCode() => version.GetHashCode();
2929

30+
public override string ToString() => version;
31+
3032
public SimpleStringVersion(string version)
3133
{
3234
if(version == null)

CSF.WebDriverExtras.Tests/Flags/VersionFactoryTests.cs renamed to CSF.WebDriverExtras.Tests/BrowserId/VersionFactoryTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
2-
using CSF.WebDriverExtras.Flags;
2+
using CSF.WebDriverExtras.BrowserId;
33
using NUnit.Framework;
44

5-
namespace CSF.WebDriverExtras.Tests.Flags
5+
namespace CSF.WebDriverExtras.Tests.BrowserId
66
{
77
[TestFixture,Parallelizable(ParallelScope.All)]
88
public class VersionFactoryTests
@@ -24,13 +24,28 @@ public void CreateVersion_can_create_a_semantic_version(VersionFactory sut)
2424
public void CreateVersion_can_create_an_unrecognised_version(VersionFactory sut)
2525
{
2626
// Arrange
27-
var versionString = "55.20";
27+
var versionString = "version 55.20";
2828

2929
// Act
3030
var result = sut.CreateVersion(versionString);
3131

3232
// Assert
3333
Assert.That(result, Is.EqualTo(new UnrecognisedVersion(versionString)));
3434
}
35+
36+
[TestCaseSource(typeof(SupportedBrowserConfigurations), nameof(SupportedBrowserConfigurations.ActualIdentifierTestCaseData))]
37+
public void CreateVersion_can_create_versions_for_all_supported_browsers(string browserName, string browserVersion)
38+
{
39+
// Arrange
40+
var sut = new VersionFactory();
41+
42+
// Act
43+
var result = sut.CreateVersion(browserVersion, browserName);
44+
45+
// Assert
46+
Assert.That(result,
47+
Is.Not.InstanceOf<UnrecognisedVersion>(),
48+
$"{nameof(VersionFactory)} created an unrecognised version for {browserName}: '{browserVersion}'.");
49+
}
3550
}
3651
}

CSF.WebDriverExtras.Tests/CSF.WebDriverExtras.Tests.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RootNamespace>CSF.WebDriverExtras.Tests</RootNamespace>
99
<AssemblyName>CSF.WebDriverExtras.Tests</AssemblyName>
1010
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11-
<ReleaseVersion>0.3.2-beta</ReleaseVersion>
11+
<ReleaseVersion>0.3.3-beta</ReleaseVersion>
1212
</PropertyGroup>
1313
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1414
<DebugSymbols>true</DebugSymbols>
@@ -69,15 +69,18 @@
6969
<Compile Include="HasValuesAttribute.cs" />
7070
<Compile Include="SuccessAndFailure\SauceLabsSuccessFailureGatewayTests.cs" />
7171
<Compile Include="ExecutesScriptAttribute.cs" />
72-
<Compile Include="Flags\SemanticVersionTests.cs" />
7372
<Compile Include="Flags\DefinitionReaderTests.cs" />
74-
<Compile Include="Flags\SimpleStringVersion.cs" />
7573
<Compile Include="Flags\FlagsDefinitionTests.cs" />
76-
<Compile Include="Flags\BrowserFlagsProviderTests.cs" />
7774
<Compile Include="FactoryBuilders\WebDriverFactorySourceIntegrationTests.cs" />
7875
<Compile Include="ConnectToGoogleIntegrationTest.cs" />
79-
<Compile Include="Flags\VersionFactoryTests.cs" />
80-
<Compile Include="Flags\BrowserIdentificationFactoryTests.cs" />
76+
<Compile Include="BrowserId\BrowserIdentificationFactoryTests.cs" />
77+
<Compile Include="BrowserId\SemanticVersionTests.cs" />
78+
<Compile Include="BrowserId\SimpleStringVersion.cs" />
79+
<Compile Include="BrowserId\VersionFactoryTests.cs" />
80+
<Compile Include="Flags\BrowserFlagsProviderTests.cs" />
81+
<Compile Include="BrowserId\BrowserIdentificationTests.cs" />
82+
<Compile Include="SupportedBrowserConfigurations.cs" />
83+
<Compile Include="BrowserId\DottedNumericVersionTests.cs" />
8184
</ItemGroup>
8285
<ItemGroup>
8386
<None Include="packages.config" />
@@ -95,6 +98,7 @@
9598
<Folder Include="Config\" />
9699
<Folder Include="SuccessAndFailure\" />
97100
<Folder Include="Flags\" />
101+
<Folder Include="BrowserId\" />
98102
</ItemGroup>
99103
<ItemGroup>
100104
<EmbeddedResource Include="Flags\SampleFlagsDefinitions.json">

CSF.WebDriverExtras.Tests/Flags/BrowserFlagsProviderTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using CSF.WebDriverExtras.BrowserId;
34
using CSF.WebDriverExtras.Flags;
45
using Moq;
56
using NUnit.Framework;

0 commit comments

Comments
 (0)