Skip to main content

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:

  1. Prerequisites to run test in BrowserStack
  2. Steps to run your first local test

Prerequisites

If you have already run your first test, you can skip the prerequisites.

Run your first local test

To run Selenium local tests with XUnit on BrowserStack Automate, complete the following steps:

  1. Clone the xunit-browserstack repository sample repository on GitHub using the following command:

     git clone https://github.com/browserstack/xunit-browserstack.git
    
  2. Open the solution XUnit-BrowserStack.sln in Visual Studio.

  3. Set the local capability to true 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
       }
     }
    
  4. 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 the xunit-browserstack/Xunit-BrowserStack/ directory:

    LocalTest.cs
       using 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;
                   }
               }
           }
       }
    
  5. 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:

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy