diff --git a/.gitignore b/.gitignore
index 4818878..906adac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,6 @@ bin
obj
.vs
.DS_Store
+local.log
+log
+browserstack.err
diff --git a/NUnit-BrowserStack/.config/dotnet-tools.json b/NUnit-BrowserStack/.config/dotnet-tools.json
new file mode 100644
index 0000000..c967c89
--- /dev/null
+++ b/NUnit-BrowserStack/.config/dotnet-tools.json
@@ -0,0 +1,5 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {}
+}
diff --git a/NUnit-BrowserStack/App.config b/NUnit-BrowserStack/App.config
deleted file mode 100644
index e10ac01..0000000
--- a/NUnit-BrowserStack/App.config
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/NUnit-BrowserStack/BrowserStackNUnitTest.cs b/NUnit-BrowserStack/BrowserStackNUnitTest.cs
index 3873945..cde298c 100644
--- a/NUnit-BrowserStack/BrowserStackNUnitTest.cs
+++ b/NUnit-BrowserStack/BrowserStackNUnitTest.cs
@@ -11,82 +11,20 @@ namespace BrowserStack
[TestFixture]
public class BrowserStackNUnitTest
{
- protected IWebDriver driver;
- protected string profile;
- protected string environment;
- private Local browserStackLocal;
+ protected RemoteWebDriver driver;
- public BrowserStackNUnitTest(string profile, string environment)
+ public BrowserStackNUnitTest()
{
- this.profile = profile;
- this.environment = environment;
- }
-
- static DriverOptions getBrowserOption(String browser)
- {
- switch (browser)
- {
- case "chrome":
- return new OpenQA.Selenium.Chrome.ChromeOptions();
- case "firefox":
- return new OpenQA.Selenium.Firefox.FirefoxOptions();
- case "safari":
- return new OpenQA.Selenium.Safari.SafariOptions();
- case "edge":
- return new OpenQA.Selenium.Edge.EdgeOptions();
- default:
- return new OpenQA.Selenium.Chrome.ChromeOptions();
- }
}
[SetUp]
public void Init()
{
- NameValueCollection caps =
- ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection;
- NameValueCollection settings =
- ConfigurationManager.GetSection("environments/" + environment)
- as NameValueCollection;
- DriverOptions capability = getBrowserOption(settings["browser"]);
-
+ DriverOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
capability.BrowserVersion = "latest";
- System.Collections.Generic.Dictionary browserstackOptions =
- new Dictionary();
-
- foreach (string key in caps.AllKeys)
- {
- browserstackOptions.Add(key, caps[key]);
- }
-
- String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
- if (username == null)
- {
- username = ConfigurationManager.AppSettings.Get("user");
- }
-
- String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
- if (accesskey == null)
- {
- accesskey = ConfigurationManager.AppSettings.Get("key");
- }
-
- browserstackOptions.Add("userName", username);
- browserstackOptions.Add("accessKey", accesskey);
- if (caps.Get("local").ToString() == "true")
- {
- browserStackLocal = new Local();
- List> bsLocalArgs = new List<
- KeyValuePair
- >()
- {
- new KeyValuePair("key", accesskey)
- };
- browserStackLocal.start(bsLocalArgs);
- }
- capability.AddAdditionalOption("bstack:options", browserstackOptions);
driver = new RemoteWebDriver(
- new Uri("https://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"),
+ new Uri("http://localhost:4444/wd/hub/"),
capability
);
}
@@ -95,10 +33,6 @@ public void Init()
public void Cleanup()
{
driver.Quit();
- if (browserStackLocal != null)
- {
- browserStackLocal.stop();
- }
}
}
}
diff --git a/NUnit-BrowserStack/LocalTest.cs b/NUnit-BrowserStack/LocalTest.cs
deleted file mode 100644
index 70f80b0..0000000
--- a/NUnit-BrowserStack/LocalTest.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using NUnit.Framework;
-using OpenQA.Selenium;
-using System.Text.RegularExpressions;
-
-namespace BrowserStack
-{
- [TestFixture("local", "chrome")]
- public class LocalTest : BrowserStackNUnitTest
- {
- public LocalTest(string profile, string environment) : base(profile, environment) { }
-
- [Test]
- public void HealthCheck()
- {
- driver.Navigate().GoToUrl("http://bs-local.com:45691/check");
- Assert.IsTrue(Regex.IsMatch(driver.PageSource, "Up and running", RegexOptions.IgnoreCase));
- }
- }
-}
diff --git a/NUnit-BrowserStack/NUnit-BrowserStack.csproj b/NUnit-BrowserStack/NUnit-BrowserStack.csproj
index 53f2f2c..c3e4e8b 100644
--- a/NUnit-BrowserStack/NUnit-BrowserStack.csproj
+++ b/NUnit-BrowserStack/NUnit-BrowserStack.csproj
@@ -1,90 +1,22 @@
-
-
-
-
-
-
+
+
- Debug
- AnyCPU
- {D309DDB3-1E3B-428B-B00B-1257F2532079}
- Library
- Properties
+ net6.0
SingleTest
SingleTest
- v4.5
- 512
+ enable
+ enable
+
+ false
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ..\packages\log4net.2.0.14\lib\net45\log4net.dll
-
-
-
- ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
-
-
- ..\packages\BrowserStackLocal.2.0.0\lib\net20\BrowserStackLocal.dll
-
-
- ..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll
-
-
- ..\packages\Selenium.WebDriver.4.1.0\lib\net45\WebDriver.dll
-
-
-
-
-
-
-
-
-
-
-
- Designer
-
-
-
+
-
+
+
+
+
+
+
-
-
-
\ No newline at end of file
+
+
diff --git a/NUnit-BrowserStack/ParallelTest.cs b/NUnit-BrowserStack/ParallelTest.cs
deleted file mode 100644
index 6923a52..0000000
--- a/NUnit-BrowserStack/ParallelTest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using NUnit.Framework;
-using OpenQA.Selenium;
-
-namespace BrowserStack
-{
- [TestFixture("parallel", "chrome")]
- [TestFixture("parallel", "firefox")]
- [TestFixture("parallel", "safari")]
- [TestFixture("parallel", "edge")]
- [Parallelizable(ParallelScope.Fixtures)]
- public class ParallelTest : SingleTest
- {
- public ParallelTest(string profile, string environment) : base(profile, environment) { }
- }
-}
diff --git a/NUnit-BrowserStack/Properties/AssemblyInfo.cs b/NUnit-BrowserStack/Properties/AssemblyInfo.cs
deleted file mode 100644
index c6753e5..0000000
--- a/NUnit-BrowserStack/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using NUnit.Framework;
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("NUnit-BrowserStack")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("NUnit-BrowserStack")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-// For more details on LevelOfParallelism Attribute review NUnit documentation- https://github.com/nunit/docs/wiki/LevelOfParallelism-Attribute
-[assembly: LevelOfParallelism(2)]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("d309ddb3-1e3b-428b-b00b-1257f2532079")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/NUnit-BrowserStack/SampleLocalTest.cs b/NUnit-BrowserStack/SampleLocalTest.cs
new file mode 100644
index 0000000..e21228c
--- /dev/null
+++ b/NUnit-BrowserStack/SampleLocalTest.cs
@@ -0,0 +1,20 @@
+using NUnit.Framework;
+using OpenQA.Selenium;
+using System.Text.RegularExpressions;
+
+namespace BrowserStack
+{
+ [TestFixture]
+ [Category("sample-local-test")]
+ public class SampleLocalTest : BrowserStackNUnitTest
+ {
+ public SampleLocalTest() : base() { }
+
+ [Test]
+ public void BStackTunnelCheck()
+ {
+ driver.Navigate().GoToUrl("http://bs-local.com:45454/");
+ StringAssert.Contains("BrowserStack Local", driver.Title);
+ }
+ }
+}
diff --git a/NUnit-BrowserStack/SingleTest.cs b/NUnit-BrowserStack/SampleTest.cs
similarity index 81%
rename from NUnit-BrowserStack/SingleTest.cs
rename to NUnit-BrowserStack/SampleTest.cs
index 42776d8..2149890 100644
--- a/NUnit-BrowserStack/SingleTest.cs
+++ b/NUnit-BrowserStack/SampleTest.cs
@@ -3,10 +3,11 @@
namespace BrowserStack
{
- [TestFixture("single", "chrome")]
- public class SingleTest : BrowserStackNUnitTest
+ [TestFixture]
+ [Category("sample-test")]
+ public class SampleTest : BrowserStackNUnitTest
{
- public SingleTest(string profile, string environment) : base(profile, environment) { }
+ public SampleTest() : base() { }
[Test]
public void SearchBstackDemo()
@@ -22,4 +23,4 @@ public void SearchBstackDemo()
Assert.AreEqual(productOnCartText, productOnPageText);
}
}
-}
\ No newline at end of file
+}
diff --git a/NUnit-BrowserStack/browserstack.yml b/NUnit-BrowserStack/browserstack.yml
new file mode 100644
index 0000000..eb1c8eb
--- /dev/null
+++ b/NUnit-BrowserStack/browserstack.yml
@@ -0,0 +1,66 @@
+# =============================
+# Set BrowserStack Credentials
+# =============================
+# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
+# BROWSERSTACK_ACCESS_KEY as env variables
+
+userName: YOUR_USERNAME
+accessKey: YOUR_ACCESS_KEY
+
+# ======================
+# BrowserStack Reporting
+# ======================
+# The following capabilities are used to set up reporting on BrowserStack:
+# Set 'projectName' to the name of your project. Example, Marketing Website
+projectName: BrowserStack Samples
+# Set `buildName` as the name of the job / testsuite being run
+buildName: browserstack build
+# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
+# buildName. Choose your buildIdentifier format from the available expressions:
+# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
+# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
+# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
+buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
+# Set `source` in the syntax `:sample-:
+
+source: nunit:sample-sdk:v1.1
+
+# =======================================
+# Platforms (Browsers / Devices to test)
+# =======================================
+# Platforms object contains all the browser / device combinations you want to test on.
+# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
+platforms:
+ - os: OS X
+ osVersion: Big Sur
+ browserName: Chrome
+ browserVersion: latest
+ - os: Windows
+ osVersion: 10
+ browserName: Edge
+ browserVersion: latest
+ - deviceName: Samsung Galaxy S22 Ultra
+ browserName: chrome # Try 'samsung' for Samsung browser
+ osVersion: 12.0
+
+# ==========================================
+# BrowserStack Local
+# (For localhost, staging/private websites)
+# ==========================================
+# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
+# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
+browserstackLocal: true # (Default false)
+
+# browserStackLocalOptions:
+# Options to be passed to BrowserStack local in-case of advanced configurations
+ # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local.
+ # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
+ # Entire list of arguments availabe here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
+
+# ===================
+# Debugging features
+# ===================
+debug: false # # Set to true if you need screenshots for every selenium command ran
+networkLogs: false # Set to true to enable HAR logs capturing
+consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors)
+# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
diff --git a/NUnit-BrowserStack/local.log b/NUnit-BrowserStack/local.log
deleted file mode 100644
index e69de29..0000000
diff --git a/NUnit-BrowserStack/packages.config b/NUnit-BrowserStack/packages.config
deleted file mode 100644
index 28fe1a7..0000000
--- a/NUnit-BrowserStack/packages.config
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/README.md b/README.md
index 96ff009..2e731cf 100644
--- a/README.md
+++ b/README.md
@@ -3,30 +3,56 @@

-
+
-## Setup
+## Run Sample Build
* Clone the repo
* Open the solution `NUnit-BrowserStack.sln` in Visual Studio
* Build the solution
-* Update `App.config` file with your BrowserStack Username and Access Key(https://www.browserstack.com/accounts/settings)
-
-## Running your tests from Test Explorer via NUnit Test Adapter
-- To run tests, run tests with fixture `parallel`
-- To run local tests, run test with fixture `local`
+* Update `browserstack.yml` file with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
+### Running your tests from CLI
+* To run the test suite having cross-platform with parallelization, dotnet test --filter "Category=sample-test"
+* To run local tests, dotnet test --filter "Category=sample-local-test"
+### Running your tests from Test Explorer
+- To run a parallel tests, run test with fixture `sample-test`
+- To run local tests, run test with fixture `sample-local-test`
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
+## Integrate your test suite
+
+This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
+
+* Create sample browserstack.yml file with the browserstack related capabilities with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) and place it in your root folder.
+* Add nuget library BrowserStack.TestAdapter
+```sh
+dotnet add BrowserStack.TestAdapter
+```
+* Build project `dotnet build`
+
## Notes
* You can view your test results on the [BrowserStack automate dashboard](https://www.browserstack.com/automate)
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/c-sharp#setting-os-and-browser)
* You can export the environment variables for the Username and Access Key of your BrowserStack account
+ * For Unix-like or Mac machines:
```
export BROWSERSTACK_USERNAME= &&
export BROWSERSTACK_ACCESS_KEY=
```
+ * For Windows Cmd:
+ ```
+ set BROWSERSTACK_USERNAME=
+ set BROWSERSTACK_ACCESS_KEY=
+ ```
+
+ * For Windows Powershell:
+ ```
+ $env:BROWSERSTACK_USERNAME=
+ $env:BROWSERSTACK_ACCESS_KEY=
+ ```
+
## Additional Resources
* [Documentation for writing automate test scripts in C#](https://www.browserstack.com/automate/c-sharp)
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)