---
title: Selenium C# tests in CI | Selenium C# Tutorial with NUnit
description: A suite that only runs when someone remembers to run it decays quickly.
  This chapter runs it on every push and pull request, first with GitHub Actions and…
source_url:
  html: https://testingbot.com/resources/courses/selenium-csharp/ci-with-github-actions
  md: https://testingbot.com/resources/courses/selenium-csharp/ci-with-github-actions.md
---

Course

[Selenium C# Tutorial with NUnit](https://testingbot.com/resources/courses/selenium-csharp)

Chapter 9 of 10

1. [1 Selenium C# Tutorial with NUnit](https://testingbot.com/resources/courses/selenium-csharp)
2. [2 Set up .NET, Selenium and NUnit](https://testingbot.com/resources/courses/selenium-csharp/setup-and-first-test)
3. [3 Selenium C# locators and WebDriverWait](https://testingbot.com/resources/courses/selenium-csharp/locators-and-waits)
4. [4 NUnit fixtures, attributes and [TestCase] ](https://testingbot.com/resources/courses/selenium-csharp/nunit-fixtures-and-attributes)
5. [5 NUnit assertions and screenshots on failure](https://testingbot.com/resources/courses/selenium-csharp/assertions-and-screenshots)
6. [6 Page objects in C#](https://testingbot.com/resources/courses/selenium-csharp/page-objects)
7. [7 Run Selenium C# tests on the TestingBot grid](https://testingbot.com/resources/courses/selenium-csharp/run-on-testingbot)
8. [8 Parallel Selenium tests with NUnit](https://testingbot.com/resources/courses/selenium-csharp/parallel-tests)
9. [9 Selenium C# tests in CI](https://testingbot.com/resources/courses/selenium-csharp/ci-with-github-actions)
10. [10 Selenium C# Quiz](https://testingbot.com/resources/courses/selenium-csharp/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 9 of 10 Intermediate 6 min read 2 quick checks Updated Nov 2026 

# Selenium C# tests in CI
On this page
1. [Store the credentials](https://testingbot.com#store-the-credentials)
2. [The GitHub Actions workflow](https://testingbot.com#the-github-actions-workflow)
3. [The same in Azure Pipelines](https://testingbot.com#the-same-in-azure-pipelines)
4. [What we ran](https://testingbot.com#what-we-ran)
5. [Where to go from here](https://testingbot.com#where-to-go-from-here)

A suite that only runs when someone remembers to run it decays quickly. This chapter runs it on every push and pull request, first with GitHub Actions and then with Azure Pipelines, keeping the test results and failure screenshots of every run.

The plan is the same on any CI system:

1. Install the .NET SDK.
2. Pass the TestingBot credentials in as secret environment variables.
3. Run `dotnet test` with `GRID=testingbot`, a build name unique to the run and a TRX logger.
4. Upload the `TestResults` folder even when tests fail, because that is when you need it.

A CI agent usually has no desktop and only a few cores, so running the browsers on the grid rather than on the agent keeps the job small and gives you browsers the agent does not have, such as Safari.

## Store the credentials[#](https://testingbot.com#store-the-credentials)

In GitHub, open the repository's Settings, then Secrets and variables, then Actions, and add `TB_KEY` and `TB_SECRET`. Never put them in the workflow file, in `appsettings.json` or in a `.runsettings` file that is committed: anything in the repository is readable by everyone who can clone it, and stays in its history.

## The GitHub Actions workflow[#](https://testingbot.com#the-github-actions-workflow)

Add `.github/workflows/ui-tests.yml`:

```yaml
name: UI tests
on: [push, pull_request]

jobs:
  selenium:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        browser: [chrome, firefox]
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-dotnet@v6
        with:
          dotnet-version: "10.0.x"
      - run: dotnet restore
      - run: dotnet build --no-restore
      - name: Run the suite on TestingBot
        env:
          GRID: testingbot
          BROWSER: ${{ matrix.browser }}
          TB_KEY: ${{ secrets.TB_KEY }}
          TB_SECRET: ${{ secrets.TB_SECRET }}
          TB_BUILD: github-${{ github.run_id }}-${{ github.run_attempt }}
        run: >
          dotnet test --no-build
          --logger "trx;LogFileName=${{ matrix.browser }}.trx"
          --logger "console;verbosity=normal"
          -- NUnit.NumberOfTestWorkers=2
      - uses: actions/upload-artifact@v7
        if: always()
        with:
          name: test-results-${{ matrix.browser }}
          path: "**/TestResults/"
```

What each part does:

- **The matrix** runs the job once per browser, in parallel jobs. `fail-fast: false` keeps the Firefox job running when the Chrome job fails, so one run tells you whether a failure is browser-specific.
- **`TB_BUILD`** from the run ID and attempt groups every session of one workflow run, from both matrix jobs, into one TestingBot build. A re-run gets a new build.
- **`NUnit.NumberOfTestWorkers=2`** per job. Two jobs times two workers is four sessions at once; keep the product at or below your plan's parallel limit.
- **`--no-build`** reuses the build from the previous step, so a compile error fails the Build step with a clear message instead of appearing in the middle of the test output.
- **`if: always()`** uploads the TRX files and screenshots even when the test step failed.

`dotnet test` exits with a non-zero code when any test fails, which fails the job and, on a pull request, the check. GitHub does not display TRX files itself: download the artifact and open it in Visual Studio or Rider, or add a test-report action from the Marketplace that renders TRX as a check summary. The [GitHub Actions guide](https://testingbot.com/support/integrations/ci-cd/github-actions) adds the TestingBot Tunnel action, for testing a site that runs inside the job, and pull request status checks.

Tests fail in CI, but the uploaded artifact is missing from the run. The upload step has no `if:` condition. Why?

 Steps are skipped after a failed step unless they use `if: always()` (or `failure()`), so the upload never ran. TRX files are only written when all tests pass. The artifact is only uploaded on the default branch.

GitHub Actions stops running later steps once one fails. The TRX logger writes its file whatever the outcome; the step that would have uploaded it was simply skipped.

## The same in Azure Pipelines[#](https://testingbot.com#the-same-in-azure-pipelines)

Teams on Azure DevOps get one more thing for free: the test results tab. Add a pipeline variable group or pipeline variables `TB_KEY` and `TB_SECRET`, marked secret, and an `azure-pipelines.yml`:

```yaml
trigger: [main]
pr: [main]

pool:
  vmImage: ubuntu-latest

steps:
  - task: UseDotNet@2
    inputs:
      version: "10.0.x"

  - task: DotNetCoreCLI@2
    displayName: Run the suite on TestingBot
    inputs:
      command: test
      arguments: "-- NUnit.NumberOfTestWorkers=2"
      publishTestResults: true
    env:
      GRID: testingbot
      BROWSER: chrome
      TB_KEY: $(TB_KEY)
      TB_SECRET: $(TB_SECRET)
      TB_BUILD: azure-$(Build.BuildId)
```

`trigger` runs the pipeline on pushes to `main` and `pr` on pull requests into it. The `pr` key works for repositories hosted on GitHub; for Azure Repos Git it is ignored, and pull request runs are set up with a build validation branch policy on `main` instead. The `DotNetCoreCLI@2` test command adds a TRX logger itself and, with `publishTestResults: true`, publishes the results to the run's Tests tab. The `env:` block matters: Azure Pipelines does **not** expose secret variables to scripts and tasks as environment variables unless you map them explicitly like this. Without it, `DriverFactory.Required` fails with "Set the TB\_KEY environment variable". The [Azure DevOps guide](https://testingbot.com/support/integrations/ci-cd/azure) covers TestingBot's Marketplace extension, which can set `TB_KEY` and `TB_SECRET` from a service connection and start the tunnel for a build.

## What we ran[#](https://testingbot.com#what-we-ran)

The workflow files above were checked for valid YAML, and their commands were run locally with the same environment variables (`dotnet restore`, `dotnet build --no-restore`, then `dotnet test --no-build` with both loggers and `GRID=testingbot`, using one worker because the account was shared). They were not run inside GitHub Actions or Azure Pipelines for this course; the action and task versions are the current major releases as of November 2026.

A new Azure pipeline fails every test in SetUp with "Set the TB\_KEY environment variable", although `TB_KEY` is defined as a secret pipeline variable. What is missing?

 The secret must be renamed to `TB_KEY_SECRET`. An `env:` mapping such as `TB_KEY: $(TB_KEY)` on the test task; secret variables are not passed to tasks as environment variables automatically. A `.runsettings` file containing the key.

Azure keeps secrets out of the environment unless a step maps them in. The explicit mapping is the fix; committing the key in a `.runsettings` file would leak it to everyone with repository access.

## Where to go from here[#](https://testingbot.com#where-to-go-from-here)

The suite now runs locally, in parallel, on a cloud grid and in CI. From here, the work is in what you test rather than how: the [Page Object Model course](https://testingbot.com/resources/courses/page-object-model) for structure as the suite grows, [cross-browser testing](https://testingbot.com/resources/courses/cross-browser-testing) for choosing the browser matrix, and the [flaky tests course](https://testingbot.com/resources/courses/flaky-tests) for keeping it trustworthy. The last chapter is a quiz on the decisions this course made.

[Previous · Chapter 8 Parallel Selenium tests with NUnit](https://testingbot.com/resources/courses/selenium-csharp/parallel-tests) [Next · Chapter 10 Selenium C# Quiz](https://testingbot.com/resources/courses/selenium-csharp/knowledge-check)

On this page

1. [Store the credentials](https://testingbot.com#store-the-credentials)
2. [The GitHub Actions workflow](https://testingbot.com#the-github-actions-workflow)
3. [The same in Azure Pipelines](https://testingbot.com#the-same-in-azure-pipelines)
4. [What we ran](https://testingbot.com#what-we-ran)
5. [Where to go from here](https://testingbot.com#where-to-go-from-here)

Certification

Earn the free, resume-worthy TestingBot Selenium C# Certification for this course.

[How it works](https://testingbot.com/resources/courses/selenium-csharp/certification)
