Skip to content

Commit a03bc56

Browse files
committed
Merge branch 'release/0.4.0' into production
2 parents 93ebd94 + 58faf93 commit a03bc56

32 files changed

Lines changed: 728 additions & 193 deletions

CSF.WebDriverExtras.Tests/App.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
<section name="WebDriverFactory" type="CSF.WebDriverExtras.Config.WebDriverFactoryConfigurationSection, CSF.WebDriverExtras"/>
55
</configSections>
66
<WebDriverFactory AssemblyQualifiedTypeName="CSF.WebDriverExtras.Factories.ChromeDriverFactory, CSF.WebDriverExtras" />
7+
<!--
8+
<WebDriverFactory AssemblyQualifiedTypeName="CSF.WebDriverExtras.Factories.SauceConnectDriverFactory, CSF.WebDriverExtras">
9+
<FactoryOptions>
10+
<Property Name="BrowserName" Value="BROWSER" />
11+
<Property Name="BrowserVersion" Value="VERSION" />
12+
<Property Name="RemoteWebDriverAddress" Value="http://ondemand.saucelabs.com/wd/hub" />
13+
<Property Name="SauceConnectUsername" Value="craigfowler_screenplay" />
14+
<Property Name="SauceConnectApiKey" Value="SECRET" />
15+
<Property Name="SauceLabsBuildName" Value="Interactive build for ISSUE_NUMBER" />
16+
</FactoryOptions>
17+
</WebDriverFactory>
18+
-->
719
<runtime>
820
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
921
<dependentAssembly>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// BrowserIdAttribute.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2018 Craig Fowler
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using System.Reflection;
28+
using OpenQA.Selenium;
29+
using Ploeh.AutoFixture;
30+
using Ploeh.AutoFixture.NUnit3;
31+
32+
namespace CSF.WebDriverExtras.Tests.Autofixture
33+
{
34+
public class BrowserIdAttribute : CustomizeAttribute
35+
{
36+
public string Browser { get; set; }
37+
38+
public string Version { get; set; }
39+
40+
PlatformType? platform;
41+
public PlatformType Platform
42+
{
43+
get {
44+
return platform ?? PlatformType.Any;
45+
}
46+
set {
47+
platform = value;
48+
}
49+
}
50+
51+
public bool HasRequestedVersion { get; set; }
52+
53+
string requestedVersion;
54+
public string RequestedVersion
55+
{
56+
get {
57+
return requestedVersion;
58+
}
59+
set {
60+
requestedVersion = value;
61+
62+
if(!String.IsNullOrEmpty(value))
63+
HasRequestedVersion = true;
64+
}
65+
}
66+
67+
public override ICustomization GetCustomization(ParameterInfo parameter)
68+
{
69+
var webDriverType = GetSanitisedWebDriverType(parameter);
70+
return GetCustomisation(webDriverType);
71+
}
72+
73+
Type GetSanitisedWebDriverType(ParameterInfo parameter)
74+
{
75+
if(parameter == null)
76+
throw new ArgumentNullException(nameof(parameter));
77+
78+
var paramType = parameter.ParameterType;
79+
80+
if(!typeof(IHasCapabilities).IsAssignableFrom(paramType))
81+
throw new ArgumentException($"Parameter type must implement {nameof(IHasCapabilities)}.", nameof(parameter));
82+
83+
if(!paramType.IsInterface)
84+
throw new ArgumentException($"The parameter type must be an interface, but `{paramType.FullName}' is not.", nameof(parameter));
85+
86+
return paramType;
87+
}
88+
89+
ICustomization GetCustomisation(Type webDriverType)
90+
{
91+
var type = typeof(WebDriverWithIdentificationCustomiszation<>);
92+
var genericType = type.MakeGenericType(webDriverType);
93+
94+
return (ICustomization) Activator.CreateInstance(genericType,
95+
Browser,
96+
Version,
97+
platform,
98+
HasRequestedVersion,
99+
RequestedVersion);
100+
}
101+
}
102+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// BrowserIdCustomization.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2018 Craig Fowler
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using Moq;
28+
using OpenQA.Selenium;
29+
using Ploeh.AutoFixture;
30+
31+
namespace CSF.WebDriverExtras.Tests.Autofixture
32+
{
33+
public class WebDriverWithIdentificationCustomiszation<T> : ICustomization
34+
where T : class,IHasCapabilities
35+
{
36+
readonly string browser, version, requestedVersion;
37+
readonly PlatformType? platform;
38+
readonly bool hasRequestedVersion;
39+
40+
public void Customize(IFixture fixture)
41+
{
42+
fixture.Customize<T>(c => {
43+
return c.FromFactory((PlatformType plat, string name, string ver) => CreateWebDriver(plat, name, ver));
44+
});
45+
}
46+
47+
T CreateWebDriver(PlatformType plat, string name, string ver)
48+
{
49+
var driver = new Mock<T>();
50+
51+
var caps = Mock.Of<ICapabilities>();
52+
53+
driver.SetupGet(x => x.Capabilities).Returns(caps);
54+
55+
var effectiveBrowserName = browser ?? name;
56+
var effectiveBrowserVersion = version ?? ver;
57+
var effectivePlatform = platform ?? plat;
58+
59+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(effectiveBrowserName);
60+
Mock.Get(caps).SetupGet(x => x.Version).Returns(effectiveBrowserVersion);
61+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(effectivePlatform));
62+
63+
if(hasRequestedVersion)
64+
{
65+
driver
66+
.As<IHasRequestedVersion>()
67+
.SetupGet(x => x.RequestedBrowserVersion)
68+
.Returns(requestedVersion);
69+
}
70+
71+
return driver.Object;
72+
}
73+
74+
public WebDriverWithIdentificationCustomiszation(string browser,
75+
string version,
76+
PlatformType? platform,
77+
bool hasRequestedVersion,
78+
string requestedVersion)
79+
{
80+
this.browser = browser;
81+
this.version = version;
82+
this.platform = platform;
83+
this.hasRequestedVersion = hasRequestedVersion;
84+
this.requestedVersion = requestedVersion;
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)