Your ultimate guide

C# With NUnit _ Basics and NuGet

How to add a new Class in Visual Studio?

            Right-click on your project > Click on Add > Select New item > from that option select class > and Click on Add.


    Basic Example Program:
using System;
namespace <project name>
     {
        class ClassName
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello World");
            }
        }
     }

  • In CSharp if you want to print any item we will use “Console.WriteLine();”.
  • Here Console is the class that can help to debug and write any statement to the output.
  • WriteLine is the method.

 



Normally When we run the C# program, one Console tab will be opened that will give the output.

If you want to get output in Debug tap in visual studio, then instead of using Console.WriteLine() use Debug.WriteLine().

To use Debug class to access this class we need to import “using System.Diagnostics;”.



 

namespace:

            namespace helps us to logically arrange the class, interfaces, enum, … whatever you have in C# object-oriented programming all those will hold here.

using: (in java import)

    In java to import any package we use the import keyword, the same as in C# we will use using keyword. 

 

using System;

Console.WriteLine();

        (Or)

System.Console.WriteLine();

 



NuGet:

What is NuGet?
    NuGet is the package manager for the .NET.

In general, In java, we have a Maven repository where you upload all the JARs.
In JavaScript, we have an NPM repository,
In C# which uses the .NET package, all the .NET packages are available in the NuGet gallery.

 

How to add selenium packages in C#? (In java we called as JAR files, in C# we called as packages)
In C# we can add packages in two ways:
   
 Way 1:

  • Goto NuGet official website https://nuget.org
  • Search the package “Selenium WebDriver”
  • Select .NET CLI then we get the install-package command Copy that command.
  • Now open Visual Studio, and then select Tools → NuGet Package Manager  Package manager console.
  • Past the install command into the Package Manager Console and then press Enter.
      Way 2:

  • In your Visual Studio, Right click on your project  Click on Manage NuGet Packages.
  • Then the NuGet Package manager window will open, and it will connect to the NuGet website). Type “Selenium WebDriver” in the Search box → select that particular package  and click on Add Package.\
  • Once download the package will see that package in the Dependencies folder
  • (or) right-click on your project folder, and select Edit Project file there we see all the package information.

- Next Page: Basics 2

No comments:

Post a Comment