Skip to content

fezza74/seleniumcs-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

347c58d · Jun 4, 2024

History

8 Commits
May 31, 2024
Jun 4, 2024

Repository files navigation

Selenium c# Settings

Settings to use Selenium c# with Visual Studio Code


Before all you need of Visual Studio Code (VSC), if you haven'yet!

Table of contents

  1. Install .NET SDK
  2. Install C# and Nuget
  3. Create a MSTest Project
  4. Add Selenium WebDriver package to the TestProject

Install .NET SDK

To install .net SDK click on this link (https://dotnet.microsoft.com/en-us/download/) and follow the instruction

After that, to verify the installation open the terminal and digit:

dotnet --version

TOP

Install CS and Nuget

To install C# on VSC press CMD+SHIFT+X(for mac) and search for C#

Click on Install (if you haven't yet)

Repeat for the NuGet Package Manager

TOP

Create a MSTest Project

From terminal

From VSC

TOP

Create Project from terminal

From the terminal digit this

dotnet new mstest -o FirstSeleniumTest

The output will be like this

The template "MSTest Test Project" was created successfully.

Processing post-creation actions...
Restoring /Users/giannifezza/Documents/HelloSeleniumTest/FirstSeleniumTest.csproj:
  Determining projects to restore...
  Restored /Users/giannifezza/Documents/HelloSeleniumTest/FirstSeleniumTest.csproj (in 233 ms).
Restore succeeded.

Now, in VSC, open the folder you just created

TOP

Create Project from VSC

The .NET Install Tool, C# Dev Kit extensions are required

By .NET Install Tool you can open the Command Palette and select .NET:New Project... and then MSTest Test Project and provide Name and Location for the new project. This will create a new project and directory that uses MSTest as the test libray and configure the test runner (UnitTest1.cs)

C# Dev Kit will generate shortcuts (the green play button) on the left side of the class and method definition. You can run the target test cases, selecting the green play button. You can also right-click on it to see more options (like Debug Test)

You can also run the target test cases by Test Explorer. This is a tree view to show all the test cases in your workspace. You can select the beaker button on the left-side Activity bar of Visual Studio Code to open it. You can also run/debug your test cases and view their test results from there

TOP

Add Selenium WebDriver package to the TestPorject

To run Selenium C# tests we can use different browsers (Chrome in this tutorial, but the steps are similar for all)

We need to:

  • Chrome browser
  • ChromeDriver for matching browser version is in the PATH
  • Selenium WebDriver library is installed and configured in the test project

To do this press CMD+SHIFT+P (for mac, or CTRL+P for Windows)

Select in the bar NuGet Package Manager: Add Package then type Selenium and press Enter

Press Enter to select Selenium.WebDriver and then select the latest version of this

if appears a popup, click Restore

Now you are ready to get started!

TOP

About

Settings to use Selenium c# with Visual Studio Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published