Run C# Visual Studio Code

broken image


  1. Run C# Visual Studio Code
  2. How To Use Visual Studio Code

Prerequisites for running a C program in Visual Studio Code. We should have a basic knowledge of. Type C#, it should look like so: Good, now we are set up and ready code 😃 # Creating a solution. The first we will do is to create a solution. A solution is something we use to keep track of all related projects. As an old.NET developer you might be used to do this via Visual Studio but we will actually do.

Run C# Visual Studio Code
Run C# Visual Studio Code
Running

Run C# Visual Studio Code

How to run c# program in visual studio code in ubuntu

Run C# Visual Studio Code

Selenium is an open-source web automation library. It supports many browsers like Chrome, Firefox, Edge etc and many languages – python, java, C#, javascript etc. Here we will get to know How you can use selenium with C# in Visual studio code.

Prerequisites for selenium with C#.

  1. Visual studio code (https://code.visualstudio.com/download)
  2. Dotnet sdk (https://dotnet.microsoft.com/download/dotnet-core)
  3. Visual C++ Redistributable for Visual Studio 2015 (In case of geckodriver) (https://www.microsoft.com/en-in/download//details.aspx?id=48145)
  4. Driver(Geckodriver, chromedriver)

Steps of Installation.

How To Use Visual Studio Code

  1. Create a Folder with name 'demoProjects' in any drive(can create a folder with any name according to you).
  2. Open VS Code and select the ‘demoProject' folder that you had created recently.
    1. Open VS Code and Click on ‘File' Tab from the menu bar.
    2. Click on ‘Open Folder' from options list.
    3. Navigate to the recently created folder and Select Folder.
  3. Add Visual studio code extensions to get it supported.
    C# and NuGet Package Manager
    1. To add 'C#' extensions click on extension button in VS code.
    2. Enter C# in the Input box and select the top most option of C# from results.
    3. Click on install button and wait till it add related packages. It will show a success message about installation.
    4. Follow the same steps from above to add 'NuGet Package Manager' extension. Enter Nuget package manager in the input box and install it.
  4. Once the above installation is completed, Create a New Folder under demoProject and name it ‘FirstTest' or with any name, Then open Terminal from View (menu bar). Go to 'FirstTest' directory by 'cd FirstTest' and trigger the below command to auto generate the related files which will help to run the tests.
    dotnet new console
  5. Now Add selenium Package to the project. Click on ‘View' from the menu bar, Select Command Palette option. Enter ‘NuGet package manager' into the input box.
    1. Select ‘Nuget package manager: Add package' from result options.
    2. After selecting, An input box will open then enter 'Selenium' and Press Enter key.
    3. It will show all package related to selenium from which, select ‘Selenium Webdriver'. Then select version according to your dotnet sdk version.
    4. After selecting version, a pop up will be shown with asking permission to fix unresolved dependencies. Click on the restore button.
  6. Either you can run the same ‘hello world' program to verify it is configured or you can insert the selenium C# test script.
    1. I am sharing an example of C# tests that will launch google and search ‘Fleek IT Solutions'.

      Note: You may have to adjust the path string according to your geckodriver and firefox.exe.

  7. To run your tests, either you can use debugger or command from the terminal. To run tests trigger the below command.
    dotnet runHitting the above command will start running your tests, and launch firefox to execute test steps.
    If there is no error, then after executing all steps it will close firefox and print a success message. And if it finds any error then it will show all error messages with the number of line where error took place. Have a look at the following image. I have run tests twice to show Pass and Fail of tests, first time without changes (correct program) and the second time with removing Locator id to show Fail message.
    [Passed tests]
    [Failed tests]




broken image