Test on Internal Networks
BrowserStack enables you to run your XUnit automated tests on your internal development environments, on localhost, and from behind a corporate firewall. This feature is called “Local Testing”.
Local Testing establishes a secure connection between your machine and the BrowserStack cloud. Once you set up Local Testing, all URLs work out of the box, including HTTPS URLs and those behind a proxy or firewall.
In this guide, you will learn about:
Prerequisites
If you have already run your first test, you can skip the prerequisites.
- BrowserStack Username and Access key, which you can find in your account settings. If you have not created an account yet, you can sign up for a Free Trial or purchase a plan.
-
XUnit
andXUnit.Runner
is installed from the NuGet Gallery. - Visual Studio is installed.
Run your first local test
To run Selenium local tests with XUnit on BrowserStack Automate, complete the following steps:
-
Clone the xunit-browserstack repository sample repository on GitHub using the following command:
git clone https://github.com/browserstack/xunit-browserstack.git
-
Open the solution
XUnit-BrowserStack.sln
in Visual Studio. -
Set the
local
capability totrue
in your XUnit config file,config.json
:{ "server": "hub.browserstack.com", "user": "YOUR_USERNAME", "key": "YOUR_ACCESS_KEY", "capabilities": { "bstack:options": { "buildName": "xunit-browserstack", "sessionName": "test", "debug": "true", "local": "true", } }, "environments": [ { "browserName": "chrome" }, { "browserName": "firefox" }, { "browserName": "safari" } ], "localOptions": { "forceLocal": true } }
-
Run a sample test case to verify if the Local test connection is setup correctly. You can use the following sample test case,
LocalTest.cs
, which can be found in thexunit-browserstack/Xunit-BrowserStack/
directory:LocalTest.csusing Xunit; using OpenQA.Selenium.Remote; using System.Text.RegularExpressions; namespace XUnit_BrowserStack { public class LocalTest : IClassFixture<BaseFixture> { private readonly BaseFixture baseFixture; public LocalTest(BaseFixture baseFixture) { this.baseFixture = baseFixture; } [Fact] [Trait("profile", "local")] public void Test() { try { RemoteWebDriver driver = baseFixture.GetDriver("chrome", "local"); driver.Navigate().GoToUrl("http://bs-local.com:45691/check"); bool isUpAndRunning = Regex.IsMatch(driver.PageSource, "Up and running", RegexOptions.IgnoreCase); Assert.True(isUpAndRunning); baseFixture.SetStatus(isUpAndRunning); } catch (Exception) { baseFixture.SetStatus(false); throw; } } } }
-
Run your local test on BrowserStack using the following command:
dotnet test --filter "profile=local"
Next steps
After you have successfully run your local test on BrowserStack, you might want to do one of the following:
- Set Local flags if you are using a Local binary to run your test.
- Run multiple tests in parallel to speed up builds
- Generate a list of capabilities that you want to use in tests
- Find information about your Projects, Builds and Sessions using our REST APIs
- Set up your CI/CD: Jenkins, Bamboo, TeamCity, Azure, CircleCI, BitBucket, TravisCI, GitHub Actions.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!