Skip to content

Commit 6dcd593

Browse files
committed
single and parallel tests
1 parent 9f89203 commit 6dcd593

26 files changed

+305
-667
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

NUnit-BrowserStack/App.config

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="environments">
5+
<section name="chrome" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
6+
<section name="firefox" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
7+
<section name="safari" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
8+
<section name="ie" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9+
</sectionGroup>
10+
<section name="capabilities" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
11+
</configSections>
12+
13+
<appSettings>
14+
<add key="user" value="BROWSERSTACK_USERNAME" />
15+
<add key="key" value="BROWSERSTACK_ACCESS_KEY" />
16+
<add key="server" value="hub-cloud.browserstack.com" />
17+
</appSettings>
18+
19+
<capabilities>
20+
<add key="build" value="nunit-browserstack" />
21+
<add key="browserstack.debug" value="true" />
22+
</capabilities>
23+
24+
<environments>
25+
<chrome>
26+
<add key="browser" value="chrome" />
27+
</chrome>
28+
<firefox>
29+
<add key="browser" value="firefox" />
30+
</firefox>
31+
<safari>
32+
<add key="browser" value="safari" />
33+
</safari>
34+
<ie>
35+
<add key="browser" value="ie" />
36+
</ie>
37+
</environments>
38+
</configuration>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using NUnit.Framework;
2+
using OpenQA.Selenium;
3+
using OpenQA.Selenium.Remote;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Specialized;
7+
using System.Configuration;
8+
9+
10+
namespace BrowserStack
11+
{
12+
[TestFixture]
13+
public class BrowserStackNUnitTest
14+
{
15+
protected IWebDriver driver;
16+
protected string environment;
17+
protected bool isLocal;
18+
private Local browserStackLocal;
19+
20+
public BrowserStackNUnitTest(string environment, bool isLocal = false)
21+
{
22+
this.environment = environment;
23+
this.isLocal = isLocal;
24+
}
25+
26+
[SetUp]
27+
public void Init()
28+
{
29+
NameValueCollection caps = ConfigurationManager.GetSection("capabilities") as NameValueCollection;
30+
NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection;
31+
32+
DesiredCapabilities capability = new DesiredCapabilities();
33+
34+
foreach (string key in caps.AllKeys)
35+
{
36+
capability.SetCapability(key, caps[key]);
37+
}
38+
39+
foreach (string key in settings.AllKeys)
40+
{
41+
capability.SetCapability(key, settings[key]);
42+
}
43+
44+
capability.SetCapability("name", GetType().Name);
45+
46+
String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
47+
if(username == null)
48+
{
49+
username = ConfigurationManager.AppSettings.Get("user");
50+
}
51+
52+
String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
53+
if (accesskey == null)
54+
{
55+
accesskey = ConfigurationManager.AppSettings.Get("key");
56+
}
57+
58+
capability.SetCapability("browserstack.user", username);
59+
capability.SetCapability("browserstack.key", accesskey);
60+
61+
if (isLocal)
62+
{
63+
browserStackLocal = new Local();
64+
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
65+
new KeyValuePair<string, string>("key", "")
66+
};
67+
browserStackLocal.start(bsLocalArgs);
68+
}
69+
70+
driver = new RemoteWebDriver(new Uri("http://"+ ConfigurationManager.AppSettings.Get("server") +"/wd/hub/"), capability);
71+
}
72+
73+
[TearDown]
74+
public void Cleanup()
75+
{
76+
driver.Quit();
77+
if (browserStackLocal != null)
78+
{
79+
browserStackLocal.stop();
80+
}
81+
}
82+
}
83+
}

NUnit-BrowserStack/LocalTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using NUnit.Framework;
2+
using OpenQA.Selenium;
3+
4+
namespace BrowserStack
5+
{
6+
[TestFixture("chrome")]
7+
public class LocalTest : BrowserStackNUnitTest
8+
{
9+
public LocalTest(string environment) : base(environment, true) { }
10+
11+
[Test]
12+
public void HealthCheck()
13+
{
14+
driver.Navigate().GoToUrl("http://bs-local.com:45691/check");
15+
StringAssert.Contains("Up and Running", driver.PageSource);
16+
}
17+
}
18+
}

Series Tests/NUnit-BrowserStack/NUnit-BrowserStack.csproj renamed to NUnit-BrowserStack/NUnit-BrowserStack.csproj

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ProjectGuid>{D309DDB3-1E3B-428B-B00B-1257F2532079}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>NUnit_BrowserStack</RootNamespace>
11-
<AssemblyName>NUnit-BrowserStack</AssemblyName>
10+
<RootNamespace>SingleTest</RootNamespace>
11+
<AssemblyName>SingleTest</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>
@@ -29,11 +29,30 @@
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
32+
<PropertyGroup>
33+
<StartupObject />
34+
</PropertyGroup>
3235
<ItemGroup>
3336
<Reference Include="BrowserStackLocal, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
3437
<HintPath>..\packages\BrowserStackLocal.0.2.0.0\lib\net45\BrowserStackLocal.dll</HintPath>
3538
<Private>True</Private>
3639
</Reference>
40+
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
41+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\Mono.Cecil.dll</HintPath>
42+
<Private>False</Private>
43+
</Reference>
44+
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
45+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\Mono.Cecil.Mdb.dll</HintPath>
46+
<Private>False</Private>
47+
</Reference>
48+
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
49+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\Mono.Cecil.Pdb.dll</HintPath>
50+
<Private>False</Private>
51+
</Reference>
52+
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
53+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\Mono.Cecil.Rocks.dll</HintPath>
54+
<Private>False</Private>
55+
</Reference>
3756
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
3857
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
3958
<Private>False</Private>
@@ -42,8 +61,16 @@
4261
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
4362
<Private>False</Private>
4463
</Reference>
45-
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
46-
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
64+
<Reference Include="nunit.engine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
65+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\nunit.engine.dll</HintPath>
66+
<Private>False</Private>
67+
</Reference>
68+
<Reference Include="nunit.engine.api, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
69+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\nunit.engine.api.dll</HintPath>
70+
<Private>False</Private>
71+
</Reference>
72+
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
73+
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
4774
<Private>True</Private>
4875
</Reference>
4976
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
@@ -54,7 +81,12 @@
5481
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
5582
<Private>False</Private>
5683
</Reference>
84+
<Reference Include="NUnit3.TestAdapter, Version=3.4.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
85+
<HintPath>..\packages\NUnit3TestAdapter.3.4.0\lib\NUnit3.TestAdapter.dll</HintPath>
86+
<Private>False</Private>
87+
</Reference>
5788
<Reference Include="System" />
89+
<Reference Include="System.Configuration" />
5890
<Reference Include="System.Core" />
5991
<Reference Include="System.Drawing" />
6092
<Reference Include="System.Xml.Linq" />
@@ -63,17 +95,22 @@
6395
<Reference Include="System.Data" />
6496
<Reference Include="System.Net.Http" />
6597
<Reference Include="System.Xml" />
66-
<Reference Include="WebDriver, Version=2.53.0.0, Culture=neutral, processorArchitecture=MSIL">
67-
<HintPath>..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll</HintPath>
98+
<Reference Include="WebDriver, Version=2.53.1.0, Culture=neutral, processorArchitecture=MSIL">
99+
<HintPath>..\packages\Selenium.WebDriver.2.53.1\lib\net40\WebDriver.dll</HintPath>
68100
<Private>True</Private>
69101
</Reference>
70102
</ItemGroup>
71103
<ItemGroup>
72-
<Compile Include="BrowserStackLocalTests.cs" />
73-
<Compile Include="BrowserStackTests.cs" />
104+
<Compile Include="BrowserStackNUnitTest.cs" />
105+
<Compile Include="LocalTest.cs" />
106+
<Compile Include="ParallelTest.cs" />
107+
<Compile Include="SingleTest.cs" />
74108
<Compile Include="Properties\AssemblyInfo.cs" />
75109
</ItemGroup>
76110
<ItemGroup>
111+
<None Include="App.config">
112+
<SubType>Designer</SubType>
113+
</None>
77114
<None Include="packages.config" />
78115
</ItemGroup>
79116
<ItemGroup>

NUnit-BrowserStack/ParallelTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using NUnit.Framework;
2+
using OpenQA.Selenium;
3+
4+
namespace BrowserStack
5+
{
6+
[TestFixture("chrome")]
7+
[TestFixture("firefox")]
8+
[TestFixture("safari")]
9+
[TestFixture("ie")]
10+
[Parallelizable(ParallelScope.Fixtures)]
11+
public class ParallelTest : SingleTest
12+
{
13+
public ParallelTest(string environment) : base(environment) { }
14+
}
15+
}
File renamed without changes.

NUnit-BrowserStack/SingleTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NUnit.Framework;
2+
using OpenQA.Selenium;
3+
4+
namespace BrowserStack
5+
{
6+
[TestFixture("chrome")]
7+
public class SingleTest : BrowserStackNUnitTest
8+
{
9+
public SingleTest(string environment) : base(environment) { }
10+
11+
[Test]
12+
public void SearchGoogle()
13+
{
14+
driver.Navigate().GoToUrl("https://www.google.com/ncr");
15+
IWebElement query = driver.FindElement(By.Name("q"));
16+
query.SendKeys("BrowserStack");
17+
query.Submit();
18+
System.Threading.Thread.Sleep(5000);
19+
Assert.AreEqual("BrowserStack - Google Search", driver.Title);
20+
}
21+
}
22+
}

NUnit-BrowserStack/local.log

Whitespace-only changes.

0 commit comments

Comments
 (0)