Explore 1.5M+ audiobooks & ebooks free for days

Only $12.99 CAD/month after trial. Cancel anytime.

Selenium with C#: Learn how to write effective test scripts for web applications using Selenium with C# (English Edition)
Selenium with C#: Learn how to write effective test scripts for web applications using Selenium with C# (English Edition)
Selenium with C#: Learn how to write effective test scripts for web applications using Selenium with C# (English Edition)
Ebook476 pages1 hour

Selenium with C#: Learn how to write effective test scripts for web applications using Selenium with C# (English Edition)

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Selenium, a web browser automation tool that has been around for a long time, is extensively utilized by developers and testers to generate automated tests for verifying the proper functioning of web applications. When combined with C#, Selenium can produce automated tests that are both robust and efficient.

This book is a comprehensive guide to learning Selenium, one of the most popular web automation tools in the industry. It starts with an introduction to Selenium and its three projects - Selenium IDE, Selenium WebDriver, and Selenium Grid. It then provides a comprehensive overview of the various entities in the Selenium C# client libraries, such as the WebDriver, WebElement, and By classes. The subsequent sections of the book elucidate how to handle different HTML elements, including forms, tables, dropdowns, windows, alerts, and frames. The book also explores the Option class, which is utilized for managing web browsers. In addition, the book emphasizes the significance of unit testing in test automation and explains how to implement the NUnit framework. To manage object information, the book delves into the Page Object model design pattern. Lastly, the book will help you set up and execute tests in parallel across various environments using Selenium Grid.

By the end, you will be able to create automated tests for web applications with ease.
LanguageEnglish
PublisherBPB Online LLP
Release dateMay 4, 2023
ISBN9789355518217
Selenium with C#: Learn how to write effective test scripts for web applications using Selenium with C# (English Edition)
Author

Pallavi Sharma

Dr. Pallavi Sharma is Professor at the School of Environment and Sustainable Development, Central University of Gujarat, India. Dr. Sharma is currently engaged in work on the mechanisms of abiotic stress tolerance in plants. She has published 50 scientific articles/book chapters in peer-reviewed journals/books with more than 7,600 citations.

Related to Selenium with C#

Related ebooks

Software Development & Engineering For You

View More

Reviews for Selenium with C#

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Selenium with C# - Pallavi Sharma

    Chapter 1

    Introduction to the Selenium Project

    Selenium is a popular automation tool to drive the web browser. For more than a decade, it has been widely used by testers across the world to improve the work they perform. Web automation using Selenium is popularly used by organizations by creating an automation ecosystem around it using various other open-source or paid technologies. To understand and use Selenium, we must be aware of the programming language. This book targets the users of the CSharp language who would like to use Selenium to automate the web browser. This book also targets testers who use the CSharp language to build the automation process around their work and would want to use Selenium to automate the web browser. In this chapter, we will investigate the Selenium project, and understand the structure of the Selenium CSharp library. We will also see how we set up our project using Visual Studio. Finally, we will take a walk-through of the web application we will be using frequently to understand various automation concepts for tests.

    Structure

    This chapter is divided into the following sections-

    Selenium Project

    Understand the Selenium Library in CSharp

    Setting the Automation Project in Visual Studio

    Objectives

    After completing this chapter, you will be able to understand what a Selenium Project is and what the Selenium library of CSharp is. You will also understand how to set the system to get started with writing the first program in CSharp for automating the web browser.

    Selenium project

    Selenium, the stories behind how and why this name was chosen are many. The most famous is that Selenium the element is considered an antidote for Mercury. At the time of the creation of Selenium by Jason Huggins, while he was working with Thoughtworks, the automation tools from the Mercury organization were quite popular and at the same time, their licenses were expensive. So, as a cure for tools by Mercury, Selenium could be used. Selenium was then released as Selenium 1.0 and since then various releases of Selenium have been done. The latest version is Selenium 4.0. In the various releases of Selenium, the release 2.0 and 3.0 are considered to be milestones. It is in these releases Selenium married Webdriver, a solution created by Simon Stewart. With Selenium 3.0 release it became a W3C standard, which meant that any web browser which is compatible with the W3C standards will be compatible with Selenium. Since the 3.0 release, all used browsers like Chrome, and Firefox provide their own drivers using which Selenium can automate them.

    Under the Selenium project, other components are also available. Selenium IDE, which is largely supported by Applitools, and Selenium Grid which allows one to execute tests in parallel using the grid structure. One of the major changes in Selenium from version 3.0 to 4.0 is a change in the implementation and structure of Selenium Grid. We will see that in the chapter, we will discuss how to set up and use Selenium Grid. To know and work with Selenium IDE, which could also assist with writing Selenium scripts, which we will discuss in detail in its chapter. The following table should help us understand where and how which Selenium component is used:

    Table 1.1: Projects in Selenium

    Selenium CSharp Library

    The Selenium CSharp library provides various interfaces and classes to help automate user actions on browsers. The most important component of this library is the IWebDriver interface which provides a method to automate the browser. The IWebElement interface provides methods to work with web elements. And the By Class which helps us create locator methods to identify the object on which action is to be performed. The detailed Selenium dotnet library is available here - https://www.selenium.dev/selenium/docs/api/dotnet/.

    It primarily consists of Interfaces and Classes.

    Classes

    Let us take a look at the following table, which lists the various classes available in Selenium (please note the following table is taken as it is from the preceding link, and no changes are made here)

    Table 1.2: Classes in Selenium

    Now, let us try and explore one of the classes and take a look at the By Class. The By class has some constructors, properties, methods, and operators. The detailed information of the By class can be explored once you click on the link of By.

    Methods

    The methods which we find when we look at the class are as follows:

    Table 1.3: Methods of By class

    Now, when you click on the By class and let us say you wish to explore the ID method, click on the ID method and we will find the method definition:

    public static By Id(

    string idToFind

    )

    So, this method returns a By-object, which is identified by a string, which was the ID value of the object passed.

    In this way, we can explore other classes of Selenium and the various methods available in those classes. This will help us write better code. In the same way, we can explore the interfaces of Selenium.

    Setup Project in Visual Studio

    Visual Studio is generally the default IDE which we use while working on the dotnet projects. And we need to understand here is t Selenium with CSharp project setup would be like a dotnet project setup. We will proceed in this book with the understanding that you are well familiar with CSharp as a programming language and are comfortable with using Visual Studio as an IDE. To set up and download Visual Studio in your system, we will follow these steps:

    Download the Visual Studio community edition from here:

    https://visualstudio.microsoft.com/downloads/

    Figure 1.1: Visual Studio Community Edition

    After you have downloaded the Visual Studio Community Edition, the next step will be to install it on the system. Once you run the installer, Visual Studio will start, and you will be required to set up some required packages. Select the one required for the dotnet development project:

    Figure 1.2: Components for Visual Studio

    We will need to select the .Net desktop development and Universal Windows Platform development as shown in Figure 1.3:

    Figure 1.3: Component Selection

    We then click on the extreme right side at the lower section of the modify button and allow the installation to take place:

    Figure 1.4: Allow component installation

    With the preceding steps, our Visual Studio IDE will be set up and ready to use. Our next step is project creation.

    To set up the project in Visual Studio, we will need to choose the type of Project we wish to create. Since this book is aimed to use Selenium using Csharp for the automation of web testing processes, it will be advisable to select an NUnit Project type. In the upcoming chapter, we will discuss NUnit and eventually move on to that by adding relevant libraries. Currently, as we begin with our first steps on Selenium, we will select a project type of ConsoleApp, and add the required NuGet packages to set up Selenium. In the following steps, let us see how we do that:

    After launching Visual Studio, we will first select Create New Project:

    Figure 1.5: Create New Project

    We can now from the list, select Console App (.Net Framework):

    Figure 1.6: Project Selection

    Provide the Project with a name, select 4.8 and .Net framework, and click on the Create button:

    Figure 1.7 Project Creation

    Once done, you should be able to see this screen, and on the right-hand side, it shows the project tree:

    Figure 1.8: CSharp Project

    Our next step here would be to add the relevant NuGet packages which would be required before writing down our first Selenium Script. For this, right click on the Solution, and select the Manage Nuget packages:

    Figure 1.9: NuGet Packages

    Click on Browse, and search for Selenium, chose Selenium Webdriver, the first option, and on the window on the right-hand side, select Solution, which will ensure that any project created in the solution will have the Selenium WebDriver NuGet available. Click on Install as shown in Figure 1.10:

    Figure 1.10: Install Selenium NuGet

    In a similar manner, our next NuGet to install would be Selenium Support:

    Figure 1.11: Selenium Support NuGet

    And after these two, we will install the NuGet for ChromeDriver, GeckoDriver, and EdgeDriver, as shown in Figure 1.12:

    Figure 1.12: Selenium ChromeDriver Nuget

    Figure 1.13: Selenium Edge Driver Nuget

    Figure 1.14: Selenium Browser Drivers NuGets

    Once all this is complete, we are now in a good position to write our first .cs file to open the web browser for Chrome, Firefox, and Edge, which we will explore in the next chapter, after we have a walk-through of our web application, which we will use at various places to understand the automation concepts.

    Conclusion

    In this chapter, we explored what is Selenium and the three projects of Selenium. We then moved on to understanding how to navigate through the Selenium dotnet library and its importance. We finally saw how to install and set up Visual Studio as the IDE for our automation project for testing using Selenium. We installed the crucial NuGet packages which we will require to get started.

    In the next chapter, we will take a walk-through of the web application which we will be using to understand the different concepts. We will also take a look at some other websites we will explore in the book to automate scenarios.

    Questions

    After reading this chapter, you should be able to answer the following questions:

    What is Selenium

    What is Selenium Grid used for?

    Is IWebDriver an interface or class in the Selenium dotnet

    Enjoying the preview?
    Page 1 of 1