Learn how to run C# scripts using the xUnit framework.
Blog ⋅ Docs ⋅ Learning Hub ⋅ Newsletter ⋅ Certifications ⋅ YouTube
Before you start performing C# automation testing with Selenium using xUnit, you need to:
- Download and install Selenium WebDriver from its official website.
- Ensure you have the latest version of C#.
- .NET framework for guidelines while developing a range of applications using C#.
- Download Selenium WebDriver Language Binding for C# and extract them to the appropriate folder. Require a .NET Core SDK of 8.0 or greater version.
Step 1: Clone the LambdaTest CSharp-xUnit-Selenium GitHub repository and navigate to the code directory:
git clone https://github.com/LambdaTest/CSharp-xUnit-Selenium
cd CSharp-xUnit-Selenium
Ensure you have your LambdaTest credentials to run C# automation scripts. Obtain these credentials from the LambdaTest Automation Dashboard or your LambdaTest Profile.
Step 2: Set your LambdaTest Username and Access Key in environment variables.
For Linux/macOS:
export LT_USERNAME="YOUR_USERNAME"
export LT_ACCESS_KEY="YOUR_ACCESS_KEY"
For Windows:
set LT_USERNAME="YOUR_USERNAME"
set LT_ACCESS_KEY="YOUR_ACCESS_KEY"
Test Scenario: Check out the sample SingleTest.cs file. This xUnit Selenium script tests a sample to-do list app by marking a couple of items as done, adding a new item to the list, and finally displaying the count of pending items as output.
Step 3: Navigate to config.json using VSCode. Replace this code in the config.json file in your project.
Step 4: In the config, update your test capabilities. We are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via the capabilities object.
Example capabilities object:
{
"server": "hub.lambdatest.com",
"user": "LT_USERNAME",
"key": "LT_ACCESS_KEY",
"capabilities": {
"lt:options": {
"buildName": "xunit build",
"sessionName": "lambdatest xunit sample test",
"visual": "true",
"plugin": "xunit:sample"
}
},
"environments": [
{
"browserName": "chrome"
},
{
"browserName": "firefox"
},
{
"browserName": "safari"
}
],
"TunnelOptions": {
"tunnel": false
}
}
Note: Generate capabilities for your test requirements with the help of the Desired Capability Generator.
Step 5: Build the solution in Visual Studio.
Step 6: Run the
tests from the Test Explorer in Visual Studio.
- Clean and rebuild the project.
dotnet clean
- Execute Single Test
dotnet test --filter "profile=single"
Executing Parallel tests in Windows
Run all tests from the Test Explorer in Visual Studio for parallel execution.
Executing parallel tests in Linux/MacOS
dotnet test --filter "profile=parallel"
For testing locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel, follow the LambdaTest Tunnel documentation.
Download the LambdaTest Tunnel binary for your OS and run the following command:
LT -user {user’s login email} -key {user’s access key}
Tunnel Capability
"lt:options": {
"buildName": "xunit build",
"sessionName": "lambdatest xunit sample test",
"visual": "true",
"plugin": "xunit:sample",
"tunnel": "true"
}
coming soon
Subscribe To Our LambdaTest YouTube Channel 🔔 for the latest video tutorials.
Join the LambdaTest Community to interact with tech enthusiasts. Connect, ask questions, and learn from professionals worldwide.
Stay updated with the latest features and product add-ons at Changelog.
LambdaTest is a leading test execution and orchestration platform. It allows users to run both manual and automated testing of web and mobile apps across various browsers, operating systems, and real device combinations. Over 500 enterprises and 1 million+ users across 130+ countries rely on LambdaTest for their testing needs.
- Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
- Real-time Cross-browser testing on 3000+ environments.
- Test on Real device cloud.
- Blazing fast test automation with HyperExecute.
- Accelerate testing, shorten job times, and get faster feedback on code changes with Test At Scale.
- Smart Visual Regression Testing on the cloud.
- 120+ third-party integration with your favorite tools for CI/CD, Project Management, Codeless Automation, and more.
- Automated Screenshot testing across multiple browsers in a single click.
- Local testing of web and mobile apps.
- Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
- Geolocation testing of web and mobile apps across 53+ countries.
- LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports.
- Have a query? We are available 24x7 to help. Contact Us
- For more info, visit LambdaTest