-
Key Features and
Create a new project in Visual Studio 2022 - Naming Standards & Comments
- Data Types
- Variables and Constant Variable
- Conditional Statement
- Switch Conditional Statement
- Arithmetic, Comparison, Assignment and Logical Operators
- For, While and Do While Loops
- Importance of Break and Continue Keywords
- Strings and Important String Methods
- Single Dimensional Array
- Multi Dimensional Array
- Methods and Method Overloading
- Math Class and Functions
- Casting and Type Conversions
- Class and Objects
- Constructor, Parameter less and Parameterized Constructor
- Single, Multi level and Hierarchical Inheritance
- Compile Time Polymorphism, Method and Operator Overloading
- Run-time Polymorphism and Importance of base keyword
- Abstract Class and Method
- Interface and Multiple Inheritance through Interfaces
Agenda
- What is C# and useful for automation testing?
- C# Key Features
- Introduction to Visual Studio
- Pre-requisites for Visual Studio 2022 Installation
- Installation Steps for Visual Studio 2022
- Create a new project in Visual Studio
- Write a sample test script using C#
What is C# and useful for automation testing?
C# or C-Sharp is an object-oriented programming language derived from C++ and Java. C# allows developers to build applications using Visual Studio on . Net platform. C# is used to develop web apps, desktop apps, mobile apps, games and much more.
Why Use C#?:
- It is one of the most popular programming language in the world
- It is easy to learn and simple to use
- It has a huge community support
- C# is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs.
- As C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa
Why is C# useful for automation testing?
- C# is useful for automation testing because it allows the automation test engineer to develop an application with the help of Visual Studio on the .Net framework.
- C# is another programming language that also supports the binding with Selenium.
- IC# IDE is Visual Studio, which gives faster development and debugging experience as compared to java's Eclipse.
- C# has a lot of inbuilt functions, which make the development fast.
C# Key Features
- Simple: C# is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functions, data types etc.
- Modern Programming Language: C# programming is based upon the current trend and it is very powerful and simple for building scalable, interoperable and robust applications.
- Object Oriented: C# is object oriented programming language. OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grow.
- Type Safe: C# type safe code can only access the memory location that it has permission to execute. Therefore it improves a security of the program.
- Scalable and Updateable: C# is automatic scalable and updateable programming language. For updating our application we delete the old files and update them with new ones.
- Component Oriented: C# is component oriented programming language. It is the predominant software development methodology used to develop more robust and highly scalable applications.
- Structured Programming Language: C# is a structured programming language in the sense that user can break the program into parts using functions. So, it is easy to understand and modify.
- Fast Speed: The compilation and execution time of C# language is fast.
Introduction to Visual Studio
Visual Studio is an IDE developed by Microsoft. Its popularity comes from offering unique features such as cloud connectivity, supported extensions, easy debugging, collaboration, deployment, and version control integration, among others. Visual Studio is available for both Windows and Mac. It can be used for mobile, web, cloud, desktop applications, and gaming application development.
Visual Studio is available in both Free and Paid versions. The free version comes with basic features, whereas the paid version comes with enterprise features.
Benefits of Visual Studio:
- Easy to Install: Visual studio is easy to install. It comes with a platform-specific installer. Simply follow the on-screen instructions during installation.
- Easy to Set up: Visual Studio comes with default templates. To create a new project, a user can choose from many available templates. The IDE will do the basic configuration to get it ready for usage.
- Extendable: Visual Studio supports thousands of extensions. Just hook into the IDE and customize them.
- IntelliSense: Visual Studio supports modern IntelliSense for many languages, which makes coding easier.
- Version Control: Users can integrate version control tools like Git and easily manage them.
- Live Share Support: Users can share their code in real-time which facilitates collaboration.
- Testing: Visual Studio makes Test Driven Development easier with its built-in testing tools. Users can write unit and integration tests quickly.
- Cloud Support: Integrate this IDE with cloud providers such as Azure, making development and deployment more straightforward and faster.
- Developer Friendly: Visual Studio offers various features for development such as easy refactoring, code clean up, etc.
- Setting up Selenium and Visual Studio: Selenium is the most popular end-to-end automation testing tool in existence. It supports the most popular programming languages – C#, Java, Python, JavaScript, and many more.
Pre-requisites for Visual Studio 2022 Installation
Make sure user computer is ready for Visual Studio installation with the below details:
Check the below system requirements.
- Windows 11 version 21H2 or higher
- 64-bit ARM operating system
- Minimum of 4 GB of RAM
- Minimum of 850 MB up to 210 GB of available hard disk space
- ARM64 processor or 1.8 GHz or faster x64 processor (quad-core or better recommended). ARM32 processors are not supported.
- Administrator rights are required to install or update Visual Studio.
Apply the latest Windows updates. These updates ensure that user computer has both the latest security updates and the required system components for
Visual Studio.
Reboot system which ensures that any pending installs or updates don’t hinder your Visual Studio install.
Free up space. Remove unneeded files and applications from your system drive by, for example, running the Disk Cleanup app.
Installation Steps for Visual Studio 2022
- Navigate to https://visualstudio.microsoft.com/
- Click on Download button and then Community 2022 option
- From your Downloads folder double click on the VisualStudioSetup
- Click Continue button
- Select the Visual Studio Community 2022 and click on the Install button
- Review the workload summaries and check .NET desktop development and Universal Windows Platform Development check boxes
- Select Install
- Restart user system
- Go to Start Menu and Select Visual Studio 2022
Create a new project in Visual Studio
- In the File Menu, Click New > Project. The Create a new project window opens and it will shows several project templates. A template contains the basic files and settings required for a given project type. Here, you can search, filter, and pick a project template.
- In the search box at the top, enter in console to filter the list of project types. Further refine the search results by picking C# from the All language dropdown list and select Windows platform options from All platforms drop-down list.
- Select the Console App (.NET Framework) template, and then choose Next
- Enter appropriate Project Name in the Configure your new project window, and then choose Next.
- The project should be created successfully. Select the code file Program.cs in the Solution Explorer window (right-hand side of Visual Studio).
- The file Program.cs opens in the Editor window. The Editor shows the contents of files and the area where user will perform coding work in Visual Studio.
Write a sample test script using C#
- using System means that user can use classes from the System namespace.
- namespace is used to organize user code, and it is a container for classes and other namespaces.
- The curly braces {} marks the beginning and the end of a block of code.
- class is a container for data and methods, which brings functionality to user program. Every line of code that runs in C# must be inside a class. Another thing that always appear in a C# program, is the Main method. Any code inside its curly brackets {} will be executed.
- static is a keyword which means object is not required to access static members. So it saves memory.
- void is the return type of the method. It doesn't return any value. In such case, return statement is not required.
- Main is the method name. It is the entry point for any C# program. Whenever we run the C# program, Main() method is invoked first before any other method. It represents start up of the program.
- string[] args is used for command line arguments in C#. While running the C# program, user can pass values. These values are known as arguments which we can use in the program.
- Console is a class of the System namespace, which has a WriteLine() method that is used to output/print text.
- User would have to write Console.WriteLine() to print/output text.
- Use Console.ReadKey() to display the output in console
- Every C# statement ends with a semicolon ;.
- C# is case-sensitive: "MyClass" and "myclass" has different meaning.