<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: AndreeaDraniceanu</title>
    <description>The latest articles on Forem by AndreeaDraniceanu (@andreeadraniceanu).</description>
    <link>https://forem.com/andreeadraniceanu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F976411%2F66dbd4f7-7e5c-4945-a015-80e99710ec6a.jpeg</url>
      <title>Forem: AndreeaDraniceanu</title>
      <link>https://forem.com/andreeadraniceanu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/andreeadraniceanu"/>
    <language>en</language>
    <item>
      <title>A Beginner’s Guide To SpecFlow ScenarioContext</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Thu, 18 Jan 2024 05:45:24 +0000</pubDate>
      <link>https://forem.com/testmuai/a-beginners-guide-to-specflow-scenariocontext-7pe</link>
      <guid>https://forem.com/testmuai/a-beginners-guide-to-specflow-scenariocontext-7pe</guid>
      <description>&lt;p&gt;SpecFlow is a great .NET testing framework for a BDD test-first approach. It uses plain and readable language to describe the behavior of the software, which both technical and non-technical staff can understand. This helps bring together the different project stakeholders, product owners, developers, and Quality Assurance (QA) engineers to collaborate and deliver high-quality software with a focus on communication, collaboration, and a good understanding of the business requirements.&lt;/p&gt;

&lt;p&gt;SpecFlow ScenarioContext is a SpecFlow framework feature commonly used in behavior-driven development (BDD) for .NET applications. ScenarioContext allows the sharing of data between different steps in a SpecFlow scenario. It acts as a storage container for scenario-specific data, allowing information to be passed between different scenario steps.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;, we will write an automated step using SpecFlow ScenarioContext to share data between steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a fake IP address for your testing projects? Use our free online&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/random-ip-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Random IP Generator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to quickly generate fake IP addresses with just a few clicks.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why use SpecFlow?
&lt;/h3&gt;

&lt;p&gt;In my experience, using &lt;a href="https://www.lambdatest.com/blog/specflow-tutorial-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SpecFlow for automation testing&lt;/a&gt; has helped the teams more easily integrate newbies into the &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; process, and providing test reports to higher-ups who do not need to know the code behind the tests is easier.&lt;/p&gt;

&lt;p&gt;With SpecFlow, the executable specifications are written in Gherkin syntax, which follows basic English language rules and can be read by anybody regardless of technical background. This is very helpful when working in teams where some QA members are not yet very experienced in writing code or when other team members read the test results.&lt;/p&gt;

&lt;p&gt;Another cool thing about the &lt;em&gt;Given-When-Then&lt;/em&gt; test style, which I will cover in more detail, is that it can be used outside the &lt;a href="https://www.lambdatest.com/blog/automation-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation framework&lt;/a&gt;. For example, the tests can be saved in a separate test management tool if the project requires it.&lt;/p&gt;

&lt;p&gt;These tests are easy to follow because they are written in plain English. Also, the manual tests — the tests that cannot or should not be automated — can be written following the same style. If a test fails, you can simply copy the SpecFlow scenario as it is in the bug report. The steps to reproduce should be clear enough for anyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Stop using the same password for everything! Create strong and unique passwords that are difficult to guess with our&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/random-password-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Random Password Generator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;. Try it now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are new to SpecFlow, you can go through this guide on &lt;a href="https://www.lambdatest.com/blog/specflow-tutorial-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;getting started with SpecFlow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Nzhp5jBO8DA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; for more tutorials on &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is SpecFlow ScenarioContext?
&lt;/h3&gt;

&lt;p&gt;A common case when working with SpecFlow is shared data between the test steps or scenarios. To avoid code duplication, we can use the &lt;em&gt;ScenarioContext&lt;/em&gt; class.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;ScenarioContext&lt;/em&gt; class is a shared context object used in SpecFlow to share data between different steps and scenarios. It allows storing and retrieving data throughout the execution of the test scenarios, and it can be used to transfer data between different steps and scenarios.&lt;/p&gt;

&lt;p&gt;Starting with SpecFlow 3.0, &lt;em&gt;ScenarioContext.Current&lt;/em&gt; has been marked as obsolete. Moving away from these properties is because they do not work when running scenarios in parallel. So, in versions 3.0 and higher, you must use the constructor to create an instance of ScenarioContext using Context-Injection.&lt;/p&gt;

&lt;p&gt;ScenarioContext can be used in any SpecFlow hook that executes a scenario. So we can use ScenarioContext in [&lt;em&gt;BeforeScenario, AfterScenario]&lt;/em&gt; and [&lt;em&gt;BeforeStep, After*Step], but it cannot be used in [*BeforeTestRun, AfterTestRun]&lt;/em&gt; or [&lt;em&gt;BeforeFeature, AfterFeature&lt;/em&gt;].&lt;/p&gt;

&lt;p&gt;It can also provide other information about the scenario, such as tags, titles, and descriptions. This information is available through the &lt;em&gt;ScenarioContext.ScenarioInfo&lt;/em&gt; class:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2At1mCp6Y1Ash8sCni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2At1mCp6Y1Ash8sCni.png" alt="images" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need to generate random text based on a regular expression for testing and generating sample data.? Use our online tool to create&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/random-data-from-regexp?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;random text from RegEx&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using ScenarioContext in Selenium
&lt;/h3&gt;

&lt;p&gt;If you want to use SpecFlow, the best way is to work with Visual Studio. You will need to install SpecFlow as an extension. You can do this from the Extensions menu → Manage Extensions, and here search for the extension by name:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AksQqPQuGwgwWsR2G.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AksQqPQuGwgwWsR2G.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the installation is done, a new project template will be available when creating a new project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Auio0e1M3RnayK_tf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Auio0e1M3RnayK_tf.png" alt="images" width="586" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you complete the New Project steps, you will have a new SpecFlow project created in Visual Studio.&lt;/p&gt;

&lt;p&gt;The SpecFlow project will contain a feature file, which is the type of file where the Gherkin scenarios are written, and a steps definition file — which is a C# class with the code for the steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AKQxN3_Py8h7_B3YW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AKQxN3_Py8h7_B3YW.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The feature file content looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: Calculator
![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png)
Simple calculator for adding **two** numbers


Link to a feature: [Calculator](SpecFlowProject2/Features/Calculator.feature)
***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)**


@mytag
Scenario: Add two numbers
    Given the first number is 50
    And the second number is 70
    When the two numbers are added
    Then the result should be 120
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’re interested in the Scenario — this is the test case itself. The SpecFlow scenarios have a &lt;em&gt;Given&lt;/em&gt; — &lt;em&gt;When&lt;/em&gt; — &lt;em&gt;Then&lt;/em&gt; Gherkin structure, equivalent to AAA — Arrange, Act, Assert. The &lt;em&gt;And&lt;/em&gt; keyword can also be used to avoid repetitions of the same keyword.&lt;/p&gt;

&lt;p&gt;This scenario is straightforward to read and understand, even if you don’t know C# or other programming languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Generate custom QR codes for your business or personal needs with our fast and easy-to-use&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/qr-code-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;QR code generator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;online tool in seconds. Try it now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The implementation for a step looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Given("the first number is (.*)")]
        public void GivenTheFirstNumberIs(int number)
        {
            throw new PendingStepException();
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, in the provided example on project creation, no actual implementation for the steps is done, so the step will just throw a &lt;em&gt;PendingStepException&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;For this sample scenario, an implementation could look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Given("the first number is (.*)")]
        public void GivenTheFirstNumberIs(int number)
        {
            a = number;
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we will look into this in more detail with a realistic web test scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/random-isbn-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Random ISBN Generator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;is a free easy-to-use tool to generate random and unique ISBN numbers. Generate the most accurate and verified ISBNs instantly.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing the First Gherkin Test
&lt;/h3&gt;

&lt;p&gt;Now that we know the structure, we can write our tests using the same format. Let’s first understand some of the most important Gherkin keywords and what they mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feature&lt;/strong&gt;: provides a high-level description of a software feature and the scenarios included in a file. The file structure in &lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Gherkin for Selenium Testing&lt;/a&gt; is defined by how different lines of code are indented in a feature file. Each line typically starts with a special keyword, and the statements are terminated by line endings known as steps. The first word in any feature file must be &lt;em&gt;Feature&lt;/em&gt;, followed by a colon (:), followed by a description of the feature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;: is a business rule or the equivalent of a test case. The first line of a test must begin with &lt;em&gt;Scenario:&lt;/em&gt;, followed by the test description.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Given&lt;/strong&gt;: is the Arrange step — it is more like a precondition to the entire test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When&lt;/strong&gt;: is used for action steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;: means the assertion of the test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;And&lt;/strong&gt;: if we need multiple &lt;em&gt;Given&lt;/em&gt;, &lt;em&gt;When&lt;/em&gt;, or &lt;em&gt;Then&lt;/em&gt; steps, we can use &lt;em&gt;And&lt;/em&gt; to avoid repeating the same keyword.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;: is used when the same &lt;em&gt;Given&lt;/em&gt; step would be repeated in all the tests inside a feature file. This is a precondition that is repeated before each of the scenarios of the feature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scenario Outline&lt;/strong&gt;: is used for data-driven scenarios or when we want to have the same scenario with different data sets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;: the &lt;em&gt;Examples&lt;/em&gt; keyword precedes the data table containing the test data for the Scenario Outline.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Gherkin test for a Login page can look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: As an existing user, I want to be able to log in, so that I can access my account.


Background: I access the login page


Scenario: Login with a valid account
    Given I enter a valid username and password
    When I press the Sign in button
    Then I can see My account page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Implementing the Test Steps
&lt;/h3&gt;

&lt;p&gt;The test steps must be implemented in a C# class, marked with the &lt;em&gt;Binding&lt;/em&gt; attribute. You can auto-generate the steps implementation by right-clicking inside the feature file and selecting &lt;em&gt;Define Steps.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AY9299hPYXdR3-N0K.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AY9299hPYXdR3-N0K.png" alt="images" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, they will have an implementation that only throws an error (as above). You can copy the steps definitions or add them to a class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AMKbDQK8y7-Pt6EQ9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AMKbDQK8y7-Pt6EQ9.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way the steps are linked to their definition is through regular expressions. So, in the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Given(@"I enter a valid username and password")]
public void GivenIEnterAValidUsernameAndPassword()
{
        // step code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code between the curly brackets will be executed for each &lt;em&gt;Given&lt;/em&gt; step that matches the regular expression between the quotes. In this case, it has to match the exact string, but it’s not mandatory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a barcode for your products? Create high-quality custom barcodes using our online&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/barcode-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;barcode generator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;. Try our barcode generator tool and get one in seconds.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using SpecFlow ScenarioContext
&lt;/h3&gt;

&lt;p&gt;As it happens so often, some of the test data we use will be shared between the test steps. For example, if you use a username and password in the first step of the previous example, you may want to check on the &lt;strong&gt;My Account&lt;/strong&gt; page that the correct username is displayed after the login.&lt;/p&gt;

&lt;p&gt;You can do this by passing a variable in each step or sharing that information using SpecFlow ScenarioContext.&lt;/p&gt;

&lt;p&gt;The SpecFlow ScenarioContext can be used inside Bindings for specific SpecFlow hooks. So, for example, we can use ScnearioContext inside the &lt;em&gt;Given, When, Then&lt;/em&gt; steps, or inside &lt;em&gt;[BeforeScenario, AfterScenario]&lt;/em&gt; or &lt;em&gt;[BeforeStep, AfterStep]&lt;/em&gt;, but not in &lt;em&gt;[BeforeTestRun, AfterTestRun]&lt;/em&gt; or &lt;em&gt;[BeforeFeature, AfterFeature]&lt;/em&gt;. This is because no scenario is executed for the last hooks.&lt;/p&gt;

&lt;p&gt;In line with the entity-based step organization rule, one efficient method for sharing data between different steps related to the same entity within the same scenario is to define instance fields in the binding classes. To use ScenarioContext, a new instance needs to be created inside the constructor of the &lt;em&gt;Bindings&lt;/em&gt; class, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Bindings(ScenarioContext scenarioContext)
{
    _scenarioContext = scenarioContext;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, you can set and read its properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_scenarioContext["property"] = "value";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Demonstration: SpecFlow ScenarioContext
&lt;/h3&gt;

&lt;p&gt;Let’s look at a scenario to better understand how to use SpecFlow ScenarioContext.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;LambdaTest eCommerce Playground&lt;/a&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expand the Shop by Category menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select a category.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the correct category page is loaded.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: ECommerce


As a user, I want to navigate between the product categories
So I can find the desired product in the list


Background:
    Given I navigate to the LambdaTest ecommerce playground page


Scenario Outline: Navigate to categories
    Given I extend the Shop by Category menu
    When I select the &amp;lt;category&amp;gt; category
    Then the correct page is loaded
Examples:
    | category   |
    | Components |
    | Cameras    |
    | Software   |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Safari;


namespace SpecFlowScenarioContextDemo.StepDefinitions
{
    [Binding]
    internal class SetUp
    {
        protected static IWebDriver driver;
        public static string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        protected ScenarioContext scenarioContext;


        public SetUp(ScenarioContext _scenarioContext)
        {
            scenarioContext = _scenarioContext;
        }


        [BeforeScenario]
        internal static void RunSetup()
        {
            SafariOptions capabilities = new SafariOptions();
            capabilities.BrowserVersion = "latest";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "macOS Ventura");
            ltOptions.Add("build", "SpecFlow ScenarioContext");
            ltOptions.Add("project", ScenarioContext.Current.ScenarioInfo.Title);
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }


        [AfterScenario]
        internal void TearDown()
        {
            driver.Quit();
        }


    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code showcases utilizing a cloud grid like LambdaTest to run the test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Catch errors before they impact your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/free-online-tools/js-validator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;JavaScript validator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;code. Our validator and linter enforces coding standards and helps you catch errors. Validate your code today.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest is an AI-based test orchestration and execution platform that allows you to run SpecFlow tests with &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; on a scalable and reliable cloud grid. With LambdaTest, you can conduct &lt;a href="https://www.lambdatest.com/selenium-c-sharp-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium C# testing&lt;/a&gt; using SpecFlow on over 3000 unique combinations of browsers, operating systems, and devices.&lt;/p&gt;

&lt;p&gt;The process is quite straightforward when running your tests on an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt;, as the necessary code modifications are only related to the infrastructure.&lt;/p&gt;

&lt;p&gt;After creating an account on LambdaTest, it is important to take note of your username and access key from the Profile Section. This combination will be used to access the remote Selenium Grid on LambdaTest.&lt;/p&gt;

&lt;p&gt;The Dashboard provides a comprehensive view of all your text logs, screenshots, and video recordings for your SpecFlow Selenium C# tests. Furthermore, you can utilize the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt; to generate the desired browser and platform capabilities for &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;


namespace SpecFlowScenarioContextDemo.StepDefinitions
{
    [Binding]
    internal class ECommerceStepDefinition : SetUp
    {
        public ECommerceStepDefinition(ScenarioContext _scenarioContext) : base(_scenarioContext)
        {
        }


        [Given(@"I navigate to the LambdaTest ecommerce playground page")]
        public void GivenINavigateToTheLambdaTestEcommercePlaygroundPage()
        {
            driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/");
        }


        [Given(@"I extend the Shop by Category menu")]
        public void GivenIExtendTheShopByCategoryMenu()
        {
            driver.FindElement(By.XPath("//a[normalize-space()='Shop by Category']")).Click();
            WaitForElement($"//h5[normalize-space()='Top categories']");
        }


        [When(@"I select the (.*) category")]
        public void WhenISelectTheCategoryCategory(string categoryName)
        {
            scenarioContext["Category"] = categoryName;
            driver.FindElement(By.XPath($"//span[normalize-space()='{scenarioContext["Category"]}']")).Click();
        }


        [Then(@"the correct page is loaded")]
        public void ThenTheCorrectPageIsLoaded()
        {
            WaitForElement($"//h3[text()='Filter']");
            Assert.That(driver.Title == scenarioContext["Category"].ToString());
        }


        private static void WaitForElement(string xpath)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2ARYQEUfvlDEMsvVdD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2ARYQEUfvlDEMsvVdD.png" alt="images" width="382" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;eCommerce.feature (the feature file)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The feature file contains the test written in plain English, using the Gherkin keywords. The file starts with a short description of the feature. This is not mandatory, but since SpecFlow tests can also be used as documentation, including it is a good practice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AB51NdgP8j9UgM3q_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AB51NdgP8j9UgM3q_.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this example, I ran the test 3 times for 3 categories. This means that we need to use Scenario Outline. They both start with the precondition that the page is loaded, defined in the &lt;em&gt;Background&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AG-Lnk9Dtqg8YyDVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AG-Lnk9Dtqg8YyDVg.png" alt="images" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next comes the test scenario, or the &lt;em&gt;ScenarioOutline&lt;/em&gt;, with 3 examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A0bGk-3xhzxyiUbY1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A0bGk-3xhzxyiUbY1.png" alt="images" width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;category&amp;gt;&lt;/code&gt; variable will receive a different value from the Examples table on each test run.&lt;/p&gt;

&lt;p&gt;The beauty of using SpecFlow and Gherkin is that this scenario is easy to read and interpret as a regular test case. No programming language is needed to understand until this point, and we can show it to other members of our team who need to know what we are testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your native, hybrid, and web apps across all legacy and latest mobile operating systems on the most powerful&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Android emulator online&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SetUp.cs (the setup class)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where I have the &lt;em&gt;BeforeScenario&lt;/em&gt; and &lt;em&gt;AfterScenario&lt;/em&gt; methods, which must be executed before and after each scenario inside the solution.&lt;/p&gt;

&lt;p&gt;The first part is the variable declaration:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AyonHe1Ix-bjl5H2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AyonHe1Ix-bjl5H2z.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I need to declare an &lt;em&gt;IWebDriver&lt;/em&gt; variable, a variable of type &lt;em&gt;ScenarioContext&lt;/em&gt;, and my LambdaTest credentials, which are stored on my machine as environment variables. I also have a constructor for the class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public SetUp(ScenarioContext _scenarioContext)
        {
            scenarioContext = _scenarioContext;
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;em&gt;BeforeScenario&lt;/em&gt; method, I have the code that needs to execute before the test steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AxwJ-GFXU2YWlWsQr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AxwJ-GFXU2YWlWsQr.png" alt="images" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will run the test on Safari browser, which is why I will set the capabilities I want to use in the test. You can easily obtain those using the Capabilities Generator. Then, create a new instance of the driver using those capabilities.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;AfterScenario&lt;/em&gt; methods will close all the browser instances:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A0ylDOlUX-0jUNZIe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A0ylDOlUX-0jUNZIe.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ECommerceStepDefinition.cs (the implementation class)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Here is where I have the implementations for the steps. The link between the class and the Gherkin steps is one through the &lt;em&gt;[Bindings]&lt;/em&gt; attribute and the regular expressions that match the test steps.&lt;/p&gt;

&lt;p&gt;Also, to have the before and after methods executed, this class needs to inherit the &lt;em&gt;SetUp&lt;/em&gt; class:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AmmG6HMx4QRnvr4yH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AmmG6HMx4QRnvr4yH.png" alt="images" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then come the steps. They use attributes as the keywords in the Gherkin tests (&lt;em&gt;Given, When, Then&lt;/em&gt;). Alternatively, you can use the &lt;em&gt;StepDefinition&lt;/em&gt; attribute to match any previous keywords.&lt;/p&gt;

&lt;p&gt;The first step is to navigate to the webpage under test using &lt;em&gt;Navigate().GoTo()&lt;/em&gt; Selenium command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Axe4DZQz01DDuwvkT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Axe4DZQz01DDuwvkT.png" alt="images" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next comes the test step that expands the “Shop by category” menu. This is done by clicking on the element found by &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath&lt;/a&gt;, using its tag (a), and the text it contains (&lt;em&gt;normalize-space()=’Shop by Category’&lt;/em&gt;). Then, I used a common method that waits for an element to be visible, using an &lt;a href="https://www.lambdatest.com/blog/selenium-webdriverwait/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;explicit wait in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the next step, I am using a string variable to pass each category that needs to be selected. To do this in SpecFlow, you can use the regular expression for any string, “(.*)”. This means that the test matches if it contains anything between the “I select the “ string and the “ category” string.&lt;/p&gt;

&lt;p&gt;In the first line of the method, I use the scenario context to store the category name and pass it to the next test step.&lt;/p&gt;

&lt;p&gt;Then, using an XPath again, the test clicks the category link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Amy55g3ERdR9ca2FH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Amy55g3ERdR9ca2FH.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, the last step checks that the page is correctly loaded by validating that the page title is the same as the previously selected category. I could have used a variable again, but using &lt;em&gt;scenarioContex&lt;/em&gt;, I don’t need to.&lt;/p&gt;

&lt;p&gt;To ensure the validation is done before the page is loaded, I am using the &lt;em&gt;WaitForElement()&lt;/em&gt; method to wait for the Filter menu to be displayed. Then, I assert that the page’s title is the same as the previously set category.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Az2q1Fb8tES67C4jX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2Az2q1Fb8tES67C4jX.png" alt="images" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this tutorial, learn what is&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Regression testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, its importance, types, and how to perform it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Execution
&lt;/h3&gt;

&lt;p&gt;The tests are available in the Test Explorer tab. I am using tests plural because a test is available for each example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AIZB-P8LEPwO1HdsE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2AIZB-P8LEPwO1HdsE.png" alt="images" width="445" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can select one of them or one of the higher nodes (project name/feature name/scenario name) and press “Run all”.&lt;/p&gt;

&lt;p&gt;Because I am using my LambdaTest account, the tests will be executed on the Selenium Grid, but I can also see the results in Visual Studio (the green check mark means they are passed).&lt;/p&gt;

&lt;p&gt;Each test execution is also displayed in the test details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A65QobMm5QXliHwfd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A65QobMm5QXliHwfd.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I can also see the test results (including a replay) on my Dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A-WGDBfNFwagd33P0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F0%2A-WGDBfNFwagd33P0.png" alt="images" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practices for SpecFlow ScenarioContext
&lt;/h3&gt;

&lt;p&gt;While ScenarioContext in SpecFlow is a powerful feature that allows data to be shared between steps within a scenario, there are situations where its usage might not be ideal. Now, let’s consider some scenarios where using alternatives or avoiding ScenarioContext in SpecFlow might be more suitable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parallel Execution
&lt;/h3&gt;

&lt;p&gt;If you design tests that run in parallel scenarios, using the SpecFlow ScenarioContext may lead to unexpected behavior. This is because the ScenarioContext is shared across steps within a scenario, and concurrent execution of scenarios can result in data interference. It is advisable to consider using thread-safe alternatives or scenarios that do not rely on shared context in &lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel execution&lt;/a&gt; environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global State Management
&lt;/h3&gt;

&lt;p&gt;SpecFlow ScenarioContext offers a way to share the state between steps; however, heavily relying on global state management can negatively impact test maintainability. It is recommended instead to aim for scenarios and steps that are independent of each other while encapsulating their required data. This approach promotes better test isolation and makes identifying the cause of failures easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data-Driven Testing
&lt;/h3&gt;

&lt;p&gt;When it comes to testing scenarios that rely on data, managing the complexity of the SpecFlow ScenarioContext can be challenging. One approach to tackle this is utilizing external data sources like tables in feature or external data files. By incorporating these sources, you can drive your tests with various datasets, making your testing more robust and adaptable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Long-Running Scenarios
&lt;/h3&gt;

&lt;p&gt;In scenarios that are long-running or involve multiple steps, using SpecFlow ScenarioContext to pass data between steps can sometimes create confusion in the test logic. Instead, it is recommended to break down complex scenarios into smaller, focused ones. Each of these smaller scenarios can then independently manage their context.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance Testing
&lt;/h3&gt;

&lt;p&gt;When it comes to performance or stress testing, where we simulate large sets of data or high concurrent user loads, using SpecFlow ScenarioContext can sometimes cause bottlenecks or contention issues. In these situations, assessing the performance impact and exploring other approaches is important.&lt;/p&gt;

&lt;h3&gt;
  
  
  External Dependency Management
&lt;/h3&gt;

&lt;p&gt;When dealing with external dependencies or services, avoiding relying solely on a shared state through SpecFlow ScenarioContext is important. This approach can present challenges when unexpected failures or changes occur in the external systems. Instead, techniques such as mocking or stubbing, which provide greater control over external dependencies, are worth considering. By employing these methods, you can better manage and mitigate potential issues.&lt;/p&gt;

&lt;p&gt;Overall, it’s important to remember that the appropriate use of SpecFlow ScenarioContext depends on your tests’ specific requirements and characteristics. While it can help share the state between steps in a scenario, it’s crucial to exercise caution and consider alternative approaches when necessary.&lt;/p&gt;

&lt;p&gt;Get ready to showcase your mastery and extensive know-how in employing Selenium for &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;C# automation testing&lt;/a&gt; by obtaining the coveted Selenium C# 101 certification. This valuable certification will bolster your technical proficiency and solidify your reputation as a skilled and reliable tester.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing tools&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Working with SpecFlow can be a very good idea, especially if you need teams and people with various skills to collaborate on the project. The scenarios are easy to read, written in plain English, and use the &lt;em&gt;Given-When-Then&lt;/em&gt; structure.&lt;/p&gt;

&lt;p&gt;SpecFlow ScenarioContext comes in as a great asset. Its main strength is its capacity to provide smooth data exchange between various processes in a scenario, improving reusability and encouraging a clear division of responsibilities. With ScenarioContext, you can pass information and context easily throughout test scenarios, making it a great tool for maintaining state and sharing relevant data during complex test executions.&lt;/p&gt;

&lt;p&gt;You can also leverage &lt;a href="https://www.lambdatest.com/blog/specflow-actions/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan_17&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SpecFlow Actions&lt;/a&gt; and take your test automation to new heights. It empowers you to execute tests across various browser versions and operating systems.&lt;/p&gt;

</description>
      <category>specflow</category>
      <category>automationtesting</category>
      <category>softwaretesting</category>
    </item>
    <item>
      <title>How to Run Multiple NUnit Test Cases</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Fri, 01 Dec 2023 13:11:24 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-run-multiple-nunit-test-cases-2bo0</link>
      <guid>https://forem.com/testmuai/how-to-run-multiple-nunit-test-cases-2bo0</guid>
      <description>&lt;p&gt;When it comes to automated testing in .NET, the NUnit framework is a go-to choice due to its simplicity and robust set of features. In this blog, I will show you how to run multiple test cases in NUnit and Selenium.&lt;/p&gt;

&lt;p&gt;When working on complex projects, having multiple NUnit test cases to cover various scenarios and edge cases is common. NUnit provides methods to automate the execution of multiple test cases, saving time and effort while maintaining high code quality.&lt;/p&gt;

&lt;p&gt;In the following sections, we will explore how to organize and structure &lt;a href="https://www.lambdatest.com/blog/multiple-nunit-test-cases/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test cases&lt;/a&gt; and execute them in bulk using attributes and data-driven testing. We will cover what NUnit is, how to run the same test with different test data, and how to run multiple &lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit test cases in parallel&lt;/a&gt;. Ultimately, we’ll have a short example of how all this information can be put together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Want to ensure your website is optimized for mobile traffic? Our comprehensive guide to&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/mobile-website-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;test website on mobile devices&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;success covers everything you need to know.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is NUnit?
&lt;/h3&gt;

&lt;p&gt;Before demonstrating how to run multiple test cases in NUnit, let’s understand what NUnit is and why it’s a popular framework for &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;NUnit is an open-source unit testing framework for .NET languages, including C# and &lt;a href="https://www.lambdatest.com/blog/multiple-nunit-test-cases/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;VB.NET&lt;/a&gt;. When writing this blog on running multiple NUnit test cases, the latest version is 3.13.3. NUnit provides a simple and intuitive way to write and execute tests, allowing you to verify the behavior and code correctness.&lt;/p&gt;

&lt;p&gt;NUnit follows the &lt;a href="https://www.lambdatest.com/blog/xunit-testing-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;xUnit testing framework&lt;/a&gt; pattern, separating test setup, execution, and assertions.&lt;/p&gt;

&lt;p&gt;One of NUnit’s main benefits is its compatibility with popular development environments like Visual Studio, which makes it a practical option for testing frameworks in .NET.&lt;/p&gt;

&lt;p&gt;We will discuss its range of properties and &lt;a href="https://www.lambdatest.com/blog/asserts-in-nunit/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit assertions&lt;/a&gt; that help organize and structure tests. To increase flexibility and &lt;a href="https://www.lambdatest.com/learning-hub/test-coverage?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test coverage&lt;/a&gt;, NUnit also offers additional features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;parameterized tests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test fixtures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test suites&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have a basic understanding of this framework, let’s look at what are annotations in NUnit. After that, we will see how to run multiple NUnit test cases.&lt;/p&gt;

&lt;p&gt;Getting started with Selenium testing with NUnit? Watch the tutorial below and expedite your learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform live&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/test-site-on-mobile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;mobile test on different devices&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;with LT Browser 2.0. Test website on multiple mobile and tablet viewports and debug UI issues on the go across 50+ device viewports.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2fN6GcZ3-fs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to our &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; for the latest updates on tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Annotations in NUnit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit annotations&lt;/a&gt;, also called NUnit attributes, are special instructions or metadata that can be applied to test methods, classes, or assembly files to modify code execution or provide additional information, like descriptions and test case links (for integration with &lt;a href="https://www.lambdatest.com/blog/best-test-management-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test management tools&lt;/a&gt; like TestRail).&lt;/p&gt;

&lt;p&gt;The most common NUnit annotations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;OneTimeSetup:&lt;/em&gt;&lt;/strong&gt; This annotation marks a method that will run once before the entire test run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;OneTimeTearDown:&lt;/em&gt;&lt;/strong&gt; This annotation marks a method that will be executed once after the entire test run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Setup:&lt;/em&gt;&lt;/strong&gt; This annotation marks a method that will run once before each test case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;TearDown:&lt;/em&gt;&lt;/strong&gt; This annotation marks a method that will execute after each test case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test:&lt;/em&gt;&lt;/strong&gt; This annotation marks test methods. Each test marked as such will be displayed in the Test Explorer panel of Visual Studio.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ignore:&lt;/em&gt;&lt;/strong&gt; This annotation marks a test method to be ignored — when the tests are automatically run, tests marked with ‘Ignore’ will not be executed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Explicit:&lt;/em&gt;&lt;/strong&gt; This annotation marks a method that will be ignored unless explicitly selected to run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;TestCase:&lt;/em&gt;&lt;/strong&gt; An annotation we use for data-driven testing, i.e., for tests that run multiple times with different data sets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Category:&lt;/em&gt;&lt;/strong&gt; This annotation can be used to group tests, which can be run together by specifying their category.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Parallelization:&lt;/em&gt;&lt;/strong&gt; This annotation marks a class or a method for parallelization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The order in which the methods are executed is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[OneTimeSetup]
    [Setup]  
    TestMethod1
    [TearDown]

    [Setup]  
    TestMethod2
    [TearDown]
[OneTimeTearDown]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Explore&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/ios-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;how to test ios app on multiple devices&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, weighing their key features and benefits to select the perfect one for your mobile app project.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Data-Driven Testing to Run Multiple NUnit Test Cases
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/data-driven-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Data-driven testing&lt;/a&gt; is an approach to testing a software application using multiple input data sets. Instead of writing separate test methods for each data set, we can leverage NUnit’s data-driven testing feature to run a single test method with different inputs. This technique is especially useful when we want to test code against various scenarios or validate different data combinations, for example, cross browser testing.&lt;/p&gt;

&lt;p&gt;Here’s an example of how to perform data-driven testing with NUnit using the TestCase attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Tests
{
    [Test]
    [TestCase("Chrome")]
    [TestCase("Safari")]
    [TestCase("Edge")]
    public void TestOnMultipleBrowsers(string browser)
    {
        // Test code goes here
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we have a Tests class with a &lt;em&gt;TestOnMultipleBrowsers&lt;/em&gt; method containing code we want to run on multiple browsers. Instead of writing separate tests for each input/output pair, we use the &lt;em&gt;[TestCase]&lt;/em&gt; attribute to specify multiple sets of input and expected output. NUnit will run the &lt;em&gt;TestAddMethod&lt;/em&gt; test method three times, once for each test case.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;[TestCase]&lt;/em&gt; attribute also supports a variety of data sources, such as arrays, data tables, and CSV files. Here’s an example of using a data table with the &lt;em&gt;TestCaseSource&lt;/em&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Tests
{
    static object[] ItemData =
    {
        new object[] { new Item("Chrome", 114)},
        new object[] { new Item("Safari", 16.5)},
        new object[] { new Item("Edge", 114)},
    };


    [Test]
    [TestCaseSource(nameof(ItemData))]
    public void TestOnMultipleBrowsers(Item item)
    {
        // Test code goes here
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a class with a test method that uses a data table to define multiple browsers and browser versions.&lt;/p&gt;

&lt;p&gt;We then use the &lt;em&gt;TestCaseSource&lt;/em&gt; attribute to specify that NUnit should use the &lt;em&gt;ItemData&lt;/em&gt; field as the data source for the test method. Again, NUnit will run the test method three times, once for each set of inputs.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Run Multiple Tests in Parallel Using NUnit?
&lt;/h3&gt;

&lt;p&gt;By default, test cases in NUnit are run sequentially, meaning that a new test will only run after the previous one has completed its execution. This is all good when we don’t have a lot of tests, but as the projects get more complex, we want to save time on the &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;. To do this, we can [run the tests in parallel]&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5Q0yxvErcCw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;For parallelization, NUnit offers the annotation &lt;em&gt;[Parallelizable]&lt;/em&gt; annotation, which can be used at the class level or at the method level. We, the designers of the tests, are in charge of ensuring that the tests are thread safe when executed concurrently.&lt;/p&gt;

&lt;p&gt;Otherwise, unexpected behavior can result from concurrent tests that edit instance fields or properties without locks, just like it would in a multi-threaded program. This applies to scenarios where one test case can change the data used in a different test case. Keeping the tests as independent as possible is always a good practice.&lt;/p&gt;

&lt;p&gt;When using the &lt;em&gt;[Parallelizable]&lt;/em&gt; annotation, we need to specify the scope of the parallelization. Here are the available options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;ParallelScope.Self:&lt;/em&gt;&lt;/strong&gt; When the test can run in parallel with other tests. This scope can be applied to classes and methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;ParallelScope.Children:&lt;/em&gt;&lt;/strong&gt; When the child tests can run in parallel with one another. This scope can be applied to the assembly and classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;ParallelScope.Fixtures:&lt;/em&gt;&lt;/strong&gt; When the fixtures (test classes) can run in parallel with one another. This scope applies to the assembly and classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;ParallelScope.All:&lt;/em&gt;&lt;/strong&gt; When the test and its descendants can run in parallel with others at the same level. This scope can be applied to classes and methods.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform live&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/test-site-on-mobile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;web device testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;on different devices with LT Browser 2.0. Test on multiple mobile and tablet viewports and debug UI issues on the go across 50+ device viewports.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Demonstration: Running Multiple NUnit Test Cases in Parallel
&lt;/h3&gt;

&lt;p&gt;In the next section of this &lt;a href="https://www.lambdatest.com/learning-hub/nunit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;NUnit tutorial&lt;/a&gt;, I will demo how we can use &lt;a href="https://www.lambdatest.com/blog/data-driven-framework-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;data-driven testing with Selenium&lt;/a&gt; and run multiple NUnit test cases in parallel, saving a lot of execution time. We will be using the already-mentioned annotations, assertions, and data-driven testing. This is equivalent to executing multiple NUnit test cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Scenarios
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Scenario 1:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the webpage: &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;LambdaTest eCommerce Playground&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the &lt;strong&gt;Shop by Category&lt;/strong&gt; menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on a category under the section &lt;strong&gt;Top Categories&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the correct page is loaded with the correct title.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat the test for multiple categories.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Scenario 2:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the webpage: &lt;a href="https://ecommerce-playground.lambdatest.io/index.php?route=account/login" rel="noopener noreferrer"&gt;LambdaTest eCommerce Playground&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter invalid credentials for the username and/or password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the correct message is displayed: “No match for E-Mail Address and/or Password.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Implementation (Local Test Execution)
&lt;/h3&gt;

&lt;p&gt;When writing this article, the latest version of &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is 4.10.0. One of the standout features in Selenium 4 is the adoption of the W3C WebDriver protocol, which takes the place of the JSON wire protocol used in Selenium 3. This shift has been a game-changer, making Selenium 4 distinct and more advanced compared to Selenium 3.&lt;/p&gt;

&lt;p&gt;To know the difference between Selenium 3 and 4 versions, we recommend checking our article on &lt;a href="https://www.lambdatest.com/blog/selenium-3-vs-selenium-4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 3 vs Selenium 4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see how to run multiple NUnit test cases on a local machine. There are a few prerequisites before we start writing the tests.&lt;/p&gt;

&lt;p&gt;First, create a new NUnit project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AHMkwO0xN63XvsHOS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AHMkwO0xN63XvsHOS.png" alt="image" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, add the &lt;em&gt;Selenium.WebDriver Nuget&lt;/em&gt; package. Also, add a NuGet package for the desired browser. As I use the Chrome browser, I will now add the &lt;em&gt;Selenium.WebDriver.ChromeDriver&lt;/em&gt; package. I am also adding the package &lt;em&gt;DotNetSeleniumExtras&lt;/em&gt;, which will be used for &lt;a href="https://www.lambdatest.com/blog/webdriverwait-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;explicit waits in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once we are done with the above prerequisites, the next step is to write the test script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using SeleniumExtras.WaitHelpers;
using OpenQA.Selenium.Support.UI;


namespace NUnitDataDriven
{
    public class NUnitTest
    {
        private static IWebDriver driver;


        [SetUp]
        public void Setup()
        {
            driver = new ChromeDriver();
        }


        [Test]
        [TestCase("Components")]
        [TestCase("Cameras")]
        [TestCase("Software")]
        public void OpenCategory(string menuOption)
        {
            driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/");
            driver.FindElement(By.XPath("//a[normalize-space()='Shop by Category']")).Click();
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            string xpath = $"//span[normalize-space()='{menuOption}']";
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
            driver.FindElement(By.XPath(xpath)).Click();
            Assert.That(Equals(driver.Title, menuOption));
        }


        [Test]
        [TestCase("andreea", "test")]
        [TestCase("andreea@getnada.com", "")]
        [TestCase("andreea@getnada.com", "xxxx")]
        public void LoginInvalidCredentials(string email, string password)
        {
            driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/index.php?route=account/login");
            driver.FindElement(By.Name("email")).SendKeys(email);
            driver.FindElement(By.Id("input-password")).SendKeys(password);
            driver.FindElement(By.CssSelector("input[value='Login']")).Click();
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            string xpath = "//div[@class='alert alert-danger alert-dismissible']";
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
            Assert.That(driver.FindElement(By.XPath(xpath)).Text.Contains("No match for E-Mail Address and/or Password."));
        }


        [TearDown]
        public void TearDown()
        {
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AvLZRHgNTk91CqR0P.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AvLZRHgNTk91CqR0P.png" alt="image" width="382" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/test-site-on-mobile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Check website on different devices&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;with LT Browser 2.0. Test on multiple mobile and tablet viewports and debug UI issues on the go across 50+ device viewports.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;The first part is the same for all C# classes and contains the references to namespaces and packages to be used:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUwXURmOU7S5-fQU8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUwXURmOU7S5-fQU8.png" alt="image" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, we have the driver variable declared in the first part of the class using the &lt;em&gt;IWebDriver&lt;/em&gt; Selenium interface:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADiG_D_2QylXA2kat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADiG_D_2QylXA2kat.png" alt="image" width="788" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We don’t need any other variables for this example, so we can go straight to the tests. However, we can use a common setup for all our tests to avoid code repetition in each test. We’ll do this using the &lt;em&gt;[SetUp]&lt;/em&gt; annotation, so the code inside will execute before each test case. This line of code simply starts the Chrome browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AxHyQTFi3nCqwv2V-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AxHyQTFi3nCqwv2V-.png" alt="image" width="788" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we can get started on the tests. We have two scenarios that will be executed with various test data. So we will have the &lt;em&gt;[Test]&lt;/em&gt; annotation to instruct the &lt;a href="https://www.lambdatest.com/learning-hub/test-runner?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test runner&lt;/a&gt; that the code inside is test code and the &lt;em&gt;[TestCase]&lt;/em&gt; annotation, once for each set of data.&lt;/p&gt;

&lt;p&gt;Let’s look at them individually:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AQWxva6IUysNfb4Jv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AQWxva6IUysNfb4Jv.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this test, we need to declare a string variable for selecting the menu option. We can call it &lt;em&gt;menuOption&lt;/em&gt;, and inside each test case annotation, we need to pass the string value to use.&lt;/p&gt;

&lt;p&gt;The first step of the test is to navigate to the desired URL using the &lt;a href="https://www.lambdatest.com/blog/iwebdriver-browser-commands-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Navigate Selenium command&lt;/a&gt;. After the page is loaded, we need to click the &lt;strong&gt;Shop by Category&lt;/strong&gt; link — for this, we will use the &lt;a href="https://www.lambdatest.com/blog/findelements-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;em&gt;FindElement() command&lt;/em&gt;&lt;/a&gt; to identify the web element using its &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath&lt;/a&gt; and the &lt;em&gt;Click()&lt;/em&gt; command to perform the click.&lt;/p&gt;

&lt;p&gt;Next, we want to click the category, but we can instruct Selenium to wait for the link to be visible before clicking it. For this, we can use an explicit wait, and the click will not be performed before the element is loaded on the page. We can use XPath again to identify the element and the &lt;em&gt;Click()&lt;/em&gt; command to click on it.&lt;/p&gt;

&lt;p&gt;The last step is the assertion, using the NUnit class &lt;em&gt;Assert&lt;/em&gt;, and we want to validate that the correct page is loaded. For this, we compare the page title with the menu option, and these two strings should be equal.&lt;/p&gt;

&lt;p&gt;In the second test case, we will need two variables — one for the user email and one for the password, and we will pass the values the same way we did in the previous test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/test-site-on-mobile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;View Website on different devices&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;with LT Browser 2.0. Test on multiple mobile and tablet viewports and debug UI issues on the go across 50+ device viewports.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATIKJ9HTZm4greY8V.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATIKJ9HTZm4greY8V.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first line is the same as in the other test, except we navigate to a different URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ABVbCeZkiawHUof8B.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ABVbCeZkiawHUof8B.png" alt="image" width="800" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to identify the email and password fields, enter their values, and click the Login button. We can use &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Locators in Selenium&lt;/a&gt; to find the elements, such as Name, ID, or &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selectors&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AY0Ti02VoTcZ_w_rv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AY0Ti02VoTcZ_w_rv.png" alt="image" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we again need &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Waits&lt;/a&gt; to ensure that the validation is not done before the warning is visible on the web page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADqXNy4de1qico5M8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADqXNy4de1qico5M8.png" alt="image" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last line is an assertion, which contains the validation that the correct message is displayed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2APyEGeYaMyLRtlz05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2APyEGeYaMyLRtlz05.png" alt="image" width="800" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And last but not least, we have a teardown method that executes after each test case due to the &lt;em&gt;[TearDown]&lt;/em&gt; annotation. We are closing the browser after each execution, using the &lt;em&gt;Quit()&lt;/em&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUmoq5YUxtt3BElyG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUmoq5YUxtt3BElyG.png" alt="image" width="634" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Local Test Execution
&lt;/h3&gt;

&lt;p&gt;The tests can be run from the &lt;strong&gt;Test Explorer&lt;/strong&gt; panel — you can see that each set of data is displayed as a separate test and can be run independently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A0mIr0ojbwcmhNDgZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A0mIr0ojbwcmhNDgZ.png" alt="image" width="447" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you run all the tests, they will run sequentially, each test opening a new Chrome browser window. Running them in parallel can cause issues because each test tries to interact and &lt;a href="https://www.lambdatest.com/blog/protractor-tutorial-handle-mouse-actions-keyboard-events/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;simulate mouse and keyboard actions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AlkD13wWTaBmHgugM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AlkD13wWTaBmHgugM.png" alt="image" width="444" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running the tests, you can see the total time is almost 40 seconds — not more, but this is a sample project with simple tests. The more tests the project has, the longer it will take to execute them locally, and this means that the local machine cannot be used during this time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing platform&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Running Multiple NUnit Test Cases on the Cloud
&lt;/h3&gt;

&lt;p&gt;Let’s see how to write the tests, but this time for running them on the &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online Selenium grid&lt;/a&gt; offered by LambdaTest — an AI-powered test orchestration and execution platform to perform &lt;a href="https://www.lambdatest.com/learning-hub/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;automated testing&lt;/a&gt; with NUnit at scale on over 3000+ real browsers and operating systems. With LambdaTest, you can run multiple NUnit test cases in parallel, reduce test execution time, and ramp up the feedback loop for deploying quality builds.&lt;/p&gt;

&lt;p&gt;Looking to get started with Selenium automation with NUnit? Check out the documentation — &lt;a href="https://www.lambdatest.com/support/docs/nunit-with-selenium-running-nunit-automation-scripts-on-lambdatest-selenium-grid/" rel="noopener noreferrer"&gt;NUnit with Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So you can test remotely and not on a local machine. To run the test on LambdaTest, first, we need to use the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Capabilities Generator&lt;/a&gt; to set up the browser capabilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnyuRHWxFfa86W8_-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnyuRHWxFfa86W8_-.png" alt="image" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how the code looks this time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;


[assembly:Parallelizable(ParallelScope.All)]


namespace NUnitDataDriven
{
    public class NUnitTest
    {
        ThreadLocal&amp;lt;IWebDriver&amp;gt; driver = new ThreadLocal&amp;lt;IWebDriver&amp;gt;();
        public static string gridURL = "@hub.lambdatest.com/wd/hub";


        public static string testURL_1 = "https://ecommerce-playground.lambdatest.io/";
        public static string testURL_2 = "https://ecommerce-playground.lambdatest.io/index.php?route=account/login";


        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");


        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "latest";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "NUnit Multiple Tests");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-c#");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver.Value = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }


        [Test]
        [TestCase("Components")]
        [TestCase("Cameras")]
        [TestCase("Software")]
        public void OpenCategory(string menuOption)
        {
            IWebDriver currentDriver = driver.Value;


            currentDriver.Manage().Window.Maximize();
            currentDriver.Navigate().GoToUrl(testURL_1);
            currentDriver.FindElement(By.XPath("//a[normalize-space()='Shop by Category']")).Click();
            WebDriverWait wait = new WebDriverWait(currentDriver, TimeSpan.FromSeconds(5));
            string xpath = $"//span[normalize-space()='{menuOption}']";
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
            currentDriver.FindElement(By.XPath(xpath)).Click();
            Assert.That(Equals(currentDriver.Title, menuOption));
        }


        [Test]
        [TestCase("andreea1", "test")]
        [TestCase("andreea2@getnada.com", "")]
        [TestCase("andreea3@getnada.com", "xxxx")]
        public void LoginInvalidCredentials(string email, string password)
        {
            IWebDriver currentDriver = driver.Value;


            currentDriver.Navigate().GoToUrl(testURL_2);
            currentDriver.FindElement(By.Name("email")).SendKeys(email);
            currentDriver.FindElement(By.Id("input-password")).SendKeys(password);
            currentDriver.FindElement(By.CssSelector("input[value='Login']")).Click();
            WebDriverWait wait = new WebDriverWait(currentDriver, TimeSpan.FromSeconds(5));
            string xpath = "//div[@class='alert alert-danger alert-dismissible']";
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
            Assert.That(currentDriver.FindElement(By.XPath(xpath)).Text.Contains("No match for E-Mail Address and/or Password."));
        }


        [TearDown]
        public void Cleanup()
        {
            bool passed = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed;
            try
            {
                // Logs the result to Lambdatest
                ((IJavaScriptExecutor)driver.Value).ExecuteScript("lambda-status=" + (passed ? "passed" : "failed"));
            }
            finally
            {
                // Terminates the remote webdriver session
                driver.Value.Quit();
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;Just like before, the first lines of code contain the references used in the class — this time, we need an additional reference, &lt;em&gt;OpenQA.Selenium.Remote&lt;/em&gt;, which allows us to run the tests remotely:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApXIacIBTEcCU8uS0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApXIacIBTEcCU8uS0.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before the class name, we use the &lt;em&gt;[assembly:Parallelizable(ParallelScope.All)]&lt;/em&gt; attribute, which will instruct the tests contained in the class to run in parallel with each other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUGMzCO6CBWyWEizF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUGMzCO6CBWyWEizF.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we have the variables declaration for the variables we will use: the driver, the test URLs, your LambdaTest username and access key, which are stored as environment variables, and the grid URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2At_dKVMTbhErwnGx6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2At_dKVMTbhErwnGx6.png" alt="image" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, there is the &lt;em&gt;[Setup]&lt;/em&gt;. In this method, we define the capabilities used when running the tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4AJMj61zFEQqFGDX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4AJMj61zFEQqFGDX.png" alt="image" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the test, the only change is that we need to create a new variable for the current instance of the driver and use it in the interactions with the browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A9VmHLLCbNcdmWarJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A9VmHLLCbNcdmWarJ.png" alt="image" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in the teardown, before closing the browser, we also want to make sure that the results are saved to LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALwxbS-PxInzYh2o1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALwxbS-PxInzYh2o1.png" alt="image" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The rest of the code is the same.&lt;/p&gt;

&lt;p&gt;Running multiple NUnit test cases in parallel on LambdaTest will help you reap the following benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We can run the tests on different configurations from the ones we have on our local machines (browsers and browser versions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running multiple NUnit test cases in parallel saves time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running the multiple NUnit test cases in parallel on the local machine can be tricky if multiple tests interact simultaneously with different browser instances. This issue is avoided if the tests run on a scalable and reliable cloud grid like LambdaTest.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this tutorial, learn&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;what is Regression testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, its importance, types, and how to perform it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Execution on Cloud
&lt;/h3&gt;

&lt;p&gt;Starting the test execution on the LambdaTest cloud grid can be done the same way as the local execution by selecting to run the tests from the &lt;strong&gt;Test Explorer&lt;/strong&gt;. This time, the execution will be done on the remote server, leaving the local machine available for other work.&lt;/p&gt;

&lt;p&gt;Also, parallel execution of multiple NUnit test cases will depend on the number of allowed parallel tests in your LambdaTest account.&lt;/p&gt;

&lt;p&gt;After running the multiple NUnit test cases in parallel, you can see both results in the &lt;strong&gt;Test Explorer&lt;/strong&gt;. You can also see them in the browser, including a video recording of the test and details about the &lt;a href="https://www.lambdatest.com/blog/top-28-selenium-webdriver-commands-in-nunit-for-test-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver NUnit commands&lt;/a&gt; that were sent.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AtErDVDLnH33dD5x-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AtErDVDLnH33dD5x-.png" alt="image" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALYZSYAXvGtVfFAIS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALYZSYAXvGtVfFAIS.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this tutorial, learn what is&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Regression testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, its importance, types, and how to perform it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this blog on running multiple NUnit test cases, we explored the powerful capabilities of NUnit for running multiple tests using data-driven testing and parallelization. By leveraging these features, we can write more efficient and comprehensive &lt;a href="https://www.lambdatest.com/learning-hub/test-suite?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test suites&lt;/a&gt; that cover a wide range of scenarios and data combinations.&lt;/p&gt;

&lt;p&gt;Data-driven testing allows us to test our code with multiple input datasets without writing separate test methods for each case. Using the &lt;em&gt;[TestCase]&lt;/em&gt; attribute, we can pass different test case data and quickly validate the expected results.&lt;/p&gt;

&lt;p&gt;This approach saves time and effort and promotes maintainability by keeping our test code concise and focused. Additionally, with NUnit, we can run our tests in parallel, which significantly reduces the overall &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec_01&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt; time, especially if we have a large number of tests.&lt;/p&gt;

&lt;p&gt;By utilizing multiple threads or processes, NUnit can distribute the workload and execute tests concurrently, leading to faster feedback and quicker test cycles.&lt;br&gt;&lt;br&gt;
Remember, when using parallelization, it’s important to ensure that the tests are thread-safe and do not have any unintended dependencies or side effects.&lt;/p&gt;

&lt;p&gt;In conclusion, NUnit offers robust features for running multiple tests using data-driven testing and parallelization. By adopting these techniques, we can enhance the efficiency and effectiveness of the test suite, resulting in improved code quality and faster delivery cycles. So go ahead, explore these features, and unlock the full potential of NUnit for your testing needs!&lt;/p&gt;

</description>
      <category>nunit</category>
      <category>automationtesting</category>
      <category>softwaretesting</category>
    </item>
    <item>
      <title>Best C# Testing Frameworks In 2023</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Wed, 05 Jul 2023 05:05:34 +0000</pubDate>
      <link>https://forem.com/testmuai/best-c-testing-frameworks-in-2023-23kb</link>
      <guid>https://forem.com/testmuai/best-c-testing-frameworks-in-2023-23kb</guid>
      <description>&lt;p&gt;Test automation has become an essential element of the Software Development Life Cycle, helping developers and &lt;a href="https://www.lambdatest.com/learning-hub/quality-assurance?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;quality assurance&lt;/a&gt; teams to simplify their testing processes, accelerate delivery, and increase efficiency.&lt;/p&gt;

&lt;p&gt;And when it comes to test automation in C# projects, selecting the right framework can significantly impact the success of your testing efforts. To select the best framework for &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;C# automation testing&lt;/a&gt;, you need to consider the project requirements, in-house expertise, and deadlines for the project.&lt;/p&gt;

&lt;p&gt;Selecting the right test automation framework is a decision that holds great importance. A well-suited framework can help you to create robust &lt;a href="https://www.lambdatest.com/learning-hub/test-suite?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test suites&lt;/a&gt;, execute tests efficiently, and obtain accurate results, saving valuable time and effort. On the other hand, an ill-fitting framework might introduce complexities, restrict flexibility, or fail to integrate with your existing development environment.&lt;/p&gt;

&lt;p&gt;In this blog, I will discuss some popular C# testing frameworks for unit testing, web automation, mobile, and BDD testing. Whether you are a seasoned C# developer or just starting your journey, this guide seeks to help you find the right C# testing frameworks to meet your testing needs.&lt;/p&gt;

&lt;p&gt;Let’s begin!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;best automation testing tools&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  C# Unit Testing Frameworks
&lt;/h3&gt;

&lt;p&gt;Unit testing frameworks can be used at all levels of testing, not only &lt;a href="https://www.lambdatest.com/learning-hub/unit-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;unit testing&lt;/a&gt;. They provide the ability to mark methods as test methods, setup, and teardown methods, help with parallelization, and help with validations. They also provide runners, so they can be integrated with other &lt;a href="https://www.lambdatest.com/blog/automation-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing frameworks&lt;/a&gt; that cannot run the tests, such as Selenium.&lt;/p&gt;

&lt;p&gt;The three major C# testing frameworks for unit testing are MSTest, NUnit, and xUnit.&lt;/p&gt;

&lt;h3&gt;
  
  
  MSTest
&lt;/h3&gt;

&lt;p&gt;MSTest is one of the popular C# testing frameworks for unit testing included by default with Microsoft Visual Studio. At the time I’m writing this blog, the latest MSTest is 3.0.2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGbGIB-PZQ2jw7U1C.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGbGIB-PZQ2jw7U1C.png" alt="image" width="800" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re working with Visual Studio and start a new project, you will have the option to create a new MSTest project, and the NuGet package is automatically added:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApZ7hlZ5ZNwQ2kc9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApZ7hlZ5ZNwQ2kc9d.png" alt="image" width="658" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MSTest uses annotations to instruct the underlying framework on how to interpret the source code.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2XUQdN-Bi2o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing tools&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of MSTest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most common features you’ll need if you use MSTest as the testing framework in your project are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Annotations that mark test classes and methods, for example, TestClass to mark a class containing tests, &lt;em&gt;TestMethod&lt;/em&gt; to mark a test case, &lt;em&gt;TestInitialize&lt;/em&gt;, &lt;em&gt;TestCleanup&lt;/em&gt;, &lt;em&gt;ClassInitialize&lt;/em&gt;, and &lt;em&gt;ClassCleanup&lt;/em&gt;, for creating setups and teardowns for the tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used for &lt;a href="https://www.lambdatest.com/learning-hub/data-driven-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;data-driven testing&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assertions (using the Assert class) are used to validate expected behaviors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allows parallelization of tests.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s dive into popular features of the MSTest framework and understand them in detail.&lt;/p&gt;

&lt;h4&gt;
  
  
  Annotations
&lt;/h4&gt;

&lt;p&gt;Annotations (also known as attributes) are used to add metadata to a test method or class. They provide additional information to the testing framework about how a test method should be executed or how a test class should be treated.&lt;/p&gt;

&lt;p&gt;If you have a test class, you need to mark it as such, and the MSTest annotation for this is &lt;em&gt;[TestClass]&lt;/em&gt;. Then, you need annotations for the methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace MSTestExample
{
    [TestClass]
    public class ExampleTest
    {
        [AssemblyInitialize]
        // This method will execute before the test run
        public void BeforeAssembly()
        {
        }


        [ClassInitialize]
        // This method will execute before all the tests in the class
        public void BeforeClass()
        {
        }


        [TestInitialize]
        // This method will execute before each test in the class
        public void BeforeTest()
        {
        }


        [TestMethod]
        // This is the test method
        public void TestMethod()
        {
        }


        [TestCleanup]
        // This method will execute after each test in the class
        public void AfterTest()
        {
        }


        [ClassCleanup]
        // This method will execute after all the tests in the class
        public void AfterClass()
        {
        }


        [AssemblyCleanup]
        // This method will execute after the test run
        public void AfterAssembly()
        {
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The running order for the annotated methods will be:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADAo1rLrPDI-epCxL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADAo1rLrPDI-epCxL.png" alt="image" width="694" height="1090"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Assertions
&lt;/h4&gt;

&lt;p&gt;Another important feature of unit testing frameworks is assertions. The test result is based on whether the assertion passes or fails. Here are the most important MSTest assertions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Assert that two values are equal
Assert.AreEqual(value1, value2);


// Assert that two values are not equal
Assert.AreNotEqual(value1, value2);


// Assert that two objects are equal
Assert.AreSame();


// Assert that two objects are not equal
Assert.AreNotSame(variable1, variable2);


// Assert that a condition is true
Assert.IsTrue(condition);


// Assert that a condition is false
Assert.IsFalse(condition);


// Assert that a value is null
Assert.IsNull(value);


//Assert that a value is not null
Assert.IsNotNull(value);


// Fail the test. This can be useful, for example, in a catch block
Assert.Fail();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use assertions specific to string values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Assert that two string values are equal
StringAssert.Equals(value1, value2);


// Assert that a string value contains a substring value
StringAssert.Contains(value, substring);


// Assert that a string value matches a regular expression pattern
StringAssert.Matches(value, regEx);


// Assert that a string value does not match a regular expression pattern
StringAssert.DoesNotMatch(value, regEx);


// Assert that a string value starts with a substring value
StringAssert.StartsWith(value, substring);


// Assert that a string value ends with a substring value
StringAssert.EndsWith(value, substring);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;This blog discusses the most exciting features of 13 best&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing frameworks&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;in 2021.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Data-driven testing
&lt;/h4&gt;

&lt;p&gt;MSTest allows data-driven testing, i.e., running the same test with different sets of data. To run parameterized tests, you need the &lt;em&gt;[DataRow]&lt;/em&gt; attribute for each set of data and the &lt;em&gt;[DataTestMethod]&lt;/em&gt; annotation for the method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[DataRow(“Chrome”,”113.0”,”Windows 11”)]
[DataRow(“Safari”,”16.0”,”macOS Ventura”)]
[DataTestMethod]
// This is the test method
public void TestMethod(string browser, string browserVersion, string os)
{
    // The test code goes here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the test will run twice: once for Chrome version 112, on Windows 11, and then for Safari 16.0, on macOS Ventura.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of MSTest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main advantages of MSTest as a unit testing framework are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s open-source, you can access the code on GitHub and even contribute to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers cross-platform support (for .NET framework, .NET Core, and &lt;a href="http://ASP.NET" rel="noopener noreferrer"&gt;ASP.NET&lt;/a&gt; Core, as well as platforms like Windows, Mac, and Linux.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports data-driven testing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  NUnit
&lt;/h3&gt;

&lt;p&gt;NUnit is yet another one of the best C# testing frameworks for unit testing. It’s an open-source framework that was ported from Java’s JUnit. At the time of writing this article, the most recent version of NUnit is 3.13.3.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Az74qup05FZIa6PzZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Az74qup05FZIa6PzZ.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of NUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the most common and useful features of NUnit are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Just like MSTest, the use of annotation to mark the purpose of classes and methods: &lt;em&gt;TestFixture&lt;/em&gt; for test classes, Test for test methods, &lt;em&gt;SetUp&lt;/em&gt;, &lt;em&gt;TearDown&lt;/em&gt;, &lt;em&gt;OneTImeSetUp&lt;/em&gt;, &lt;em&gt;OneTimeTeardown&lt;/em&gt; for setups and teardowns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support data-driven testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uses assertions that validate our post-conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers parallelization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2fN6GcZ3-fs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Improve your software testing process with our&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automation-testing-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing tutorial&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;. Discover the benefits of automation testing, learn about the best tools and techniques, and get expert insights on optimizing your testing strategy.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Annotations
&lt;/h4&gt;

&lt;p&gt;Just like MSTest, &lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;annotations in NUnit&lt;/a&gt; are used to mark methods and classes. For classes, there are two annotations: the &lt;em&gt;[TestFixture]&lt;/em&gt;, which marks a test class, and the &lt;em&gt;[SetUpFixture]&lt;/em&gt;, which marks a class that only contains the setup and the teardown that will run once before the entire test run.&lt;/p&gt;

&lt;p&gt;Here are the rest of the most common annotations needed in a test framework:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace NUnitExample
{
    [TestFixture]
    public class ExampleTest
    {
        [OneTimeSetUp]
        // This method will run once before the test run, if included in a SetUpFixture class
        // Or it will run once before the test class, if included in a TestFixture class
        public void BeforeClass()
        {
        }


        [SetUp]
        // This method will execute before each test in the class
        public void BeforeTest()
        {
        }


        [Test]
        // This is the test method
        public void TestMethod()
        {
        }


        [TearDown]
        // This method will execute after each test in the class
        public void AfterTest()
        {
        }


        [OneTimeTearDown]
        // This method will run once after the test run, if included in a SetUpFixture class
        // Or it will run once after the test class, if included in a TestFixture class
        public void AfterClass()
        {
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The running order for the annotated methods will be.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A7zRGTyVJITjmK2hj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A7zRGTyVJITjmK2hj.png" alt="image" width="572" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Assertions
&lt;/h4&gt;

&lt;p&gt;For validation, NUnit uses assertions as well. The most useful &lt;a href="https://www.lambdatest.com/blog/asserts-in-nunit/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit assertions&lt;/a&gt; are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Assert that two values are equal
Assert.AreEqual(value1, value2);


// Assert that two values are not equal
Assert.AreNotEqual(value1, value2);


// Assert that two objects are equal
Assert.AreSame(variable1, variable2);


// Assert that two objects are not equal
Assert.AreNotSame(variable1, variable2);


// Assert that a condition is true
Assert.IsTrue(condition);


// Assert that a condition is false
Assert.IsFalse(condition);


// Assert that a collection contains an object
Assert.Contains(variable, collection);


// Fail the test. This can be useful, for example, in a catch block
Assert.Fail();


// Pass the test
Assert.Pass();


// Assert that an object is null
Assert.IsNull(variable);


// Assert that an object is not null
Assert.IsNotNull(variable);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And string assertions are as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Assert that two string values are equal
StringAssert.Equals(value1, value2);


// Assert that a string value starts with a substring value
StringAssert.StartsWith(substring, value);


// Assert that a string value does not start with a substring value
StringAssert.DoesNotStartWith(substring, value);


// Assert that a string value ends with a substring value
StringAssert.EndsWith(substring, value);


// Assert that a string value does not end with a substring value
StringAssert.DoesNotEndWith(substring, value);


// Assert that a string value contains a substring value
StringAssert.Contains(substring, value);


// Assert that a string value does not contain a substring value
StringAssert.DoesNotContain(substring, value);


// Assert that a string value matches a regular expression pattern
StringAssert.IsMatch(regex, value);


// Assert that a string value does not match a regular expression pattern
StringAssert.DoesNotMatch(regEx, value);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Discover the 17 key&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/17-key-benefits-of-automation-testing-for-a-successful-release/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;benefits of automation testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, which will help you decide whether this is the right call for your SDLC. Find out more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Data-driven testing
&lt;/h4&gt;

&lt;p&gt;Data-driven testing in NUnit is done using the &lt;em&gt;[TestCase]&lt;/em&gt; annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TestCase("Chrome", "113.0", "Windows 11")]
[TestCase("Safari", "16.0", "macOS Ventura")]
[Test]
public void TestMethod(string browser, string browserVersion, string os)
{
    /// The test code goes here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages of NUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Among the pros of NUnit, it’s worth mentioning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open-sourced with an active community on GitHub.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Has data-driven capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Test execution&lt;/a&gt; can be done from a console runner or using the NUnit runner in Visual Studio.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  xUnit
&lt;/h3&gt;

&lt;p&gt;The last C# testing framework for unit testing on the list is xUnit. The latest version of xUnit at the time of writing this article is 2.4.2. xUnit is an open-source framework for the .NET framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A0ejvISSxmyXTFvq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A0ejvISSxmyXTFvq1.png" alt="image" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of xUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most useful features of the xUnit framework are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s open-source, and the community can contribute to the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports data-driven testing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The setup and teardown are replaced by constructors and IDisposable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Annotations
&lt;/h4&gt;

&lt;p&gt;Like the other frameworks, xUnit also uses annotations, but, as opposed to MSTest and NUnit, it doesn’t need an annotation for the test class and does not use annotations for setup and teardown methods.&lt;/p&gt;

&lt;p&gt;So the remaining main annotations are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Fact]
// This is the test method
public void TestCase()
{
}


[Theory]
// This is a test method that will run once for each data set
[InlineData("Chrome", "113.0", "Windows 11")]
[InlineData("Safari", "16.0", "macOS Ventura")]
public void DataDrivenTestCase(string browser, string browserVersion, string os)
{
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn why Python is the top choice for automation testing. This comprehensive tutorial provides a step-by-step guide to&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/python-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Python automation testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to help you streamline your testing process.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Assertions
&lt;/h4&gt;

&lt;p&gt;Like before, assertions are used for validations. With xUnit, the string assertions are done through the &lt;em&gt;Assert&lt;/em&gt; class, too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Assert that two string values are equal
Assert.Equal(value1, value2);

// Assert that two string values are not equal
Assert.NotEqual(value1, value2);


// Assert that a condition is true
Assert.True(condition);


// Assert that a condition is false
Assert.False(condition);


// Assert that a string value contains a substring value
Assert.Contains(substring, value);


// Assert that a string value does not contain a substring value
Assert.DoesNotContain(substring, value);


// Assert that a string value starts with a substring value
Assert.StartsWith(substring, value);


// Assert that a string value ends with a substring value
Assert.EndsWith(substring, value);


// Assert that a string value matches a regular expression pattern
Assert.Matches(regex, value);


// Assert that a string value does not match a regular expression pattern
Assert.DoesNotMatch(regex, value);


// Assert that an object is null
Assert.Null(object);


// Assert that an object is not null
Assert.NotNull(object);


// Assert that two objects are equal
Assert.Same(variable1, variable2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages of xUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main advantages of using xUnit are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Fewer annotations are needed because they are not required for the setup and teardown&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In xUnit, parallel test execution using a Selenium Grid can be achieved at the thread level.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  C# Testing Frameworks for Web
&lt;/h3&gt;

&lt;p&gt;In this section, I will cover the most popular C# testing frameworks used for &lt;a href="https://www.lambdatest.com/learning-hub/web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;web automation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selenium
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is still one of the best C# testing frameworks and is widely used by automation testers when it comes to &lt;a href="https://www.lambdatest.com/learning-hub/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;web testing&lt;/a&gt;. Selenium is not a testing framework in itself but a framework that automates web browsers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AXjtgGKodhbXP72O_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AXjtgGKodhbXP72O_.png" alt="image" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Many other popular automation testing frameworks are wrappers that use the Selenium libraries, so they perform actions using Selenium code. These frameworks also include validation, reporting capabilities, and other test-related functionalities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most important features of Selenium are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allows the most common actions a user can perform: clicking a button, entering input data, selecting values from drop-downs, checking and unchecking checkboxes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can automate multiple browsers such as Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and even Microsoft Internet Explorer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works on Windows, macOS, and Linux.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example of Selenium with NUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s what a Selenium test using the NUnit framework looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;

namespace SeleniumLocators
{
    public class Tests
    {
        private static IWebDriver driver = new ChromeDriver();

        [Test]
        public void ValidateSignIn()
        {
            driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/index.php?route=account/login");
            driver.FindElement(By.Name("email")).SendKeys("test@email.com");
            driver.FindElement(By.Id("input-password")).SendKeys("password");
            driver.FindElement(By.CssSelector("input[value='Login']")).Click();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple test that navigates to a given URL address, enters login credentials then presses a Login button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you use a Mac and want to run the test in Internet Explorer? This article explores how to test&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/test-internet-explorer-for-mac/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Internet Explorer for Mac&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are some benefits of using Selenium as your C# testing framework:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Selenium is a well-established and widely used framework. There are over 50 thousand questions tagged Selenium on StackOverflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Great community support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is open-source.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports many programming languages, including C#, Java, Python, JavaScript, and Perl.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some downsides of using Selenium WebDriver can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A steep learning curve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lack of built-in reporting and result analysis.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Playwright
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, an open-source test automation framework, was first created by contributors from Microsoft. It has support for various programming languages such as Java, Python, C#, and Node.js and comes with an Apache 2.0 License.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6a22l6ppJamnR1ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6a22l6ppJamnR1ne.png" alt="image" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of Playwright&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are some of its most important features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Supports multiple browsers: Chrome, Edge, Safari, and Firefox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be used for API and &lt;a href="https://www.lambdatest.com/learning-hub/ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;UI testing&lt;/a&gt;. With a third-party plugin integration, Playwright can even be used for &lt;a href="https://www.lambdatest.com/learning-hub/accessibility-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;accessibility testing&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports parallel test execution — particularly useful when working with large test suites or performing &lt;a href="https://www.lambdatest.com/online-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built-in reporters.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Playwright Code Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is a code example of C# with the Playwright that runs on the LambdaTest platform.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.Playwright;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;


class PlaywrightTestSingle
{
    public static async Task main(string[] args)
    {
        using var playwright = await Playwright.CreateAsync();


        string user, accessKey;
        user = Environment.GetEnvironmentVariable("LT_USERNAME");
        accessKey = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");


        Dictionary&amp;lt;string, object&amp;gt; capabilities = new Dictionary&amp;lt;string, object&amp;gt;();
        Dictionary&amp;lt;string, string&amp;gt; ltOptions = new Dictionary&amp;lt;string, string&amp;gt;();


        ltOptions.Add("name", "Playwright Test");
        ltOptions.Add("build", "Playwright C-Sharp tests");
        ltOptions.Add("platform", "Windows 10");
        ltOptions.Add("user", user);
        ltOptions.Add("accessKey", accessKey);


        capabilities.Add("browserName", "Chrome");
        capabilities.Add("browserVersion", "latest");
        capabilities.Add("LT:Options", ltOptions);


        string capabilitiesJson = JsonConvert.SerializeObject(capabilities);


        string cdpUrl = "wss://cdp.lambdatest.com/playwright?capabilities=" + Uri.EscapeDataString(capabilitiesJson);


        await using var browser = await playwright.Chromium.ConnectAsync(cdpUrl);
        var page = await browser.NewPageAsync();
        try {
          await page.GotoAsync("https://www.bing.com");
          await page.Locator("[id='sb_form_q']").ClickAsync();
          await page.FillAsync("[id='sb_form_q']", "LambdaTest");
          await page.waitForTimeout(1000)
          await page.Keyboard.PressAsync("Enter");
          await page.waitForSelector("[class=' b_active'])
          var title = await page.TitleAsync();


          if (title.Contains("LambdaTest"))
          {
            // Use the following code to mark the test status.
            await SetTestStatus("passed", "Title matched", page);
          }
          else {
            await SetTestStatus("failed", "Title not matched", page);
          }
        }
        catch (Exception err) {
          await SetTestStatus("failed", err.Message, page);
        }
        await browser.CloseAsync();
    }


    public static async Task SetTestStatus(string status, string remark, IPage page) {
        await page.EvaluateAsync("_ =&amp;gt; {}", "lambdatest_action: {\"action\": \"setTestStatus\", \"arguments\": {\"status\":\"" + status + "\", \"remark\": \"" + remark + "\"}}");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test opens the Bing homepage, searches for the keyword “LambdaTest”, waits for the results to load, and validates that the title contains “LambdaTest”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium Automation&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Testing scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Playwright&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The benefits of using Playwright as your web automation framework include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Easy to set up and configure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-language support: C#, Java, Python, Javascript, and TypeScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports CI/CD integration.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Playwright&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And some of the cons of using Playwright are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No support for legacy Microsoft Edge or IE11.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No support for desktop or native mobile apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uses desktop browsers, and not devices, for emulating mobile devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  C# Testing Frameworks for Mobile and Desktop
&lt;/h3&gt;

&lt;p&gt;This section will cover two popular C# testing frameworks for mobile and desktop, i.e., Appium and Ranorex.&lt;/p&gt;

&lt;h3&gt;
  
  
  Appium
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt; is regarded as one of the best C# testing frameworks for mobile test automation. It is an open-source framework specifically designed for mobile applications. It leverages the mobile JSON wire protocol to enable users to create automated UI tests for native, web-based, and hybrid mobile applications on Android and iOS platforms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AJxBNmzesUml5bFZf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AJxBNmzesUml5bFZf.png" alt="image" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is compatible with various types of mobile applications, including native apps developed with the iOS or Android SDKs, mobile web apps accessed through a mobile browser, and hybrid apps that utilize WebView.&lt;/p&gt;

&lt;p&gt;Appium is a popular choice among mobile game developers, who use advanced testing techniques to simulate user inputs in input-driven games. They can also test these games simultaneously on two separate platforms using the same script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of Appium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of Appium’s important features are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It has a very active community.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports test automation on real devices, simulators, and virtual machines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers an &lt;a href="https://www.lambdatest.com/blog/appium-inspector-for-apps/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Appium Inspector&lt;/a&gt; that can inspect Android and iOS apps’ native components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ability to handle &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;end-to-end testing&lt;/a&gt; flows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example of Appium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below, you can see an example of how an Appium test script looks like that runs on LambdaTest. This is a simple example that clicks a couple of elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Appium.iOS;
using System.Threading;


namespace csharp_appium_first
{
    class Program
    {
        static void Main(string[] args)
        {
            AppiumOptions caps = new AppiumOptions();


            caps.AddAdditionalCapability("LT_USERNAME", "username");
            caps.AddAdditionalCapability("LT_ACCESSKEY", "accessKey");  
            caps.AddAdditionalCapability("app", "APP_URL");
            caps.AddAdditionalCapability("deviceName", "iPhone 12");
            caps.AddAdditionalCapability("platformVersion", "15");
            caps.AddAdditionalCapability("platformName", "iOS");
            caps.AddAdditionalCapability("isRealMobile", true);
            caps.AddAdditionalCapability("network", false);


            IOSDriver&amp;lt;IOSElement&amp;gt; driver = new IOSDriver&amp;lt;IOSElement&amp;gt;(
                new Uri("https://mobile-hub.lambdatest.com/wd/hub"), caps);




            IOSElement nf = (IOSElement)new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.Id("notification"))
            );
            nf.Click();


            driver.Navigate().Back();


            IOSElement st = (IOSElement)new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.Id("speedTest"))
            );
            st.Click();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages of Appium&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s free and open-source.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports multiple programming languages: C#, Java, JavaScript, and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy to learn for people who already know Selenium.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Appium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But also keep in mind some of the disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Limited report capabilities&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works on desktop apps, but the support is rather limited.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does not support older Android versions (before 4.2).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium online&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Automation Testing scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Ranorex
&lt;/h3&gt;

&lt;p&gt;Ranorex is a test automation tool used to automate &lt;a href="https://www.lambdatest.com/learning-hub/functional-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;functional testing&lt;/a&gt; of desktop, web, and mobile applications. It provides a wide range of features, such as a record and playback functionality, an object repository, and a set of built-in actions. Ranorex tests can be written in C#, &lt;a href="http://VB.NET" rel="noopener noreferrer"&gt;VB.NET&lt;/a&gt;, and Python and executed across multiple platforms and browsers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ap3Q6NK0QlSxDo_G2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ap3Q6NK0QlSxDo_G2.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient features of Ranorex&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of Ranorex’s notable features are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Ranorex spy allows easy UI element identification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports data-driven testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built-in integration with &lt;a href="https://www.lambdatest.com/blog/best-test-management-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test management tools&lt;/a&gt; like TestRail and Jira.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The object repository allows testers to manage and maintain test objects in a centralized location.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reporting features enable the testers to generate detailed &lt;a href="https://www.lambdatest.com/learning-hub/test-reports?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test reports&lt;/a&gt; that help identify issues and track test results over time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example of Ranorex&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is what a Ranorex test code looks like for automating login functionality in a desktop application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TestModule("36B3BA50-0797-4CDE-81E9-873F5EE516BD", ModuleType.UserCode, 1)]
    public class AddCredentialEntry : ITestModule
    {

        string _varTitle = "WordPressDemo";
        [TestVariable("8FCE8266-9831-4706-ACA6-BB8D8A06B5AE")]
        public string varTitle
        {
            get { return _varTitle; }
            set { _varTitle = value; }
        }

        string _varUsername = "admin";
        [TestVariable("E65F0C1D-2762-405A-96A0-4515BFA94FDD")]
        public string varUsername
        {
            get { return _varUsername; }
            set { _varUsername = value; }
        }


        string _varPassword = "demo123";
        [TestVariable("AE0C46C8-7A5D-45CC-83AB-44B0B8BF61C5")]
        public string varPassword
        {
            get { return _varPassword; }
            set { _varPassword = value; }
        }

        string _varURL = "bitly.com/wp_demo";
        [TestVariable("43C83430-F236-42FF-841D-A4BD6EB9C627")]
        public string varURL
        {
            get { return _varURL; }
            set { _varURL = value; }
        }


        string _varRepoIconIndex = "1";
        [TestVariable("D2BDF856-F604-4019-8F2A-8634CFFB3D18")]
        public string varRepoIconIndex
        {
            get { return _varRepoIconIndex; }
            set {
                    _varRepoIconIndex = value;
                    // Additionally set the Repository Variable in Setter-Method
                    MyRepo.varIconIndex = _varRepoIconIndex;
                }
        }


        string _varRepoExpires = "1 Year";
        [TestVariable("A4A86036-4706-4288-AFB4-B2E86A05D3C8")]
        public string varRepoExpires
        {
            get { return _varRepoExpires; }
            set {
                    _varRepoExpires = value;
                    // Additionally set the Repository Variable in Setter-Method
                    MyRepo.varExpires = _varRepoExpires;
                }
        }


        // Repository object to access UI Elements
        KeePassTestSuiteRepository MyRepo = KeePassTestSuiteRepository.Instance;

        /// Constructs a new instance.
        public AddCredentialEntry()
        {
            // Do not delete - a parameterless constructor is required!
        }

        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;

            // Click 'Add Entry' Button MainMenu
            MyRepo.MainForm.Edit.Click();
            MyRepo.KeePass.AddEntry.Click();

            // Set text fields
            MyRepo.AddEntry.Title.TextValue = varTitle;
            MyRepo.AddEntry.UserName.TextValue = varUsername;
            MyRepo.AddEntry.Password.TextValue = varPassword;
            MyRepo.AddEntry.Repeat.TextValue = varPassword;
            MyRepo.AddEntry.URL.TextValue = varURL;

            // Choose an icon
            MyRepo.AddEntry.MBtnIcon.Click();
            MyRepo.IconPicker.LI_Icon.Click(Location.CenterLeft);
            MyRepo.IconPicker.ButtonClose.Click();

            // Set Expires
            MyRepo.AddEntry.MBtnStandardExpires.Click();
            MyRepo.KeePass.MI_Expires.Click();

            // Save Credential Entry
            MyRepo.AddEntry.ButtonOK.Click();
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages of Ranorex&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main advantage of Ranorex are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It supports testing on web, mobile, and desktop apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports real device testing as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is easy to integrate into a CI/CD process with tools like Jenkins, Git, Travis CI, and Azure DevOps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of Ranorex&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Ranorex tool comes with a few downsides as well. These are as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No support for macOS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No community support, which can make it hard to find solutions to your problems online.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  C# Testing Frameworks for BDD
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Behavior Driven Development&lt;/a&gt; (BDD) is a process that supports the collaboration between the technical people in the team and the non-technical people (either in the team or in the customer’s organization).&lt;/p&gt;

&lt;p&gt;Popular C# testing frameworks for BDD are SpecFlow and BDDfy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium Testing tool&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  SpecFlow
&lt;/h3&gt;

&lt;p&gt;A really useful C# automation testing framework is SpecFlow — a BDD framework that uses Gherkin to write tests in a natural language. This makes it easy for non-technical people to understand what is being tested and to read the reports.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AwypV2d85J0jLY7dw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AwypV2d85J0jLY7dw.png" alt="image" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It can be integrated with other frameworks, such as &lt;a href="https://www.lambdatest.com/blog/specflow-tutorial-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit with Selenium&lt;/a&gt; and with Visual Studio, so the tests can run directly from the IDE’s test runner.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Nzhp5jBO8DA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient Features of SpecFlow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most notable SpecFlow features are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Integration with Visual Studio.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Good reporting capabilities — reports are easy to read.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Good support for parallel execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s a collaboration framework meant to reduce the gap between technical and non-technical staff.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allows users to write tests in a natural language syntax, making it easy for non-technical stakeholders to understand and provide feedback.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example of SpecFlow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SpecFlow tests are written in Gherkin, which in fact, looks exactly like plain English (although they allow other languages as well):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Feature: Search
The user should be able to perform searches for products in the list


@mytag
Scenario: Search for product in category
    Given I navigate to the https://ecommerce-playground.lambdatest.io/ web page
    When I select the Laptops category
    And I search for "Lenovo"
    Then the result page contains only products containing "Lenovo" in their name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The implementation behind the steps is regular C# code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of SpecFlow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are the most important pros of SpecFlow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Good documentation is available online.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open-source and free to use, making it accessible to teams of any size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports a variety of .NET languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parallel execution with SpecFlow&lt;/a&gt; can be performed by leveraging the parallelism capabilities of NUnit through SpecFlow’s dependency injection.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of SpecFlow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the cons of SpecFlow framework you should consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Writing tests in Gherkin syntax may require additional time and effort upfront, which may not be suitable for teams with tight deadlines or limited resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test execution may be slower due to the overhead of the Gherkin language and the need to convert it to executable code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  BDDfy
&lt;/h3&gt;

&lt;p&gt;BDDfy is another C# testing framework for BDD that uses the Gherkin language for easier collaboration between tech and non-tech folks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AFIB4L08XZK_9Sy3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AFIB4L08XZK_9Sy3m.png" alt="image" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient Features of BDDfy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the best features of BDDfy are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Just like with SpecFlow, the tests can be written in the Given — When — Then Gherkin language, which makes the tests easy to write even by non-technical people on the team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has good test reporting capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports standalone scenarios that don’t necessarily need to be part of user stories.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example of BDDfy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;BDDfy’s tests look similar to those of SpecFlow since they can also use the Gherkin language. Here is a sample from their documentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Scenario: Card has been disabled
Given the card is disabled
When the Account Holder requests $20
Then the ATM should retain the card
  And the ATM should say the card has been retained
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestStack.BDDfy;


namespace BDDfy.Samples.Atm
{
    [TestClass]
    public class CardHasBeenDisabled
    {
        void GivenTheCardIsDisabled()
        {
            throw new NotImplementedException();
        }


        void WhenTheAccountHolderRequestsMoney()
        {
        }


        void ThenTheAtmShouldRetainTheCard()
        {
        }


        void AndTheAtmShouldSayTheCardHasBeenRetained()
        {
        }


        [TestMethod]
        public void Execute()
        {
            this.BDDfy();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages of BDDfy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Among the main advantages of BDDfy, worth mentioning are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It can run with any testing framework, or with no testing framework, which makes it really flexible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be very easy for beginners to learn it, and the language is very intuitive.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages of BDDfy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And some of the disadvantages of using BDDfy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Documentation is somewhat limited when compared to SpecFlow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The community of users is not vast at the time of writing this article.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Expediting your C# Testing with LambdaTest
&lt;/h3&gt;

&lt;p&gt;For any developer, building quality software is a challenge. Developing testing skills is the key to creating a lasting product. C# testing frameworks are emerging to address the growing need for effective test automation.&lt;/p&gt;

&lt;p&gt;With an automation testing framework for C#, you can easily perform automated testing for your website or mobile app.&lt;/p&gt;

&lt;p&gt;Digital experience testing clouds like LambdaTest let you perform manual and &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; of your websites and web apps on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ real browsers, devices, and operating system combinations. Its cloud-based automation testing platform lets you run C# automation tests using different C# testing frameworks like Selenium, Appium, SpecFlow, NUnit, and more. With LambdaTest, developers and testers can easily perform cross-browser testing and parallelize their tests.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jrgx_3gfWVA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=video" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with detailed tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, Cypress testing, &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;LambdaTest also offers &lt;a href="https://www.lambdatest.com/hyperexecute?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;HyperExecute&lt;/a&gt; — a blazing-fast next-generation test automation cloud that helps you accelerate the release cycle while performing C# automation. It is up to 70% faster than any other conventional testing grid. HyperExecute provides optimal speed, test orchestration, and detailed execution logs to help you accelerate TTM (Time to Market).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salient Features of LambdaTest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main features of LambdaTest are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Provides a live testing feature that allows users to interact with web applications in real time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports automated testing using popular frameworks like Selenium, Cypress, Playwright, and Appium.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrations with popular project management and CI/CD tools like JIRA, Slack, Trello, Jenkins, Travis CI, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example for performing C# automation on LambdaTest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest provides an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online Selenium grid&lt;/a&gt;, so the main code will be of Selenium. But you will need to set the Selenium capabilities to use your LambdaTest account. And you can use the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;capabilities generator&lt;/a&gt; to generate the capabilities you want to include (such as operating system, browser version, resolution, etc.).&lt;/p&gt;

&lt;p&gt;This can be done in a &lt;em&gt;[SetUp]&lt;/em&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[SetUp]
public void Setup()
{
    ChromeOptions capabilities = new ChromeOptions();
    capabilities.BrowserVersion = "108.0";
    Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
    ltOptions.Add("username", LT_USERNAME);
    ltOptions.Add("accessKey", LT_ACCESS_KEY);
    ltOptions.Add("platformName", "Windows 11");
    ltOptions.Add("project", "Selenium Scroll");
    ltOptions.Add("w3c", true);
    ltOptions.Add("plugin", "c#-nunit");
    capabilities.AddAdditionalOption("LT:Options", ltOptions);
    driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a C# expert, you can also acquire a &lt;a href="https://www.lambdatest.com/certifications/selenium-c-sharp-101?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=certification" rel="noopener noreferrer"&gt;Selenium C# 101 Certification&lt;/a&gt; from LambdaTest to master the fundamentals of &lt;a href="https://www.lambdatest.com/selenium-c-sharp-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium C# testing&lt;/a&gt; and expanding your career prospects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=july_05&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium Automation Testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;scripts on the LambdaTest cloud grid. Test on 3000+ desktop &amp;amp; mobile environments. Try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Identifying the right C# testing frameworks for the job is crucial when starting a new automation testing project. Since no two projects are the same, the requirements will vary, so it is always a good idea to research all the pros and cons of the C# testing frameworks that are available.&lt;/p&gt;

&lt;p&gt;When choosing a test automation framework, testers and test managers should carefully consider whether the features match the project’s requirements, what the learning curve is, and whether the pricing fits the budget.&lt;/p&gt;

&lt;p&gt;For those interested in C# testing frameworks, this blog provides a list of frameworks with details about their features, advantages, and disadvantages.&lt;/p&gt;

</description>
      <category>testingframeworks</category>
      <category>frameworks</category>
      <category>automationtesting</category>
      <category>softwaretesting</category>
    </item>
    <item>
      <title>IWebDriver Browser Commands In Selenium C#: A Detailed Guide</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Mon, 01 May 2023 11:12:45 +0000</pubDate>
      <link>https://forem.com/testmuai/iwebdriver-browser-commands-in-selenium-c-a-detailed-guide-3bb7</link>
      <guid>https://forem.com/testmuai/iwebdriver-browser-commands-in-selenium-c-a-detailed-guide-3bb7</guid>
      <description>&lt;p&gt;Selenium WebDriver is a popular tool for automating web application testing, and it supports various programming languages, including C#. Its primary testing tool is the IWebDriver interface, which simulates an ideal web browser.&lt;/p&gt;

&lt;p&gt;In this blog on IWebDriver, we will explore the IWebDriver browser commands in C# and how they can be used to control the behavior of a web browser during testing.&lt;/p&gt;

&lt;p&gt;Understanding these commands is essential for automating interactions in web pages or web applications. We will start with a brief overview of IWebDriver and then dive into the various commands, such as navigating to a URL, clicking elements, sending keys to elements, and more.&lt;/p&gt;

&lt;p&gt;By the end of this blog on IWebDriver, you will understand IWebDriver browser commands in C# and how to use them effectively while performing &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;C# automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Discover the top 70+ essential&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/snowflake-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Snowflake test templates&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to ensure your data’s integrity, accuracy, and consistency. Download our comprehensive template now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is IWebDriver in Selenium C#?
&lt;/h3&gt;

&lt;p&gt;IWebDriver in &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium C#&lt;/a&gt; is an interface used to create a connection between &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; and the web browser to automate web applications.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver allows users to interact with web elements, navigate between pages, and execute actions on a web page.&lt;/p&gt;

&lt;p&gt;The IWebDriver interface provides a set of commands and properties that enable developers and testers to perform &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; of web applications using C# programming language.&lt;/p&gt;

&lt;p&gt;With IWebDriver, users can write scripts that mimic human actions on a website, making it an essential tool for web developers and testers who need to test their web applications efficiently and accurately.&lt;/p&gt;

&lt;p&gt;You can learn more about the IWebDriver interface through this blog on &lt;a href="https://www.lambdatest.com/blog/selenium-4-webdriver-hierarchy/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 4 WebDriver Hierarchy&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  IWebDriver Browser Commands in Selenium C
&lt;/h3&gt;

&lt;p&gt;IWebDriver browser commands in C# allow you to interact with a web browser programmatically. Some interactions possible using IWebDriver browser commands in C# are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;navigating to a URL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;clicking elements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;entering text into form fields&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are part of the IWebDriver interface in C# and provide a standard way to control a web browser for automated testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common IWebDriver Browser Commands
&lt;/h3&gt;

&lt;p&gt;The most common IWebDriver browser commands in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; are the ones that deal with the current web page information, navigating between pages, managing windows, and switching between windows, frames, and alerts. I’ll explain them briefly, but we must create a new driver instance before that. We will be demoing the same on the cloud grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;When performing &lt;a href="https://www.lambdatest.com/selenium-c-sharp-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium C# testing&lt;/a&gt;, utilizing a cloud Selenium Grid like LambdaTest can offer numerous advantages that are difficult to achieve with a local Selenium Grid. Not only does it provide scalability, reliability, and security, but it also allows for a broader range of browser coverage and &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt; in parallel. This level of flexibility and efficiency is impossible with a local Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=video" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;LambdaTest offers the added advantage of effortlessly obtaining browser properties through the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Automation Capabilities Generator&lt;/a&gt;. The utility covers everything once you choose the desired OS, browser combination, and versions. This ensures accuracy and provides a plethora of valid combinations and data while minimizing any chances of error. With this feature, you can have your code ready to use quickly!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Get a head start on your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/jenkins-test-cases?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Jenkins test templates&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;with our pre-built template for continuous testing. Explore this comprehensive list of test cases and scenarios.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the common code that will be a part of all the IWebDriver browser commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;


namespace SeleniumCSharp_BrowserCommands
{
    public class BrowserCommandsTests
    {
        private static IWebDriver driver;
        private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        private static readonly string testUrl = "https://ecommerce-playground.lambdatest.io/";


        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "latest";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "Selenium Scroll");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will be repeated before each test, so we only need to write it once. The first part of the class contains the using statements, which contain the libraries and namespaces used in the class:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuV-Y-_h5P7v8lFSA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuV-Y-_h5P7v8lFSA.png" alt="image" width="742" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then comes the variables we need in our test:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AwIVObD7pIiZxRhGh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AwIVObD7pIiZxRhGh.png" alt="image" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use the LambdaTest Selenium Grid to run the tests, we need to add the username and access key. The best way is to store them as environment variables and get the values from there.&lt;/p&gt;

&lt;p&gt;However, before running the tests, you need to set the environment variables LT_USERNAME &amp;amp; LT_ACCESS_KEY from the terminal. You can check the account details on your &lt;a href="https://accounts.lambdatest.com/detail/profile" rel="noopener noreferrer"&gt;LambdaTest Profile&lt;/a&gt; page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For macOS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export LT_USERNAME=LT_USERNAME   export LT_ACCESS_KEY=LT_ACCESS_KEY&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Linux:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;export LT_USERNAME=LT_USERNAME   export LT_ACCESS_KEY=LT_ACCESS_KEY&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;set LT_USERNAME=LT_USERNAME   set LT_ACCESS_KEY=LT_ACCESS_KEY&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In addition, we need to declare the driver and the web page URL we would like to test.&lt;/p&gt;

&lt;p&gt;The following part pertains to the test configuration, encompassing the conditions, requirements, or any other necessary code that must be executed before the commencement of the test. Here, we’re adding the desired capabilities to my Chrome driver so that the test will run on this specific configuration.&lt;/p&gt;

&lt;p&gt;The method has the &lt;em&gt;SetUp&lt;/em&gt; &lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit annotation&lt;/a&gt;, which means that it will be executed before each test. Of course, it’s not mandatory to use NUnit; other &lt;a href="https://www.lambdatest.com/blog/automation-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing frameworks&lt;/a&gt; are available in C#, such as &lt;a href="https://www.lambdatest.com/blog/nunit-vs-xunit-vs-mstest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;MSTest or xUnit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AdVvifXILw_t-nFH4TJ5n9Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AdVvifXILw_t-nFH4TJ5n9Q.png" alt="image" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Browser Navigation Commands in Selenium C
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;Navigate()&lt;/em&gt; command in Selenium C# simulates how a user would navigate online. For example, going back and forward between the pages, going to a different URL, or &lt;a href="https://www.lambdatest.com/blog/refresh-page-using-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;refreshing a page using Selenium C#&lt;/a&gt;. Let’s look at how to use them:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2023%2F04%2Funnamed-100-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2023%2F04%2Funnamed-100-1.png" alt="driver.navigate" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Navigate().GoToUrl()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;GoToUrl()&lt;/em&gt; is the most used since this is usually the prerequisite step to add to our setup before testing the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Navigate().Refresh()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;Refresh()&lt;/em&gt; command will simulate the browser page refresh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Navigate().Back() and Navigate().Forward()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;Navigate().Back()&lt;/em&gt; and &lt;em&gt;Navigate().Forward()&lt;/em&gt; commands are used to simulate the back and forward actions in the browser.&lt;/p&gt;

&lt;p&gt;So this is what the navigate commands look like when working with Selenium C#:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;

namespace SeleniumCSharp_BrowserCommands
{
    public class BrowserCommandsTests
    {
        protected static IWebDriver driver;
        private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        protected static readonly string testUrl = "https://ecommerce-playground.lambdatest.io/";

        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "latest";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "Selenium Scroll");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }

        [Test]
        public void NavigateMethods()
        {
            // Navigate to the test URL
            driver.Navigate().GoToUrl(testUrl);

            // Refresh the current page
            driver.Navigate().Refresh();

            // Go back once
            driver.Navigate().Back();

            // Go forward
            driver.Navigate().Forward();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Browser Manage Commands in Selenium C
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;Manage()&lt;/em&gt; interface instructs the driver to change its settings. This includes things like resizing the window and handling browser cookies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manage().Window&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Using the same setup as before, you can use the following commands to change the size of the window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
        public void ManageWindows()
        {
            // First, navigate to the URL
            driver.Navigate().GoToUrl(testUrl);

            // Maximize the browser window
            driver.Manage().Window.Maximize();

            // Minimize the browser window
            driver.Manage().Window.Minimize();

            // Modify the window size using the given parameters for width and height
            driver.Manage().Window.Size = new Size(500, 300);
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Manage().Cookies:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you need to work with cookies, use the &lt;em&gt;Manage()&lt;/em&gt; interface. To see the cookies the website uses in the browser, you can open the Developer Tools under the Application tab and check the Storage — Cookies menu. You can learn more about it through this blog on &lt;a href="https://www.lambdatest.com/blog/handling-cookies-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;handling cookies in Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are the cookies of our test website:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A-xfCLh7STVoyKInRf4-mUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A-xfCLh7STVoyKInRf4-mUg.png" alt="image" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is how the commands look in a test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void CookiesCommands()
{
    driver.Navigate().GoToUrl(testUrl);

    // Add a new cookie
    driver.Manage().Cookies.AddCookie(new Cookie("cookieName", "value"));

    // Retrieve a cookie based on its name
    // In this case, the "currency" cookie
    var cookie = driver.Manage().Cookies.GetCookieNamed("currency");

    // Delete a cookie based on its name
    // In this case, the "language" cookie
    driver.Manage().Cookies.DeleteCookieNamed("language");

    // Delete a given cookie
    // In this case, the cookie saved as a variable earlier
    driver.Manage().Cookies.DeleteCookie(cookie);

    // Deletes all the cookies
    driver.Manage().Cookies.DeleteAllCookies();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Switch Window Commands in Selenium C
&lt;/h3&gt;

&lt;p&gt;Window switching or using the &lt;em&gt;SwitchTo()&lt;/em&gt; command in test automation is a technique used to switch between different windows or frames within a web application. This command is used in Selenium, a popular test automation framework, to switch the driver’s focus to a different window or frame to perform the subsequent actions in the appropriate context.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;SwitchTo()&lt;/em&gt; commands in Selenium allow you to move the focus to a different window, a frame, or an alert. Let’s have a look at how they work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SwitchTo().Window()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can open multiple browser windows (or tabs) simultaneously where you want to interact with them one at a time — even if the interaction might mean only closing them. To get the full list of opened windows, you can use the &lt;em&gt;CurrentWindowHandle&lt;/em&gt; or &lt;em&gt;WindowHandles&lt;/em&gt; properties, then switch to the desired window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void SwitchWindows()
{
    // Get the current window’s handle
    var handle = driver.CurrentWindowHandle;

    // Get the list of all opened windows’ handles
    var handles = driver.WindowHandles;

    //Switch to the window you want active in your test
    driver.SwitchTo().Window(handle);

    //Switch to the window you want active in your test, by selecting it from a list
    driver.SwitchTo().Window(handles[3]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SwitchTo().Alert()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An alert is a dialog box that appears on the screen and interrupts the user’s interaction with the web application until it is either dismissed or handled.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/handling-webelements-in-selenium-python/#alert?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Handling alerts in Selenium&lt;/a&gt; is an essential aspect of test automation because alerts are commonly used in web applications for various purposes, such as validation, confirmation, or error reporting. If an alert is not handled properly in a test automation script, it can cause the script to fail or produce inaccurate results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Get a head start on your CI/CD pipeline with our pre-built template for automated testing. Explore this comprehensive list of&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/cicd-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;CI/CD test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;and scenarios.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, we will see how the alerts work, taking &lt;a href="https://www.lambdatest.com/selenium-playground/javascript-alert-box-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Playground&lt;/a&gt; as an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Am2deEH77ri2kXka9Mmyi2A.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Am2deEH77ri2kXka9Mmyi2A.gif" alt="image" width="1600" height="819"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have an alert with a confirm box that allows adding a text before accepting or dismissing it. But before I act on the alert, I must switch to it. Here’s how the switch command for alerts looks and the available actions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A8xuZfqr59h3m4CdA7GGyUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A8xuZfqr59h3m4CdA7GGyUg.png" alt="image" width="459" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have one scenario for dismissing the alert:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void DismissAlert()
{
    // Navigate to the desired page
driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/javascript-alert-box-demo");

    // Identify the button to click
    driver.FindElement(By.XPath("//div[contains(text(),'Java Script Alert Box')]/following-sibling::p/button")).Click();

    // Dismiss the alert
    driver.SwitchTo().Alert().Dismiss();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And another one where we use both the &lt;em&gt;SendKeys()&lt;/em&gt; and the &lt;em&gt;Accept()&lt;/em&gt; commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void SendKeysAndAcceptAlert()
{
    // Navigate to the desired page
    driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/javascript-alert-box-demo");

    // Identify the button to click
    driver.FindElement(By.XPath("//div[contains(text(),'Java Script Alert Box')]/following-sibling::p/button")).Click();

    // Enter text in the alert box
    driver.SwitchTo().Alert().SendKeys("It's me, Mario");

    // Accept the alert
    driver.SwitchTo().Alert().Accept();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To find an element on a page and click it (before the alert pops, you need to press the &lt;em&gt;Click me&lt;/em&gt; buttons), you need to use the &lt;a href="https://www.lambdatest.com/blog/findelements-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;em&gt;findElement()&lt;/em&gt; Selenium command&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SwitchTo().Frame()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Web pages can be divided into several sections using HTML frames, and each section can load a different HTML document. Sometimes you want to interact with elements that are inside a different frame than the active one, so you need, once more, to use the &lt;a href="https://www.lambdatest.com/blog/handling-frames-and-iframes-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;switch command in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To demonstrate, let’s take a look at this web page. If you check its code, it contains several frames (marked by the HTML tag &lt;em&gt;iframe&lt;/em&gt;). Here’s how you can work with them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void SwitchToFrames()
{
    // Navigate to the desired page
    driver.Navigate().GoToUrl("https://codepen.io/fidabrj/pen/NWYeaqG");

    // Switch to frame by name
    driver.SwitchTo().Frame("result");

    // Switch to the parent frame
    driver.SwitchTo().ParentFrame();

    // Switch to the first frame or the main document of the web page
    driver.SwitchTo().DefaultContent();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Close and Quit Commands in Selenium C
&lt;/h3&gt;

&lt;p&gt;If you want to close the browser instances opened by Selenium, you have two options. The first is to close the current window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Close();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or close all opened windows. I recommend using a &lt;em&gt;TearDown&lt;/em&gt; method for your tests — to close all opened instances of the browser at the end of each test. It should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TearDown]
public void TearDown()
{
    driver.Quit();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Url, Title, and PageSource properties in Selenium C
&lt;/h3&gt;

&lt;p&gt;The next three subpoints are not commands in Selenium C# but properties. They are nevertheless important and often used in UI tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALyU8FdMRtm5nE5aR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ALyU8FdMRtm5nE5aR.png" alt="image" width="486" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Url&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first on the list is the &lt;em&gt;Url&lt;/em&gt; property. This is the address of the opened web page and is stored as a string.&lt;/p&gt;

&lt;p&gt;This can be useful when you want to check that the navigation was done correctly after other actions performed in the application, like clicking a link or pressing a button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Discover the top 50+ essential&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/flutter-testing-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Flutter test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to ensure your mobile applications are bug-free before their release. Download our comprehensive template now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PageTitle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly, you can obtain the current page title as a string. This is handy to validate that the page has the correct title.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PageSource&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And last but not the list, you can also obtain the page’s source code, similar to what you see in the browser when you right-click on the page and select “View page source”.&lt;br&gt;&lt;br&gt;
Using these three attributes in a test looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void Properties()
{
    driver.Navigate().GoToUrl(testUrl);

    // Validate that the page title is correct
    Assert.That(driver.Title == "Your Store");

    // Validate that the page Url is correct
    Assert.That(driver.Url == testUrl);

    // Validate that the page source contains expected text
    Assert.That(driver.PageSource.Contains("Top Trending Categories"));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will explain how the &lt;em&gt;Assert&lt;/em&gt; works in a bit, too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Demonstration — Selenium IWebDriver Browser Commands in C
&lt;/h3&gt;

&lt;p&gt;In this section of the IWebDriver browser commands tutorial, let’s see a scenario that uses some of these IWebDriver browser commands to see them in a testing context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the page &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maximize the browser window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Special link.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the page title is “Special offers”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go back to the previous page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the URL is &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the cookie “currency” has the value “USD”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the browser window.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the code you need for this test, created with Selenium 4.8 and &lt;a href="https://www.lambdatest.com/blog/nunit-parameterized-test-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit testing framework&lt;/a&gt;. If you need help setting up the project and adding driver capabilities, follow the steps in this &lt;a href="https://www.lambdatest.com/blog/selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;

namespace SeleniumCSharp_BrowserCommands
{
    public class BrowserCommandsTests
    {
        private static IWebDriver driver;
        private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        private static readonly string testUrl = "https://ecommerce-playground.lambdatest.io/";

        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "108.0";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "Selenium Scroll");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }


        [Test]
        public void NavigateTest()
        {    
            driver.Navigate().GoToUrl(testUrl);
            driver.Manage().Window.Maximize();
            driver.FindElement(By.PartialLinkText("Special")).Click();
            Assert.That(driver.Title.Equals("Special Offers"));
            driver.Navigate().Back();
            Assert.That(driver.Url.Equals(testUrl));
            var cookie = driver.Manage().Cookies.GetCookieNamed("currency");
            Assert.That(cookie.Value.Equals("USD"));
        }

        [TearDown]
        public void TearDown()
        {
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first part is the setup we created above, so there’s no real need to get into its details again. So let’s jump directly to the test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Ad1DJ5wGN3NcYS42mDN-hOw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Ad1DJ5wGN3NcYS42mDN-hOw.png" alt="image" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, the method is marked with the &lt;em&gt;Nunit [Test]&lt;/em&gt; annotation, which means it will show up in the Test Explorer of Visual Studio:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATHqE_zBNyuPcZpo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATHqE_zBNyuPcZpo2.png" alt="image" width="508" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will be using some of the commands discussed earlier. To navigate to the web page’s address, we have the &lt;em&gt;Navigate()&lt;/em&gt; command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AHgoZPqav5k_pD7ugsFcaZg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AHgoZPqav5k_pD7ugsFcaZg.png" alt="image" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, we maximize the window using:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4xOAMD1s8pwbLiwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4xOAMD1s8pwbLiwi.png" alt="image" width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up, we need to interact with an element to click on it. We can use &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath&lt;/a&gt; as a locator, and the &lt;em&gt;Click()&lt;/em&gt; command to interact with the web element:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A4sRXTssvPFg01NudydAj3Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A4sRXTssvPFg01NudydAj3Q.png" alt="image" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fourth step of the test is to verify that the web page has the correct title. This is easily done using the &lt;em&gt;Title&lt;/em&gt; attribute and comparing it with the expected value. We use the &lt;a href="https://www.lambdatest.com/blog/asserts-in-nunit/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Assert class&lt;/a&gt;, provided by NUnit. The test will continue if the two values are equal and the validation passes. If the assertion fails, the test will fail, and the following steps will not be executed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnFgP3Z_QubSFU7mm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnFgP3Z_QubSFU7mm.png" alt="image" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moving on, we go back one page, using the command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Af4OaDBCErwyUirCxm4QBIw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2Af4OaDBCErwyUirCxm4QBIw.png" alt="image" width="680" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s usually a good practice to keep the number of assertions to a minimum; for the sake of this demonstration, I will use more than one assertion in this test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn 43 excellent test cases for&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/salesforce-test-cases?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;salesforce test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;by reading this guide. Every significant test case will be covered in detail in this guide, along with how to set up your Salesforce testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we want to check that the back navigation worked as expected, so we assert that the current Url of the page is the same as the first Url we used (the one stored in the &lt;em&gt;testUrl&lt;/em&gt; variable):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AP1WXMq5wrG9lpqQlN0Uf-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AP1WXMq5wrG9lpqQlN0Uf-g.png" alt="image" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also want to verify that the currency cookie is set to USD. For this, we must first get the cookie information and store it in a variable:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AV26ebglKwcBXW537.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AV26ebglKwcBXW537.png" alt="image" width="800" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And check that the cookie’s value is the expected one, using another assert:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AAIJeVJdVsSDbUUyxxVl9yg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AAIJeVJdVsSDbUUyxxVl9yg.png" alt="image" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last step is closing the browser. However, I want this step to execute regardless of the status of the previous steps, so I added it to a teardown method. In this specific example, I only have one test, but in a real-life project with multiple tests, a method marked with the &lt;em&gt;[TearDown]&lt;/em&gt; NUnit annotation will run after each test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A5_iVEYheP5wPOQutsTa-2A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A5_iVEYheP5wPOQutsTa-2A.png" alt="image" width="634" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are a developer or tester who wants to take your Selenium C# skills to the next level, consider taking Selenium C# 101 certification by LambdaTest. The certification is designed to validate the skills and knowledge of testers and developers who work with Selenium and C#.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Read this tutorial about&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/servicenow-test-case-template?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may01_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;ServiceNow Test cases&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;, to know what it is, it’s benefits, types and test cases.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Understanding the IWebDriver browser commands in Selenium C# is essential for any aspiring automation tester or developer who wants to build efficient and robust automated tests. This blog has provided an overview of the various IWebDriver browser commands available in Selenium’s IWebDriver interface, including navigation commands, window, and frame and cookie commands.&lt;/p&gt;

&lt;p&gt;Additionally, we have seen how to use these commands in C# code examples. With this knowledge, you can build robust automated tests with Selenium and C# to help you deliver high-quality software applications.&lt;/p&gt;

</description>
      <category>webdriver</category>
      <category>selenium</category>
      <category>guide</category>
      <category>automationtesting</category>
    </item>
    <item>
      <title>How To Scroll Down A Page In Selenium WebDriver Using C#</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Fri, 17 Mar 2023 04:34:12 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-scroll-down-a-page-in-selenium-webdriver-using-c-pjg</link>
      <guid>https://forem.com/testmuai/how-to-scroll-down-a-page-in-selenium-webdriver-using-c-pjg</guid>
      <description>&lt;p&gt;Scrolling up or down, and even horizontally, is quite common when navigating a web page. In test automation, this becomes important when you want to check that all the expected elements are displayed on the page. For example, the button to scroll back up works fine or interacts with elements that otherwise are not visible.&lt;/p&gt;

&lt;p&gt;In version 4.2, &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; introduced scroll wheel actions; however, these only work with the Chromium browser. To scroll down a page in &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium C#&lt;/a&gt;, you will need to stick with the JavaScriptExecutor for other browsers or if you are using an older Selenium version.&lt;/p&gt;

&lt;p&gt;In this blog, we will look at how to scroll down a page in Selenium WebDriver using C#.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JavaScriptExecutor in Selenium?
&lt;/h3&gt;

&lt;p&gt;So, I mentioned JavaScriptExecutor, but what is it exactly? In short, it’s an interface to use with Selenium to interact with the web elements on a page using JavaScript code. This is because even Selenium has some limitations when it comes to web interactions, and JavaScript is a front-end programming language, which means it was designed specifically for the visible part of a web app.&lt;/p&gt;

&lt;p&gt;Some of these actions include scrolling up and down a page, going back a certain number of pages, and interacting with elements. Selenium does this as well, but I’ll explain why JavaScript Executor is sometimes better later.&lt;/p&gt;

&lt;p&gt;The syntax for &lt;a href="https://www.lambdatest.com/blog/how-to-use-javascriptexecutor-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JavaScriptExecutor in Selenium&lt;/a&gt; is shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IJavaScriptExecutor js = (IJavaScriptExecutor) driver;
js.ExecuteScript("script to execute");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;IJavaScriptExecutor&lt;/strong&gt; is the interface you need to cast on the driver object. Then, using the &lt;strong&gt;ExecuteScript&lt;/strong&gt; method, pass the JavaScript script as a parameter. We’ll see it in action in upcoming sections of this blog on how to scroll down a page in &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; using C#.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Can JavaScriptExecutor Help in Selenium Exceptions?
&lt;/h3&gt;

&lt;p&gt;Not only can JavaScriptExecuter perform additional actions, but it can also help avoid potential exceptions without requiring extra steps. Some of these &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Exceptions&lt;/a&gt; are listed below.&lt;/p&gt;

&lt;h3&gt;
  
  
  NoSuchElementException
&lt;/h3&gt;

&lt;p&gt;If your test throws a &lt;strong&gt;NoSuchElementException&lt;/strong&gt;, ensure you’re using the correct locator for the element. You can check that simply by typing the locator in the search bar of the &lt;strong&gt;Elements&lt;/strong&gt; tab in Developer Tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ASy0l-alT1e2Qpzol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ASy0l-alT1e2Qpzol.png" alt="image" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Developer Tools will show how many elements were found and highlight the currently selected element in the HTML of the web page and on the page itself (see above my search for an ID on the page).&lt;/p&gt;

&lt;p&gt;Once that’s out of the way, you can know that the element is loaded on the web page and the right locator is used. In this case, it’s safe to assume that the exception comes from the fact that the element is not visible because the page needs to be scrolled down.&lt;/p&gt;

&lt;p&gt;The command for this is shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;js.ExecuteScript("window.scrollBy(0,250)", "");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that the page will be scrolled down by 250 pixels. You can use the same command to scroll up using a negative value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;js.ExecuteScript("window.scrollBy(0,-250)", "");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ElementClickInterceptedException
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;ElementClickInterceptedException&lt;/strong&gt; is thrown when the element is found on the page, but a different element overlaps our element, and the click would be performed on this incorrect element.&lt;/p&gt;

&lt;p&gt;For example, when a prompt is loaded on a page with some action like “sign in” or “sign up” or when a menu is expanded on top of the element that interests you. To overcome this, you can use the click from the JavaScriptExecutor instead of the Selenium one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;js.ExecuteScript("arguments[0].click();", myElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Demonstration: How to Scroll Down A Page In Selenium WebDriver using C
&lt;/h3&gt;

&lt;p&gt;Before we look at some examples of how to scroll down a page in Selenium WebDriver using C# to perform various types of scrolling, let’s set up a new test project. I’ll use the LambdaTest eCommerce Playground for the following scenarios — scrolling up, scrolling down, and scrolling to a specific element.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download and install Visual Studio.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new Visual Studio (or Visual Code) project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, add Selenium.WebDriver NuGet package — you can do this by right-clicking on the solution name in &lt;strong&gt;Solution Explorer → Manage NuGet Packages&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ARg25kp8MX6c018Xo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ARg25kp8MX6c018Xo.png" alt="image" width="800" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/appium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Appium Automation&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tutorial, learn about Appium and its benefits for mobile automation testing. Take a look at how Appium works and see how to perform Appium testing of your mobile applications.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also add the package from the console, in the &lt;strong&gt;Tools → NuGet Package Manager → Package Manager Console,&lt;/strong&gt; by running the following command. At the time of writing this blog on how to scroll down a page in Selenium WebDriver using C#, the latest version of Selenium.WebDriver NuGet package is 4.7.0, so I will be using this moving forward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PM&amp;gt; NuGet\Install-Package Selenium.WebDriver -Version 4.7.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuWRruRgsRRj8Cg4S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AuWRruRgsRRj8Cg4S.png" alt="image" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I’ll be using my LambdaTest platform to run my tests — this will help me run the tests on a different setup than what I have on my local machine or even run tests in parallel without using my machine’s resources.&lt;/p&gt;

&lt;p&gt;LambdaTest is a &lt;a href="https://www.lambdatest.com/learning-hub/continuous-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;continuous testing&lt;/a&gt; platform that lets you perform &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;C# automation testing&lt;/a&gt; of websites and web applications across 3000+ real desktop and mobile browsers. You can automate your tests with frameworks like Selenium, Cypress, &lt;a href="http://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, and more. It further allows you to accelerate your test cycles by running automated C# tests in parallel.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SqQ8SugRDos"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; to see our latest tutorials about &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, Cypress testing, &lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;I’ll be using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Automation Capabilities Generator&lt;/a&gt; to create this setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Annl08YBocxhBWLGO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Annl08YBocxhBWLGO.png" alt="image" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After generating the automation capabilities, I will copy it into my test class as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;


namespace ScrollAction_SeleniumWebDriver
{
    public class ECommerceTests
    {
        private static IWebDriver driver;
        private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        private static readonly string testUrl = "https://ecommerce-playground.lambdatest.io/";


        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "108.0";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "Selenium Scroll");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;In this blog section of how to scroll down a page in Selenium WebDriver using C#, we will use the JavaScriptExecutor to scroll a page, let’s understand the above code.&lt;/p&gt;

&lt;p&gt;In the above test script, the class starts with &lt;strong&gt;using&lt;/strong&gt; statements. These are used to instruct the code about the packages that will be used inside our class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A7HG73fP_HK0qNmw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A7HG73fP_HK0qNmw1.png" alt="image" width="742" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only difference between these two &lt;strong&gt;using&lt;/strong&gt; statements is that to run on the &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; with LambdaTest, you need to use the &lt;strong&gt;OpenQA.Selenium.Remote&lt;/strong&gt; namespace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A1-e8VQMXtE-2a9rW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A1-e8VQMXtE-2a9rW.png" alt="image" width="742" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moving on, we have the variables we need to set up for our tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApRrfBPomqXhzidzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApRrfBPomqXhzidzA.png" alt="image" width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, if you run your tests locally, you don’t need to define the &lt;strong&gt;gridURL, LT_USERNAME&lt;/strong&gt;, and &lt;strong&gt;LT_ACCESS_KEY&lt;/strong&gt;. You only need the &lt;strong&gt;driver&lt;/strong&gt;, which is the object that receives the requests from Selenium and sends them to the actual browser, and the &lt;strong&gt;testURL&lt;/strong&gt;, a string that stores our website URL, so we don’t have to write it again every time.&lt;/p&gt;

&lt;p&gt;If you test on the cloud grid, you also need the username and access key — I have them stored as environment variables because I find it safer, and if they change, I only need to change them in one place and not update all my projects that use them. The &lt;strong&gt;gridURL&lt;/strong&gt; is a string I will be using a bit later.&lt;/p&gt;

&lt;p&gt;Next comes the setup method: thanks to NUnit, using the &lt;strong&gt;SetUp&lt;/strong&gt; annotation, the code knows that the method marked as &lt;strong&gt;SetUp&lt;/strong&gt; needs to run before each test. We have a &lt;strong&gt;SetUp&lt;/strong&gt; method whether we test on the grid:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AeW5BK8jngpFNP_Nr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AeW5BK8jngpFNP_Nr.png" alt="image" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use all the capabilities defined above with the Capabilities Generator. Then the driver will be a new instance of the remote driver, using the URI created using the &lt;strong&gt;username, access key&lt;/strong&gt;, and the &lt;strong&gt;gridURL&lt;/strong&gt; variable we declared first.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Scroll to the Bottom of the Page in Selenium C#?
&lt;/h3&gt;

&lt;p&gt;The first test I’ll write will scroll to the bottom of a web page. I’ll use the LambdaTest eCommerce Playground to do this. The idea is that to interact with the elements at the bottom of the page, I need to bring them into view.&lt;/p&gt;

&lt;p&gt;As previously mentioned, we will need a JavaScriptExecutor to do this. The test class will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void ScrollToTheBottom()
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    driver.Navigate().GoToUrl(testUrl);
    js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens here is that I used the NUnit &lt;strong&gt;[Test]&lt;/strong&gt; annotation to mark my method as a test method — pretty straightforward here. This means that it will show up in my Test Explorer, and I can run it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ar0mXoU8L0T6m1TN_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ar0mXoU8L0T6m1TN_.png" alt="image" width="628" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first line inside the method is where I declare a new variable of the type &lt;strong&gt;IJavaScriptExecutor&lt;/strong&gt;, which will cast upon the driver:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4cb17yWk4CxXzean.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A4cb17yWk4CxXzean.png" alt="image" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up comes opening the test site (the &lt;strong&gt;testUrl&lt;/strong&gt; variable declared before) using the &lt;strong&gt;Navigate().GoToUrl()&lt;/strong&gt; Selenium command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ABE4di7HMG557zgGN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ABE4di7HMG557zgGN.png" alt="image" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And last but not least, we have the &lt;strong&gt;scrollTo&lt;/strong&gt; command that performs the actual scroll.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AByqlW_DAsNNm5Ghk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AByqlW_DAsNNm5Ghk.png" alt="image" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What happens here is the first parameter of the scroll represents the horizontal value. I don’t want to scroll horizontally, so I will leave it to 0. For the second parameter, I don’t know the exact length of the page, so I give it the &lt;strong&gt;document.body.scrollHeight&lt;/strong&gt; value. This value represents the height of the loaded page.&lt;/p&gt;

&lt;p&gt;You can see the &lt;strong&gt;scrollHeight&lt;/strong&gt; in the browser using the Console of Developer Tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ap70C4_E0gFVsEQu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Ap70C4_E0gFVsEQu0.png" alt="image" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ll also add a &lt;strong&gt;TearDown&lt;/strong&gt; method so the browser doesn’t stay open after the test completes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TearDown]
public void TearDown()
{
    driver.Quit();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The TearDown &lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Annotation in NUnit&lt;/a&gt; is a method to be run after each test. The single command I need is the one that closes all instances of the driver — &lt;strong&gt;Quit()&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The result can be seen when running the test on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AqPiBIgT105FyZVb4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AqPiBIgT105FyZVb4.gif" alt="image" width="1600" height="814"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see here that all the test steps were executed and passed successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AeByWAdRqxB2812ii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AeByWAdRqxB2812ii.png" alt="image" width="642" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this Data driven testing tutorial, let us deep dive into what data driven testing is, its pros &amp;amp; cons, its types,&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/data-driven-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;data driven testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;in an agile environment, benefits, and their best practices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Scroll to the Top of the Page in Selenium C#?
&lt;/h3&gt;

&lt;p&gt;By default, the page will load and scroll to the top, so simply executing a script that scrolls up will look like the test didn’t do anything.&lt;/p&gt;

&lt;p&gt;In this blog section of how to scroll down a page in Selenium WebDriver using C#, I will modify my existing test to scroll back up after scrolling down, so both scrolls can be visible in the &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void ScrollToTheBottomAndBackToTheTop()
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    driver.Navigate().GoToUrl(testUrl);
    js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
    js.ExecuteScript("window.scrollTo(0, -document.body.scrollHeight)");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only new line of code is the last one. It looks the same as the one above, with the notable difference that it will use the same scroll amount but in the negative.&lt;/p&gt;

&lt;p&gt;You can see the below video logs of the test execution that the page has scrolled down and then to the top.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWYU1OWKxTRwoxDGT.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWYU1OWKxTRwoxDGT.gif" alt="image" width="1600" height="814"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Scroll Down a Page in Selenium WebDriver with C# by Given the Number of Pixels?
&lt;/h3&gt;

&lt;p&gt;If you know the precise position where you want to scroll, you can execute a script that scrolls by that number of pixels. I’ll write a new test this time that opens the same web page and scrolls it down by 500 pixels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void ScrollByAmount()
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    driver.Navigate().GoToUrl(testUrl);
    js.ExecuteScript("window.scrollBy(0,500)");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To scroll up, use the same command, but by a negative number of pixels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;js.ExecuteScript("window.scrollBy(0,-500)");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Scroll to an Element with Selenium C#?
&lt;/h3&gt;

&lt;p&gt;The above scenario is probably not a very likely one. It will, however, be more common to want to scroll to a specific element on the page.&lt;/p&gt;

&lt;p&gt;For this, you first want to identify the element on the page using the &lt;a href="https://www.lambdatest.com/blog/selenium-locators-cheat-sheet/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For this example, I want to scroll to the &lt;strong&gt;Shop Now&lt;/strong&gt; button highlighted in the screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AZ-cIzufVWQjEUxpH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AZ-cIzufVWQjEUxpH.png" alt="image" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see that the page is scrolled around the middle, the same things I want my test to perform. But I don’t want to give a specific number of pixels. Instead, I will specify the element I want to bring into view.&lt;/p&gt;

&lt;p&gt;To identify the element, I will use XPath as a locator and the &lt;a href="https://www.lambdatest.com/blog/selectorshub-an-innovation-for-all-the-unsolved-xpath-selectors-problems/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SelectorsHub&lt;/a&gt; Chrome extension to get it.&lt;/p&gt;

&lt;p&gt;The steps are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Right-click on the element and choose &lt;strong&gt;Inspect&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As shown below in the screenshot, copy the relative XPath from SelectorsHub and use it in the test.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbDWDplStT7mmW2PQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AbDWDplStT7mmW2PQ.png" alt="image" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here’s how the test looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void ScrollToElement()
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    driver.Navigate().GoToUrl(testUrl);
    var button = driver.FindElement(By.XPath("//a[@class='btn btn-outline-primary btn-lg']"));
    js.ExecuteScript("arguments[0].scrollIntoView();", button);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this test, we have a new variable for the element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADi7m3CJlfYbnOKUc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ADi7m3CJlfYbnOKUc.png" alt="image" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am using the &lt;strong&gt;driver.*FindElement&lt;/strong&gt;* command, with the chosen selector XPath, and using the XPath from before. For more information about the &lt;strong&gt;driver.FindElement&lt;/strong&gt; command, check out this article on using the &lt;a href="https://www.lambdatest.com/blog/findelements-in-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;driver.FindElement And driver.FindElements In Selenium C#.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the last line is the &lt;strong&gt;JavaScriptExecuteScript&lt;/strong&gt;, where I tell my code to scroll to the element&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AlWDV4UMdt8OWYeQw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AlWDV4UMdt8OWYeQw.png" alt="image" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Scroll Horizontally with Selenium C#?
&lt;/h3&gt;

&lt;p&gt;In this blog section of how to scroll down a page in Selenium WebDriver using C#, we will learn how to scroll horizontally. To demonstrate this, I will use a different page, the LambdaTest Web Technologies Browser Compatibility, and I will resize the browser window to make sure that the horizontal scroll is visible:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6B1Jo76HLm9-6mN7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6B1Jo76HLm9-6mN7.png" alt="image" width="621" height="920"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using System.Drawing;


namespace ScrollAction_SeleniumWebDriver
{
    public class ECommerceTests
    {
        private static IWebDriver driver;
        private static readonly string gridURL = "@hub.lambdatest.com/wd/hub";
        private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
        private static readonly string testUrl = "https://www.lambdatest.com/web-technologies";


        [SetUp]
        public void Setup()
        {
            ChromeOptions capabilities = new ChromeOptions();
            capabilities.BrowserVersion = "108.0";
            Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;();
            ltOptions.Add("username", LT_USERNAME);
            ltOptions.Add("accessKey", LT_ACCESS_KEY);
            ltOptions.Add("platformName", "Windows 11");
            ltOptions.Add("project", "Selenium Scroll");
            ltOptions.Add("w3c", true);
            ltOptions.Add("plugin", "c#-nunit");
            capabilities.AddAdditionalOption("LT:Options", ltOptions);
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities);
        }


        [Test]
        public void ScrollHorizontally()
        {
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            driver.Manage().Window.Size = new Size(200, 1500);
            driver.Navigate().GoToUrl(testUrl);
            js.ExecuteScript("window.scrollBy(50,0)");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What I have different now is the &lt;strong&gt;System.Drawing&lt;/strong&gt; namespace, which allows me to give the new size to the window, the different testUrl, and the &lt;strong&gt;driver.Manage().Window.Size&lt;/strong&gt; method.&lt;br&gt;&lt;br&gt;
&amp;lt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Manage().Window.Size = new Size(200, 1500);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above line of command changes the driver window size to 200 by 1500 pixels. This allows the horizontal scroll to appear so I can run my test. The JavaScript command is the same as the one used for vertical scrolling by a given number of pixels, except this time, I gave a value to the first argument of the &lt;strong&gt;scrollBy()&lt;/strong&gt; method, which signifies the horizontal amount, and 0 to the second argument, which is the vertical amount.&lt;/p&gt;

&lt;p&gt;You can scroll vertically and horizontally simultaneously by giving both values in pixels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;js.ExecuteScript("window.scrollBy(50,100)");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s see how that looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AprzDBNrBmEiKkZkh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AprzDBNrBmEiKkZkh.gif" alt="image" width="1600" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the content of the page was moved as the scroll was performed.&lt;/p&gt;

&lt;p&gt;To demonstrate your expertise as a tester the Selenium C# 101 certification from LambdaTest is a great way to demonstrate your proficiency as a tester. By earning this certificate, you can stand out from the crowd and highlight your C# automation skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/xcuitest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;XCUITest&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tutorial, learn about XCUITest framework and its benefits for mobile automation testing. Take a look at how XCUITest works and see how to use it to test your mobile applications.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summing Up
&lt;/h3&gt;

&lt;p&gt;With this, you now know how to scroll down a page in Selenium WebDriver using C#. In &lt;a href="https://www.lambdatest.com/learning-hub/web-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar17_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;web automation&lt;/a&gt; with Selenium, we can sometimes find ourselves in situations where using just simple Selenium commands is not enough to achieve our goals. One of these situations is where the web page under test has a vertical or horizontal scroll or both, and scrolling needs to be done on the page.&lt;/p&gt;

&lt;p&gt;While Selenium only provides scrolling capabilities limited to specific browsers, we can insert JavaScript commands in our Selenium tests to overcome these limitations. We can do this by using the &lt;strong&gt;IJavaScriptExecutor&lt;/strong&gt; interface provided by Selenium, which sends JavaScript commands to the browser that allow us to scroll up, down, horizontally, or to a specific web element on the page.&lt;/p&gt;

</description>
      <category>selenium</category>
      <category>webdriver</category>
      <category>automationtesting</category>
      <category>cloudtesting</category>
    </item>
    <item>
      <title>How To Use driver.FindElement And driver.FindElements In Selenium C#</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Tue, 21 Feb 2023 06:41:00 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-use-driverfindelement-and-driverfindelements-in-selenium-c-5e6f</link>
      <guid>https://forem.com/testmuai/how-to-use-driverfindelement-and-driverfindelements-in-selenium-c-5e6f</guid>
      <description>&lt;p&gt;One of the essential parts when performing &lt;a href="https://www.lambdatest.com/automated-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated UI testing&lt;/a&gt;, whether using &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NoSuchElementException in Selenium.&lt;/a&gt; This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.&lt;/p&gt;

&lt;p&gt;To do this, we have two methods: &lt;em&gt;driver.FindElement&lt;/em&gt; and &lt;em&gt;driver.FindElements&lt;/em&gt; in Selenium C#. The first one is needed when we want to identify a single element, such as an input field where we want to enter some text or a button on which we want to click. The second one is useful when we need to check multiple elements of the same type — for example, when we want to check that a drop-down list contains all the expected values.&lt;/p&gt;

&lt;p&gt;In this blog on using &lt;em&gt;driver.FindElement&lt;/em&gt; and &lt;em&gt;driver.FindElements&lt;/em&gt; in Selenium C#, I will use Selenium 4.4.0. But, before we deep dive into how and when to use each of the &lt;em&gt;FindElement&lt;/em&gt; and &lt;em&gt;FindElements&lt;/em&gt; commands, let’s discuss how to identify the web elements on the page.&lt;/p&gt;

&lt;p&gt;When we use the FindElement() and FindElements() commands, we need to identify the web elements by locators. The syntax is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 driver.FindElement(By.locator_strategy)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Locators enable testers to select an HTML DOM element to interact with. Selecting the right &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;locator strategies&lt;/a&gt; for these web elements can be crucial for the stability of the UI tests. You don’t want your tests to fail just because they didn’t find the correct button to click on or the correct text input to write in, right?&lt;/p&gt;

&lt;p&gt;The locators are available for selection, and I will explain each of them below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AQdugCqF2MXUE20Pn.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AQdugCqF2MXUE20Pn.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This tutorial dive deep into&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;web testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;to help you understand its life cycle, elements, angles, the role of automation, and more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Traditional Locators in Selenium
&lt;/h2&gt;

&lt;p&gt;Selenium supports multiple locator strategies. Firstly, we have the traditional locators. These are locators that relate directly to the web element’s attributes. Traditional locators are supported in all versions of Selenium. The eight traditional locators are explained below:&lt;/p&gt;

&lt;h3&gt;
  
  
  ID locator in Selenium
&lt;/h3&gt;

&lt;p&gt;In a perfect world, each web element on our applications under test has an ID attribute. To find if the element has an ID or to see its ID, you simply have to right-click the element on the page and select Inspect (below I will demonstrate using the Chrome browser, but all major browsers have this functionality):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AveDH6YRQjgRvIyOr.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AveDH6YRQjgRvIyOr.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open up the Elements pane in the Developer Tools, which contains the page’s HTML code. Here, you can see the attributes of the HTML element. In my example, the field has an ID so I could use it in my UI tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform manual or automated cross browser&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;web testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;on 3000+ browsers online. Deploy and scale faster with the most powerful cross browser testing tool online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A4Mb84SGkdRADaDCE.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A4Mb84SGkdRADaDCE.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what I need to use in my tests is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 driver.FindElement(By.Id("user-message"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  ClassName locator in Selenium
&lt;/h3&gt;

&lt;p&gt;The class attribute in HTML is commonly used to point to a class in the CSS sheet. Multiple elements can share the same class and therefore the same styling.&lt;/p&gt;

&lt;p&gt;The same element can also have multiple classes. You can see the class name (if the element has one) in the same panel as above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AH4g22S6WkOsQ-z4X.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AH4g22S6WkOsQ-z4X.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the element has multiple classes, they are all displayed and separated by a space character. You can select one of the classes to use in the tests, which will translate to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 driver.FindElement(By.ClassName("w-full"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on the &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ClassName locator in Selenium.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Name locator in Selenium
&lt;/h3&gt;

&lt;p&gt;This is the Name attribute of the web element. The same as the ID and the ClassName, which you can find in the Elements panel of the Developer Tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A7FgPKp-kALIb76Sf.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A7FgPKp-kALIb76Sf.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.Name("SearchDualList"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on the &lt;a href="https://www.lambdatest.com/blog/how-to-use-name-locator-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Name locator in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tag Name locator in Selenium
&lt;/h3&gt;

&lt;p&gt;This is the actual HTML tag of the element. So it will be a button, input, label, select, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AywKqsktLQuI4nyyZ.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AywKqsktLQuI4nyyZ.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.TagName(“Input”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on the &lt;a href="https://www.lambdatest.com/blog/how-to-use-name-locator-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Name locator in Selenium.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Link Text locator in Selenium
&lt;/h3&gt;

&lt;p&gt;This applies to link elements (the “a” tag in HTML) and refers to the visible link text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;It’s crucial to debug websites for Safari before pushing them live. In this article, we look at how to debug websites using&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/debug-websites-using-safari-developer-tools/#none?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;dev tools in Safari&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Developer .&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A2XkOOm0xK5VNDeDn.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A2XkOOm0xK5VNDeDn.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So to use this in your test, you will need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.LinkText("Simple Form Demo"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on the &lt;a href="https://www.lambdatest.com/blog/using-link-text-and-partial-link-text-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Link Text locator in Selenium.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Partial Link Text locator in Selenium
&lt;/h3&gt;

&lt;p&gt;The same as above, but using only a part of the text link. For the example above, I can have something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.PartialLinkText("Form Demo"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about it, you can refer to our earlier blog on the &lt;a href="https://www.lambdatest.com/blog/using-link-text-and-partial-link-text-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Partial Link Text locator in Selenium.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Selector in Selenium
&lt;/h3&gt;

&lt;p&gt;I left CSS Selectors and XPath last because, although they are widely used, they are not as straightforward as the other locators. The &lt;a href="https://www.lambdatest.com/blog/css-selectors-cheat-sheet/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selector in Selenium&lt;/a&gt; is a combination of an element’s CSS Selectors and the selector’s value, used to identify the element on the web page. The basic syntax for CSS Selectors is &lt;em&gt;node[attribute = ‘attribute_value’]&lt;/em&gt;. For our example above, we would have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.CssSelector("input[id=’user_message’]"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The big advantage of using CSS Selectors is that they allow us to combine multiple attributes to identify a single element, which is very useful when our elements don’t have an ID, a Name, or a ClassName, or when these attributes are not unique. It also allows us to identify elements relative to their position on the page (for example, the child input element of a span element).&lt;/p&gt;

&lt;h3&gt;
  
  
  XPath in Selenium
&lt;/h3&gt;

&lt;p&gt;Another very common locator strategy is &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt;. XPath is a language used for querying XML documents. It works on both HTML and XML documents, allowing us to navigate through the XML structure of any document. It contains a path expression and some conditions. The basic XPath syntax is &lt;em&gt;//tag[@attribute=’value’]&lt;/em&gt;. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.XPath("//input[@id=’user-message’]"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s important to note that when deciding on a locator strategy, some are faster, and some are slower. The ID locator strategy is the fastest and usually more recommended, while XPath tends to be slower.&lt;/p&gt;

&lt;h2&gt;
  
  
  Relative Locators in Selenium
&lt;/h2&gt;

&lt;p&gt;Relative locators have been introduced with &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium 4&lt;/a&gt;, and they can be used to locate elements on the web page in relation to another element on that page. To learn more about it, you can go through our earlier log on &lt;a href="https://www.lambdatest.com/blog/selenium-4-relative-locator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Relative Locators in Selenium 4.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FwFDA0822T0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This article explains the&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/emulator-vs-simulator-vs-real-device/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;emulator vs simulator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;vs real device differences, the learning of which can help you select the right mobile testing solution for your business.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The available relative locators are:&lt;/p&gt;

&lt;h3&gt;
  
  
  Above
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Above&lt;/em&gt; identifies an element that is located above a different element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("showInput"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Below
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Below&lt;/em&gt; identifies an element that is located below a different element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RelativeBy.WithLocator(By.TagName("input")).Below(By.TagName("li"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  LeftOf
&lt;/h3&gt;

&lt;p&gt;You probably already figured out how this goes. Yes, the element is located based on an element that can be found to its left.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RelativeBy.WithLocator(By.TagName("input")).LeftOf(By.TagName("p"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  RightOf
&lt;/h3&gt;

&lt;p&gt;Similar to the previous locator, it will retrieve the element based on an element to its right.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RelativeBy.WithLocator(By.TagName("input")).RightOf(By.TagName("p"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Near
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Near&lt;/em&gt; will locate an element relative to an element that is within 50px.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RelativeBy.WithLocator(By.TagName("input")).Near(By.TagName("p"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to find a single web element using driver.FindElement in Selenium C#?
&lt;/h2&gt;

&lt;p&gt;Finding unique elements to interact with is the first common situation when writing automated tests with Selenium. For these cases, you will want to use the command &lt;em&gt;driver.FindElement&lt;/em&gt; in Selenium C#. This will look something along these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.Id("user-message"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return a web element. Then, you can perform any actions available for web elements in Selenium C#, such as SendKeys() to enter text, Click() to click on it, Clear() to clear its text, and so on.&lt;/p&gt;

&lt;p&gt;To learn more about SendKeys, you can go through our earlier blog on &lt;a href="https://www.lambdatest.com/blog/how-to-use-selenium-sendkeys/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SendKeys in Selenium.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at an example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I will exemplify this with a simple login test case. Here are the test steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the webpage &lt;a href="https://ecommerce-playground.lambdatest.io/index.php?route=account/login" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/index.php?route=account/login&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter valid credentials (EMail and Password).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Press the Login button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the user account page is loaded.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For all the web elements interaction stated, we are looking to identify a single element to perform actions on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Insert text into the E-Mail Address input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert text into the Password input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Login button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find the MyAccount header on the page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt; on using driver.FindElement and driver.FindElements in Selenium C#, I’ll be running my tests on the LambdaTest cloud grid using different OS and browser configurations.&lt;/p&gt;

&lt;p&gt;Cloud testing platforms like LambdaTest allow you to perform manual and automated &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and browser versions at scale. It provides support for different &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=v&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing frameworks&lt;/a&gt; like Selenium, &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Cypress&lt;/a&gt;, &lt;a href="http://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, and more. Furthermore, using parallel &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;, you can also trim down lead time by multiple folds.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jrgx_3gfWVA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; to see our latest tutorials about &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/appium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium automation&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/playwright-framework?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright automation,&lt;/a&gt; and more.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a great solution for testing of&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage?" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Safari browser on windows&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;Forget about emulators or simulators — use real online browsers. Try LambdaTest for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Setup
&lt;/h2&gt;

&lt;p&gt;The first step of the implementation is setting up the project in Visual Studio. I’ll be using &lt;a href="https://www.lambdatest.com/learning-hub/nunit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;NUnit&lt;/a&gt; as my test framework, but if you have other preferences, like xUnit or MSTest, they will do the trick just as well. You can see a detailed comparison between &lt;a href="https://www.lambdatest.com/blog/nunit-vs-xunit-vs-mstest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;NUnit vs. XUnit vs. MSTest&lt;/a&gt; to choose the right framework for your testing needs.&lt;/p&gt;

&lt;p&gt;For this, select the project type you need in Visual Studio:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AKcgHlYxmNi3DKykG.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AKcgHlYxmNi3DKykG.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2306%2F0%2AWDbjyJD8Yudelrsv.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2306%2F0%2AWDbjyJD8Yudelrsv.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter a name for the project, select the location, and you should end up with a default created test class that looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework; namespace SeleniumLocators { public class Tests { [SetUp] public void Setup() { } [Test] public void Test1() { Assert.Pass(); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 using NUnit.Framework; namespace SeleniumLocators { public class Tests { [SetUp] public void Setup() { } [Test] public void Test1() { Assert.Pass(); } } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to add the NuGet packages for Selenium. You can do this by right-clicking on the project name in the solution explorer and selecting Manage NuGet packages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ABWIjTQLxKa8JuGur.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ABWIjTQLxKa8JuGur.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open up the package manager. In the browse tab, look for each of the following packages and click install for each of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Selenium.WebDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://Selenium.Support" rel="noopener noreferrer"&gt;Selenium.Support&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DotNetSeleniumExtras.WaitHelpers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once installed, they will be visible in the Installed tab, along with the installed version:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Am87iRrJ9i7KdeEMO.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Am87iRrJ9i7KdeEMO.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am not testing locally. I want to do my tests on the latest version of Safari (currently 16.0). Since I’m a Windows user, the LambdaTest Grid is helpful because it allows me to test a configuration I cannot set up on my machine. I am using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Automation Capabilities Generator&lt;/a&gt; to generate the desired configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ALZ_ccD2JRARisL7a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ALZ_ccD2JRARisL7a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Now that everything’s set up, here’s the implementation for our test scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Remote; using OpenQA.Selenium.Safari; using OpenQA.Selenium.Support.UI; using SeleniumExtras.WaitHelpers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace SeleniumLocators { public class Tests { private static IWebDriver driver; private static readonly string gridURL = "@hub.lambdatest.com/wd/hub"; private static readonly string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME"); private static readonly string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY"); private readonly string loginURL = "https://ecommerce-playground.lambdatest.io/index.php?route=account/login"; private readonly string homePageURL = "https://ecommerce-playground.lambdatest.io/index.php";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[SetUp] public void Setup() { DriverOptions capabilities = new SafariOptions(); capabilities.BrowserVersion = "16.0"; Dictionary&amp;lt;string, object&amp;gt; ltOptions = new Dictionary&amp;lt;string, object&amp;gt;(); ltOptions.Add("username", LT_USERNAME); ltOptions.Add("accessKey", LT_ACCESS_KEY); ltOptions.Add("platformName", "MacOS Ventura"); ltOptions.Add("build", "[DEMO] E-commerce"); ltOptions.Add("w3c", true); ltOptions.Add("project", "LambdaTest Playground"); ltOptions.Add("plugin", "c#-c#"); capabilities.AddAdditionalOption("LT:Options", ltOptions); driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), capabilities); }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test] public void ValidateSignIn() { driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/index.php?route=account/login"); driver.FindElement(By.Name("email")).SendKeys("andreea@getnada.com"); driver.FindElement(By.Id("input-password")).SendKeys("test"); driver.FindElement(By.CssSelector("input[value='Login']")).Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); wait.Until(ExpectedConditions.ElementExists(By.XPath("//h2[text()='My Account']"))); } } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;Let’s walk through the code now and see what’s going on.&lt;/p&gt;

&lt;p&gt;The first lines of code, the &lt;strong&gt;using&lt;/strong&gt; ones, are there to instruct our test class on what packages to use:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7XsXa4komauVNa4C.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7XsXa4komauVNa4C.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we have the class, which contains our actual test. In the first part, I declared the variables I’ll need in my tests:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Amd1i9CyY6bmjS_g6.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2Amd1i9CyY6bmjS_g6.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I need an IWebDriver instance to interact with the browser. And the gridURL, LT_USERNAME, and LT_ACCESS_KEY are string variables that I will be using in the setup to connect to my LambdaTest Grid account. I also stored the login page URL as a variable to make it easier to read. It’s also a good idea to store credentials (such as the LT_USERNAME and LT_ACCESS_KEY) as environment variables in your operating system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A507OPXWgP4pLL1yp.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A507OPXWgP4pLL1yp.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;[SetUp]&lt;/em&gt; is an &lt;em&gt;NUnit&lt;/em&gt; attribute, marking a method that will run before each test method. Consider this method as the precondition of the tests. Here I set up my driver and my LambdaTest configuration.&lt;/p&gt;

&lt;p&gt;Then all this goes into the &lt;em&gt;SetUp&lt;/em&gt; method and a new instance of the driver, which is linked to my account URL.&lt;/p&gt;

&lt;p&gt;Next comes the actual test, where you can see the &lt;em&gt;FindElement&lt;/em&gt; in action. Again, we have an NUnit attribute, which is [Test]. This marks a test method. If you open the Test Explorer of Visual Studio (from the Test menu → Test Explorer), you will see all the methods with this attribute. I currently have just one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AQcPfnzOaksvA64cQ.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AQcPfnzOaksvA64cQ.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AxtvFNyIMLYwZW-jS.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AxtvFNyIMLYwZW-jS.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first line is the navigate command, which instructs the browser to go to the desired URL. In our case, the Login page.&lt;/p&gt;

&lt;p&gt;Next, we have various interactions with web elements on the page. I tried to use as many of the available locators, so as you can see, I’ve used: &lt;em&gt;driver.FindElement(&lt;/em&gt;&lt;a href="http://By.Name" rel="noopener noreferrer"&gt;&lt;em&gt;By.Name&lt;/em&gt;&lt;/a&gt;&lt;em&gt;(“email”))&lt;/em&gt; to locate the Email input field:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A9NRbsPWssYM4UH24.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A9NRbsPWssYM4UH24.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;driver.FindElement(&lt;/em&gt;&lt;a href="http://By.Id" rel="noopener noreferrer"&gt;&lt;em&gt;By.Id&lt;/em&gt;&lt;/a&gt;&lt;em&gt;(“input-password”))&lt;/em&gt; to locate the Password field:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A43fkQPonoVrktatT.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A43fkQPonoVrktatT.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And driver.FindElement(By.CssSelector(“input[value=’Login’]”))using a CSS Selector build on the value attribute, to locate the Login button:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AMvHAWGVMGDXtRbgq.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AMvHAWGVMGDXtRbgq.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, once the elements are correctly located, simply use Selenium’s methods to interact with them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;SendKeys() to enter text in the input fields (for email and password)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click() to press the login button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can learn more about the Action Class through this blog on &lt;a href="https://www.lambdatest.com/blog/what-is-actions-class-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Action Class in Selenium&lt;/a&gt;. The following lines instruct the browser to wait for 5 seconds or until the element with the given XPath exists, using an explicit wait. The test will fail if the element is not found within 5 seconds.&lt;/p&gt;

&lt;p&gt;Now my test is displayed in Visual Studio’s Test Explorer, and I can run it from here by right-clicking on it and selecting Run or by pressing the Run button at the top:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2136%2F0%2AlXPHRXBCj8h8UH5W.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2136%2F0%2AlXPHRXBCj8h8UH5W.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the test finishes running, I can see the result in the same panel (green means passed)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2124%2F0%2A6cLC4s_81s3iVIPl.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2124%2F0%2A6cLC4s_81s3iVIPl.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As well as in my Dashboard in LambdaTest &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; in the Automation tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ACieRo9J6wjDRNEeN.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ACieRo9J6wjDRNEeN.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, I can go deeper into details and see a recording of my test, as well as each detailed step:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AB_rimlWG2YFx9F57.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AB_rimlWG2YFx9F57.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/test-analytics?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Analytics&lt;/a&gt; is a comprehensive solution that helps you manage and optimize your QA processes and test data through access to powerful analytics capabilities.&lt;/p&gt;

&lt;p&gt;With LambdaTest Analytics, you can easily access, analyze, and streamline your QA efforts, ensuring that your product is successful by incorporating key analytics insights. Whether you are looking to improve your testing efficiency or simply want to better understand the performance of your product, LambdaTest Analytics is what you need.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F0%2Af1D8MvdpdKPCwY3J.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F0%2Af1D8MvdpdKPCwY3J.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform manual or automated cross&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb20ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;browser testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;on 3000+ browsers online. Deploy and scale faster with the most powerful cross browser testing tool online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find multiple web elements using driver.FindElements in Selenium C#?
&lt;/h2&gt;

&lt;p&gt;The second case I’ll present is when you are not looking for a single element but trying to find all the elements that meet certain criteria. The Selenium C# method used for this is FindElements(), and it works pretty much the same way as FindElement(), except that this method returns a collection of web elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElements(By.XPath("//a[text()='HTC Touch HD']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s better to illustrate this with an example as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the ecommerce-playground.lambdatest.io/index.php?route=common/home page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for “HTC” products.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the required number of products returned (in this case, 8).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AI3IT6Z9yAfHUK5sk.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AI3IT6Z9yAfHUK5sk.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test] public void ValidateNumberOfProducts() { int expectedNumber = 8; driver.Navigate().GoToUrl("https://ecommerce-playground.lambdatest.io/index.php?route=common/home"); driver.FindElement(By.Name("search")).SendKeys("htc"); driver.FindElement(By.XPath("//button[text()='Search']")).Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); wait.Until(ExpectedConditions.ElementExists(By.XPath("//h1[text()='Search - htc']"))); var results = driver.FindElements(By.XPath("//a[text()='HTC Touch HD']")); Assert.That(results, Has.Count.EqualTo(expectedNumber)); }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;I also added a new string variable for the URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AXdpSnXBoo1rFNIKx.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AXdpSnXBoo1rFNIKx.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, inside the test, I created a simple integer variable that stores the expected number of results, which I will use later:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AxSDxCN4zbzE7p7yQ.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AxSDxCN4zbzE7p7yQ.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This test should be easy to understand after we already went over the first one. The second line is the same, except we navigate to a different page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A742w7Rub8LzgBPwI.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A742w7Rub8LzgBPwI.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, using the Selenium driver.FindElement() method, I have two interactions with elements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2624%2F0%2A9GHB3XBFXqz6OITa.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2624%2F0%2A9GHB3XBFXqz6OITa.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I used a wait again to ensure that I validated after loading the correct page. I’m using the H1 web element with the text “Search — htc” to be displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AaiYJD1dUciH0bj8w.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AaiYJD1dUciH0bj8w.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ATf4Skni1FWxFJ3u8.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2ATf4Skni1FWxFJ3u8.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then we have the &lt;em&gt;driver.FindElements()&lt;/em&gt; in Selenium C#, where we identify all the elements that have the same locator, in this case, the same XPath:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AqKcIkLHYJqfMTQSw.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AqKcIkLHYJqfMTQSw.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The collection of elements is saved within a variable, which I used in the last line. Here I verify the number of web elements returned by the driver.FindElements() in Selenium C# is the number I expect:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2316%2F0%2AEDotHWMQlid_cTgk.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2316%2F0%2AEDotHWMQlid_cTgk.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Assert is a class provided by NUnit, which allows us to make validations. If the condition we pass as a parameter is true, then the test passes. Otherwise, it will fail.&lt;/p&gt;

&lt;p&gt;Now that the tests are written, you can see them both in the Test Explorer. To run them both, you just need to press the Run All button, right-click and select Run, or use the Ctrl+R, T shortcut, just like before:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A1tH1CvvEst_yzfr3.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A1tH1CvvEst_yzfr3.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the tests are finished running, you’ll be able to see the results in Visual Studio:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A-bs4bEkY_3YBZ92c.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A-bs4bEkY_3YBZ92c.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now, you can see the new test execution in your LambdaTest account, under the Automation tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AnCtKcEM5shgcVRXL.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AnCtKcEM5shgcVRXL.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And, if you click on one of the runs, you can see a video recording of the test, the configuration on which the test ran&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AAnTZWzH1RvNAFMnb.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AAnTZWzH1RvNAFMnb.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And a step-by-step description of the Selenium commands sent:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2138%2F0%2AIzZim9xH8cJi1NTz.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2138%2F0%2AIzZim9xH8cJi1NTz.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are a tester seeking to improve your abilities, consider obtaining the Selenium C# 101 certification from LambdaTest as a way to demonstrate your expertise. This certification can help you to stand out and highlight your skills to potential employers or clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;The &lt;em&gt;driver.FindElement()&lt;/em&gt; and &lt;em&gt;driver.FindElements()&lt;/em&gt; in &lt;em&gt;Selenium C#&lt;/em&gt; are two of the most common commands when working on web UI automation. Here are the most important things to remember:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The syntax in Selenium C# for finding elements is:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.locator_strategy); driver.FindElements(By.locator_strategy);
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;driver.FindElement()&lt;/em&gt; in Selenium C# returns the first web element found using the provided locator. If you need to select a specific element, ensure that the locator strategy will return only one element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;driver.FindElements()&lt;/em&gt; in Selenium C# returns a collection of web elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s crucial to use a good locator strategy; otherwise, you can end up with unwanted exceptions, or Selenium might try to interact with the incorrect element on the web page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>snippet</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>## How To Use WebDriverWait In Selenium C#</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Tue, 21 Feb 2023 06:21:00 +0000</pubDate>
      <link>https://forem.com/testmuai/-how-to-use-webdriverwait-in-selenium-c-3734</link>
      <guid>https://forem.com/testmuai/-how-to-use-webdriverwait-in-selenium-c-3734</guid>
      <description>&lt;p&gt;The more you work with &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt;, the more you will come across various exceptions, such as &lt;em&gt;NoSuchElementException&lt;/em&gt; (when an element is not visible on the page) or &lt;em&gt;StaleElementReferenceException&lt;/em&gt;. Or there will be times when you will try to interact with an element that is not yet in the state you expect it to be (e.g., clickable).&lt;/p&gt;

&lt;p&gt;To do this, you can instruct &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; to wait for certain conditions to be met &lt;strong&gt;explicitly&lt;/strong&gt;. &lt;a href="https://www.lambdatest.com/blog/explicit-fluent-wait-in-selenium-c/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Explicit waits in Selenium&lt;/a&gt; are a way to deal with the dynamic nature of web pages, where elements may take longer to load or become available for interaction. By using explicit waits, you can tell &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; to wait for a specific condition to be met before executing the next step in your automation script. This allows for a more flexible and robust automation solution.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;, I will show you how you can use the WebDriverWait in Selenium C# to increase the reliability of your test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/jest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Jest automation&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tests in massive parallel across multiple browser and OS combinations with LambdaTest, Read more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Selenium Waits?
&lt;/h3&gt;

&lt;p&gt;Before we dig deeper, let’s understand the &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;waits in Selenium&lt;/a&gt; and why we use them. Selenium WebDriver doesn’t keep track of the DOM’s live, active state. Its default page load method waits for the document.readyState to become “complete”. This can happen before all the elements on the page are loaded and can cause the tests to throw NoSuchElementException. You can refer to this blog on the &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;most common Selenium exceptions&lt;/a&gt; to learn more about it.&lt;/p&gt;

&lt;p&gt;Consider a test where you try to click on a button that has not yet loaded or is not yet enabled (though visible) on the page. If Selenium WebDriver attempts to click on a button that is not available in the DOM, it will throw a &lt;em&gt;NoSuchElementException&lt;/em&gt;. You might also witness the &lt;a href="https://www.lambdatest.com/blog/how-to-deal-with-element-is-not-clickable-at-point-exception-using-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;em&gt;Element Is Not Clickable at Point&lt;/em&gt;&lt;/a&gt; exception if the element is visible in the DOM but not clickable at a particular point.&lt;/p&gt;

&lt;p&gt;This will cause all further steps to fail, although the application works as expected when clicking the button at the correct time. To prevent this, we use waits. With waits, we can tell our tests to wait a certain amount or for specific conditions before moving on to the next steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Waits in Selenium C
&lt;/h3&gt;

&lt;p&gt;There are several ways to wait for a web element to appear on a web page. I will go through each one and then expand more on the explicit waits, which are the focus of this blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  Thread.Sleep()
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;System.Threading.Thread.Sleep(milliseconds)&lt;/em&gt; is not a Selenium WebDriver method but a built-in one in .Net. What it does is it suspends the current thread for the number of milliseconds passed as a parameter.&lt;/p&gt;

&lt;p&gt;However, this is not recommended when working with &lt;a href="https://www.lambdatest.com/automated-web-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated web UI testing&lt;/a&gt;, because it is very rigid — the specified time has to pass before moving to the next step, regardless of whether the element you are waiting for was loaded faster.&lt;/p&gt;

&lt;p&gt;For example, if your web element takes 3 seconds to load, and the Sleep parameter is set to 5 seconds, the test will wait 5 seconds before moving to the next step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread.Sleep(5000);
driver.FindElement(By.Id("slowButton")).Click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your website or web app online for iOS browser compatibility, including on the latest iPhone Simulator, by using an&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/test-on-iphone-simulator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;iPhone tester&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;. Perform seamless cross-browser testing on this device to ensure a flawless user experience. You can even try it for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It might not sound like a big deal, but if you have hundreds of tests and many of them use &lt;em&gt;Thread.Sleep()&lt;/em&gt;, which can add a lot of unnecessary wait time to the &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;. If the test takes around 5 seconds, adding up the Sleep time of another 5 seconds, that means doubling the time it takes to run the test!&lt;/p&gt;

&lt;p&gt;Also, if the time it takes for the button to load exceeds those 5 seconds, you will still get a &lt;em&gt;NoSuchElementException&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implicit Wait
&lt;/h3&gt;

&lt;p&gt;Then, we have the Selenium &lt;a href="https://www.lambdatest.com/blog/implicit-wait-csharp-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;implicit wait&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/implicit-wait-csharp-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;implicit wait in Selenium&lt;/a&gt; is dynamic — it waits until an element is visible on the page or until the given timespan has elapsed. If the element has not been found before the given time duration, an &lt;em&gt;ElementNotVisibleException&lt;/em&gt; or &lt;em&gt;NoSuchElementException&lt;/em&gt; will be thrown.&lt;/p&gt;

&lt;p&gt;The Selenium implicit wait applies to all the web elements in the test script and is a much-preferred method to &lt;em&gt;Thread.Sleep()&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explicit Wait
&lt;/h3&gt;

&lt;p&gt;However, if you want even more flexibility, you should go for the explicit wait. The WebDriverWait in Selenium C# is part of the &lt;a href="http://OpenQA.Selenium.Support" rel="noopener noreferrer"&gt;&lt;em&gt;OpenQA.Selenium.Support&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.UI&lt;/em&gt; package.&lt;/p&gt;

&lt;p&gt;WebDriverWait in Selenium C# allows Selenium not only to wait for an element to be visible on the web page but also until specific conditions are met.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.PollingInterval = TimeSpan.FromMilliseconds(200);          wait.Until(ExpectedConditions.ElementIsVisible(By.Id("my-element']"))).Click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;A complete&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;WebDriver&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tutorial that covers what WebDriver is, its features, architecture and best practices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is how WebDriverWait in Selenium C# works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The condition is checked. If the condition is true, the next lines of code are executed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the condition is false, a thread sleep is called at a polling interval. The default value of this polling interval is 250 ms, but a different value can be specified:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wait.PollingInterval = TimeSpan.FromMilliseconds(200);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;After this interval elapses, the condition is rechecked.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This step repeats until the given wait time expires or the condition is met.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Expected Conditions with Explicit Wait
&lt;/h3&gt;

&lt;p&gt;Here are some examples of &lt;a href="https://www.lambdatest.com/blog/expected-conditions-in-selenium-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Expected Conditions in Selenium&lt;/a&gt; I have used the most in my tests (your tests might have different needs, but these are just to illustrate how explicit waits can be useful):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ElementExists&lt;/strong&gt;: waits for the element to exist in the DOM of the page, even if it’s not visible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ElementIsVisible&lt;/strong&gt;: waits for the element to be visible on the page. There are cases when the element can exist in the DOM but is not yet displayed on the page, so we cannot interact with it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ElementToBeClickable&lt;/strong&gt;: wait for an element to become clickable — can be useful when a button is quickly loaded on the page but cannot be clicked right away because it is disabled or cannot be clicked until a different action is performed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AlertIsPresent&lt;/strong&gt;: waits for the presence of an alert — alerts are usually triggered by another action, and it can take some time to display them. If you interact with an element on the alert (like dismiss/confirm the alert or try to confirm its text) too soon, you can get a NoAlertPresentException.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;InvisibilityOfElementLocated&lt;/strong&gt;: waits for an element to not be visible on the page. For instance, you want to check that after inserting invalid data in an input field, the warning message is no longer displayed when the correct data is entered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TextToBePresentInElement&lt;/strong&gt;: waits for a given text to be displayed inside a certain web element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ElementToBeSelected&lt;/strong&gt;: waits for an element to be selected — can be used for checkboxes that are automatically selected through other actions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Demonstration: How to use WebDriverWait in Selenium C
&lt;/h3&gt;

&lt;p&gt;In this section, we will go over an example of using WebDriverWait in Selenium C# to handle the dynamic nature of web pages. The WebDriverWait class is a useful tool for waiting for specific conditions to be met before executing the next step in your automation script. This helps to make your scripts more flexible and robust, allowing for a better automation solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Scenario
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;a href="https://www.lambdatest.com/selenium-playground/jquery-download-progress-bar-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;JQuery Download Progress Bar&lt;/a&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Start Download button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Close button when it’s available:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;If this is your first test, you will need to create a new project. In this WebDriverWait in Selenium C# tutorial, I’ll be using the &lt;a href="https://www.lambdatest.com/blog/mstest-tutorial-running-first-selenium-automation-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;MSTest framework&lt;/a&gt;, which is Microsoft’s tool for running tests in .NET applications. If you prefer to work with NUnit, you can check out the &lt;a href="https://www.lambdatest.com/learning-hub/nunit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium NUnit tutorial.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To learn more about MSTest, NUnit, and other popular &lt;a href="https://www.lambdatest.com/blog/11-best-unit-testing-frameworks-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unit testing frameworks&lt;/a&gt; like xUnit, you can go through this blog on &lt;a href="https://www.lambdatest.com/blog/nunit-vs-xunit-vs-mstest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit vs xUnit vs MSTest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, we will be executing the test on the LambdaTest cloud grid. Cloud testing platforms like LambdaTest allow you to perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser&lt;/a&gt; testing at scale over an &lt;a href="https://www.lambdatest.com/online-device-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; of 3000+ browsers and browser versions.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;By using an&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/ios-simulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;iPhone emulator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;, such as the iOS simulator by LambdaTest, you can effortlessly test your websites and web applications across a range of devices, operating system versions, and browsers, from the latest models to older ones. Additionally, you can test your iOS app online across 200+ device and iOS environments. Register for free and start testing today.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Subscribe to &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with detailed tutorials around Selenium testing, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To create a new test project in Visual Studio, select the MSTest Test Project type:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the following NuGet packages from the Package Manager:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.WebDriver&lt;/strong&gt;: For this WebDriverWait in Selenium C# tutorial, I am using version 3.141.0, which is still one of the most used versions in existing &lt;a href="https://www.lambdatest.com/blog/top-selenium-open-source-projects-on-github/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium projects.&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://Selenium.Support" rel="noopener noreferrer"&gt;&lt;strong&gt;Selenium.Support&lt;/strong&gt;&lt;/a&gt;: It should be the same version as the Selenium.WebDriver package; this is the package that contains the Selenium WebDriverWait.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Install the NuGet packages from the UI, from the &lt;em&gt;Tools menu → NuGet Package Manager → Manage NuGet Packages for Solution…&lt;/em&gt; and search for them in the list:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AsPFX4kkFDw8ju0nh.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AsPFX4kkFDw8ju0nh.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or you can run the install command from the &lt;em&gt;Package Manager Console (Tools menu → NuGet Package Manager → Package Manager Console):&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PM&amp;gt; NuGet\Install-Package Selenium.WebDriver -Version 3.141.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Aqnu2cwFgUeKb7dfI.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2Aqnu2cwFgUeKb7dfI.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I used the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt; to create the configuration where I want to run my tests. You can create your custom setup, depending on the configuration you want to use in your tests. I’m keeping it simple, testing on Windows 11 with Chrome version 101 and a resolution of 1280×800.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Before running the tests, please set the environment variables LT_USERNAME &amp;amp; LT_ACCESS_KEY from the terminal. The account details are available on your &lt;a href="https://accounts.lambdatest.com/detail/profile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Profile&lt;/a&gt; page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;For macOS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LT_USERNAME=LT_USERNAME
export LT_ACCESS_KEY=LT_ACCESS_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Linux:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LT_USERNAME=LT_USERNAME
export LT_ACCESS_KEY=LT_ACCESS_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set LT_USERNAME=LT_USERNAME
set LT_ACCESS_KEY=LT_ACCESS_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a new class containing the following code:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using OpenQA.Selenium.Support.UI;


namespace SeleniumExplicitWaits
{
    [TestClass]
    public class SeleniumWebDriverWaits
    {
        private static IWebDriver driver;
        public static string gridURL = "@hub.lambdatest.com/wd/hub";
        public static string LT_USERNAME = Environment.GetEnvironmentVariable("LT_USERNAME");
        public static string LT_ACCESS_KEY = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");


        [TestInitialize]
        public void SetUp()
        {
            var desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browserName", "Chrome");
            desiredCapabilities.SetCapability("platform", "Windows 11");
            desiredCapabilities.SetCapability("version", "101.0");
            desiredCapabilities.SetCapability("screenResolution", "1280x800");
            desiredCapabilities.SetCapability("user", LT_USERNAME);
            desiredCapabilities.SetCapability("accessKey", LT_ACCESS_KEY);
            desiredCapabilities.SetCapability("build", "Selenium C-Sharp");
            desiredCapabilities.SetCapability("name", "Selenium Test");
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), desiredCapabilities, TimeSpan.FromSeconds(600));


        }


        [TestMethod]
        public void DownloadFile()
        {
            driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/jquery-download-progress-bar-demo");
            driver.FindElement(By.Id("downloadButton")).Click();
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
            wait.PollingInterval = TimeSpan.FromMilliseconds(200);
            wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[contains(text(),'Close') and @class='ui-button ui-corner-all ui-widget']"))).Click();


        }

        [TestCleanup]
        public void Cleanup()
        {
            driver.Quit();
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;automation testing platform&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Walkthrough
&lt;/h3&gt;

&lt;p&gt;The using statements in any C# class contain the packages that will be used:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AMLvQ-cck7-qDeugt.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AMLvQ-cck7-qDeugt.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;[TestClass]&lt;/em&gt; attribute from MSTest marks the class as a test class:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AVCeqP-mv6U5o6Zef.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AVCeqP-mv6U5o6Zef.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next part, I’m declaring all the variables that will be used in the methods:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6jrpcXLHXGrc6nxU.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A6jrpcXLHXGrc6nxU.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The driver is a new instance of the IWebDriver interface. Through it, we control the browser.&lt;/p&gt;

&lt;p&gt;The next lines of code are related to my LambdaTest Account because I want my tests to run on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;. This way, I can specify configurations where my tests will run, which can be different from my local configuration.&lt;/p&gt;

&lt;p&gt;This brings us to the next part:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2APiQussIOCwJNdrn4.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2APiQussIOCwJNdrn4.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method is triggered before each test case. It will create a new browser instance with specific capabilities.&lt;/p&gt;

&lt;p&gt;The next method is the actual test:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWlu9s_U6KAvMs_k5.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWlu9s_U6KAvMs_k5.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The [TestMethod] attribute informs that the method is a test method. The Navigate().GoToUrl() is the Selenium C# method to go to a specific URL.&lt;/p&gt;

&lt;p&gt;Then, the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;FindElement() in Selenium&lt;/a&gt; is the method that allows us to identify web elements on the web page based on locators, such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XPath&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSSSelector&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Link text or partial link text&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the first element I’m interacting with, I’m using the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator in Selenium&lt;/a&gt;. It’s usually recommended because it should be unique. To retrieve this information from the browser, right-click the element and select Inspect. This will open up (if it’s not already open) the Developer Tools, where you can see the details of the element:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATkPZZOEcZPpgWZ0a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATkPZZOEcZPpgWZ0a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I’m using the actual explicit wait:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOAE15w2XU7d-m30f.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOAE15w2XU7d-m30f.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a new variable of type WebDriverWait, giving it a time span of 20 seconds — this is the maximum amount of type I am instructing Selenium to wait for my condition to be met.&lt;/p&gt;

&lt;p&gt;Next, I am using a polling interval of 200 milliseconds — this is completely optional, but I wanted to show you how it can be used. Selenium will retry to find the web element every 200 milliseconds.&lt;/p&gt;

&lt;p&gt;Finally, I specified the condition I wanted to wait for, which was for the button to become clickable. The button doesn’t have an Id, so I am using an XPath with a combination of 2 attributes: text and class name. I can see this in Developer Tools as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button type="button" class="ui-button ui-corner-all ui-widget"&amp;gt;Close&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last method is the cleanup, marked by the attribute [&lt;em&gt;TestCleanup&lt;/em&gt;], which will run after every test. It simply closes the browser using the Selenium Quit() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [TestCleanup]
        public void Cleanup()
        {
            driver.Quit();
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The test will be visible in Visual Studio’s test explorer, and you can run it from there. If you choose to run it locally, you will see the browser open up and perform all the steps. If you are using cloud Selenium Grid, like me, you will see the test result when it finishes running:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AH2wMnuRpS3M2ccyK.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AH2wMnuRpS3M2ccyK.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you will see the results online:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUKoUffnn46eV7F8I.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AUKoUffnn46eV7F8I.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also see all the retries performed before the element was found:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AdYqv3c4Ib_1E8wTg.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AdYqv3c4Ib_1E8wTg.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;testing automation cloud&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;However, my test was successful because after waiting less than the given time, the element was found and clickable.&lt;/p&gt;

&lt;p&gt;Demonstrate your expertise and knowledge in using Selenium for &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;C# automation testing&lt;/a&gt; with this Selenium C# 101 certification. This will enhance your technical skills and establish your credibility as a tester.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Having the option to wait for web elements to be loaded or meet a certain condition can be very important in &lt;a href="https://www.lambdatest.com/automated-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=feb22_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated UI testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this blog on WebDriverWait in Selenium C#, I covered how to create explicit waits using WebDriverWait in Selenium C# to create more stable tests and why they can be preferred to implicit waits. I also showed how you can run the tests on the cloud, so you don’t have to use your local settings and configuration, and how to see the results on the LambdaTest cloud Selenium Grid.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>azurefunctions</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Getting Started with SpecFlow Actions [SpecFlow Automation Tutorial]</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Mon, 21 Nov 2022 16:10:45 +0000</pubDate>
      <link>https://forem.com/testmuai/getting-started-with-specflow-actions-specflow-automation-tutorial-40pj</link>
      <guid>https://forem.com/testmuai/getting-started-with-specflow-actions-specflow-automation-tutorial-40pj</guid>
      <description>&lt;p&gt;With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Behavior Driven Development&lt;/a&gt;, or BDD, is a great way to bring together technical and non-technical folks by focusing more on the behavior of the apps, and a good understanding of the requirements, from a behavioral perspective.&lt;/p&gt;

&lt;p&gt;BDD is centered on explicitly defining a feature’s desired behavior from the beginning. Specification by example is a method for identifying behaviors that use concrete examples rather than abstract, general language to describe the intended behavior. They act as the product’s requirements/acceptance criteria (before development) and test cases (after development).&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/blog/specflow-tutorial-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SpecFlow automation tutorial&lt;/a&gt;, I’ll demonstrate how a BDD web test can be written using SpecFlow and Selenium C# and how to run it on the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; with SpecFlow Actions. I am using Visual Studio 2022, but you can use an older version to follow along.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;It’s crucial to debug websites for Safari before pushing them live. In this article, we look at how to debug websites using &lt;a href="https://www.lambdatest.com/blog/debug-websites-using-safari-developer-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;dev tools on safari&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is BDD testing?
&lt;/h2&gt;

&lt;p&gt;BDD is built on &lt;a href="https://www.lambdatest.com/blog/tdd-vs-bdd/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TDD (Test-driven development)&lt;/a&gt;, which makes it an approach where tests are written first.&lt;/p&gt;

&lt;p&gt;Since BDD is a collaborative approach, the product owner (stockholder), developers, project managers, QAs, and user acceptance testers come together to discuss which test scenarios should be passed to consider this software/application successful. They create a set of test scenarios in this way.&lt;/p&gt;

&lt;p&gt;Since all of these test scripts are written in plain English, they also serve as documentation for the project. SpecFlow is a framework for defining these scenarios in a more structured way and tying them to tests that run against the code.&lt;/p&gt;

&lt;p&gt;These two approaches — in isolation and together — can help you write better code and provide higher-quality software faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cucumber and the Gherkin language
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/selenium-cucumber?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cucumber&lt;/a&gt; is one of the most important tools that support BDD. It provides a means to write tests everyone can understand regardless of their technical skills.&lt;/p&gt;

&lt;p&gt;Cucumber reads plain language executable specs and verifies that the program performs what it is supposed to. The specifications provide several scenarios. For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scenario: We only work on weekdays
   Given today is Sunday
   When I get up
   Then I don’t have to work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Each scenario consists of a series of actions that the Cucumber must perform. Cucumber checks whether the program matches the specification and produces a report stating if each scenario was successful or unsuccessful.&lt;/p&gt;

&lt;p&gt;The Cucumber files use the extension .feature, and the scenarios must follow syntax rules called Gherkin. The lines in &lt;a href="https://www.lambdatest.com/software-testing-questions/what-is-gherkin?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Gherkin&lt;/a&gt; should start with keywords.&lt;/p&gt;

&lt;p&gt;The most important keywords in Gherkin are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feature:&lt;/strong&gt; provides a high-level description of the feature being tested and groups related scenarios.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; a practical example of a business rule. It includes a series of steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Given:&lt;/strong&gt; a keyword that marks a step that gives an initial context of the system — the preconditions of the scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When:&lt;/strong&gt; used for steps that describe an action.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Then:&lt;/strong&gt; marks a step that describes the expected result of the scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;And / But:&lt;/strong&gt; are used when multiple Given, When, or Then steps need to be used.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction to SpecFlow Actions
&lt;/h2&gt;

&lt;p&gt;SpecFlow is a BDD automation framework for .NET that uses the Gherkin language. It is provided as a Visual Studio extension. While writing this SpecFlow automation tutorial, the latest SpecFlow version is 3.9, released in November 2021.&lt;/p&gt;

&lt;p&gt;SpecFlow uses the official Gherkin parser, with support for over 70 languages — which means that you can write your Given/When/Then scenarios in languages other than English, too. Then, using bindings, these tests are connected to the application code, enabling you to run the tests using the testing framework of your choice (such as NUnit, in our case).&lt;/p&gt;

&lt;p&gt;To use SpecFlow, you need to install the Visual Studio extension. That can be easily done from the Visual Studio → Extension menu → Manage extensions, and search for SpecFlow.&lt;br&gt;
Then, to create a new SpecFlow project, from the New Project wizard, select the SpecFlow Project type:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Av7XjAs60-Vm6nBQIfRfPow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Av7XjAs60-Vm6nBQIfRfPow.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a target framework and your preferred &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation framework&lt;/a&gt; and complete the wizard. In this SpecFlow automation tutorial, we’ll be using NUnit from here on, and I’ll explain along the way the NUnit methods.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Nzhp5jBO8DA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; to see our latest tutorials about &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/appium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Appium automation&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright automation&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;By default, the project will have a Features folder containing a file with the .feature extension and a StepDefinitions folder, which includes the implementations of the features:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKgXNqBAgs7tHr0r5YJiM0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKgXNqBAgs7tHr0r5YJiM0g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are SpecFlow Actions?
&lt;/h2&gt;

&lt;p&gt;SpecFlow Actions is a solution provided by SpecFlow that enables us to integrate our SpecFlow tests with &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;. It manages the browser’s lifetime and offers simple configuration options and Selenium helper methods.&lt;/p&gt;

&lt;p&gt;The aim is to address typical issues testers run into when automating websites, applications, or APIs, such as working with multiple browsers or always being up-to-date with the latest browser version.&lt;/p&gt;

&lt;p&gt;In the upcoming sections of this SpecFlow automation tutorial, I will walk you through the steps you need to integrate SpecFlow Actions with &lt;a href="https://www.lambdatest.com/learning-hub/continuous-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;continuous testing&lt;/a&gt; clouds like LambdaTest to run tests in parallel on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ real browsers, devices, and OS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demonstration: SpecFlow Actions on Cloud Grid
&lt;/h2&gt;

&lt;p&gt;Before starting with SpecFlow automation, follow the steps above to install the SpecFlow extension and create a new SpecFlow project.&lt;/p&gt;

&lt;p&gt;Next, you’ll need to install the following NuGet packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.WebDriver:&lt;/strong&gt; At the time of writing this SpecFlow automation tutorial, SpecFlow.Actions for LambdaTest worked with version 3.141.0 of Selenium.WebDriver, so this is the version I have installed, too.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SpecFlow.Actions.LambdaTest:&lt;/strong&gt; I’ll use the latest version (0.1.332) for this SpecFlow automation tutorial.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more ways to install a NuGet package. You can do it from the NuGet Package Manager of the project:&lt;/p&gt;

&lt;p&gt;1- Right-click on the project name and select Manage NuGet Package), and here, in the Browse tab, search for the desired package:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F1%2ASpLVIoIURv4iThhAZEcihw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F1%2ASpLVIoIURv4iThhAZEcihw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or you can use the NuGet Package Manager Console (Tools → NuGet Package Manager → Package Manager Console, and run the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add &amp;lt;PROJECT&amp;gt; package [options] &amp;lt;PACKAGE_NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package Selenium.WebDriver --version 3.141.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now the project should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVNZ_TT0J3mQrqIJOJTJ-CA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVNZ_TT0J3mQrqIJOJTJ-CA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- To run the tests on the cloud, create in the project folder a new .json file called specflow.actions, and add the Selenium settings you want to use:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "selenium": {
    "defaultTimeout": 60,
    "pollingInterval": 5,
    "lambdatest": {
      "url": "@hub.lambdatest.com/wd/hub"&amp;gt;https://${LT_USERNAME}:${LT_ACCESS_KEY}@hub.lambdatest.com/wd/hub"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;3- You can get your LambdaTest username and access key from the &lt;a href="https://automation.lambdatest.com/build?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation tab&lt;/a&gt; by clicking on Access Key:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AxQrljTyXzJkwuQquamuTbA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AxQrljTyXzJkwuQquamuTbA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Then, add one .json file for each environment where you want to run your tests. For example, I’ll test Firefox on Windows 10 and Chrome on Windows 11.&lt;/p&gt;

&lt;p&gt;I can use a specific browser version by providing the exact version number, instructing SpecFlow Actions to use the latest version, or telling it to go back to a certain number of versions.&lt;/p&gt;

&lt;p&gt;Let me illustrate that. Here is the &lt;em&gt;specflow.actions.windows10.firefox.json&lt;/em&gt; file, where I am using the latest version of Firefox:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "selenium": {
    "browser": "Firefox",
    "capabilities": {
      "platform": "Windows 10",
      "version": "latest",
      "build": "[Demo - 2] SpecFlow Actions on LambdaTest",
      "project": "SpecFlow Actions Demo",
      "selenium_version": "3.141.59"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And the &lt;em&gt;specflow.actions.windows11.chrome.json&lt;/em&gt; file, where I am using the 4th latest version of Chrome:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "selenium": {
    "browser": "Chrome",
    "capabilities": {
      "platform": "Windows 11",
      "version": "latest-4",
      "build": "[Demo - 1] SpecFlow Actions on LambdaTest",
      "project": "SpecFlow Actions Demo",
      "selenium_version": "3.141.59"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Most of the browser capabilities are optional, but they are helpful when you need specific configurations or want to personalize the results, for example with the build and project names.&lt;/p&gt;

&lt;p&gt;You can use the same capabilities you would obtain using the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation Capabilities Generator&lt;/a&gt;, but in JSON format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AIHmeSm2Bn8-mXTxWtvHfAA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AIHmeSm2Bn8-mXTxWtvHfAA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Every modern web browser has a robust set of developer tools for testing element alignment and functionality. This article will show how to inspect elements on iPhone and iPad(&lt;a href="https://www.lambdatest.com/blog/how-to-inspect-elements-on-iphone/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to inspect on mac&lt;/a&gt;).&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Scenario
&lt;/h2&gt;

&lt;p&gt;I’ll use a fairly simple scenario to demonstrate how to write a BDD test scenario using SpecFlow.Actions with Selenium in C#. The test will be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the page &lt;a href="https://ecommerce-playground.lambdatest.io/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.io/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select a category and perform a search.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the correct number of results is returned.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2712%2F1%2AkQFxNvy4WzO00Q5H6lGT9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2712%2F1%2AkQFxNvy4WzO00Q5H6lGT9g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Implementation
&lt;/h2&gt;

&lt;p&gt;The .&lt;em&gt;feature&lt;/em&gt; file contains the test scenarios written using the Gherkin language. I am testing two scenarios — see how easy they are to read:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: ECommerce Playground Demo

@searchItems
Scenario: Search for iPod Nano
    Given I select the Software category
    When I search for iPod Nano
    Then I should get 4 results for iPod Nano

@searchItems
Scenario: Search for HTC Touch HD
    Given I select the Tablets category
    When I search for HTC Touch HD
    Then I should get 8 results for HTC Touch HD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The class containing the implementation (I named it &lt;em&gt;SearchItemsStepDefinitions.cs&lt;/em&gt;) of the steps should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using SpecFlow.Actions.Selenium;
using TechTalk.SpecFlow;

[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]
namespace LTSpecFlow.StepDefinitions
{
    [Binding]
    public class AddItemsToCartStepDefinitions
    {
        private readonly IBrowserInteractions _browserInteractions;
        public AddItemsToCartStepDefinitions(IBrowserInteractions browserInteractions)
        {
            _browserInteractions = browserInteractions;
        }

        [BeforeScenario]
        public void SetUp()
        {
            _browserInteractions.GoToUrl("https://ecommerce-playground.lambdatest.io/");
        }

        [Given(@"I select the (.*) category")]
        public void GivenISelectTheCategory(string category)
        {
            _browserInteractions.WaitAndReturnElement(By.XPath("(//div[@class='dropdown search-category']/button[@type='button'])[1]")).Click();
            _browserInteractions.WaitAndReturnElement(By.XPath($"(//a[text()='{category}'])[1]")).Click();
        }

        [When(@"I search for (.*)")]
        public void WhenISearchForProduct(string product)
        {
            _browserInteractions.WaitAndReturnElement(By.XPath("(//input[@name='search'])[1]")).SendKeys(product);
            _browserInteractions.WaitAndReturnElement(By.XPath("(//button[normalize-space()='Search'])[1]")).Click();
        }

        [Then(@"I should get (.*) results for (.*)")]
        public void ThenIShouldGetResults(int itemsCount, string product)
        {
            int actualCount = _browserInteractions.WaitAndReturnElements(By.XPath($"//div[@class='row']//div[@class='carousel-item active']/img[@alt='{product}']")).Count();
            Assert.AreEqual(itemsCount, actualCount);
        }

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;Let’s begin with the feature file. Each feature file should, ideally, test only one feature of the application. This is defined by the “Feature” keyword, which should be the file’s first line. In my case, I am &lt;a href="https://www.lambdatest.com/blog/website-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing website&lt;/a&gt;’s search functionality, so the name I gave to the feature is “Search products”:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: Search products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, before my test scenario, I added a tag. These tags are used to identify and group related scenarios or scenarios that will be run together at some point.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@searchItems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;One scenario can have multiple tags, for example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SmokeTests @RegressionTests @FunctionalityTests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next comes the actual test scenario:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@searchItems
Scenario: Search for iPod Nano
    Given I select the Software category
    When I search for iPod Nano
    Then I should get 4 results for iPod Nano
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It’s written in plain English and uses the Gherkin keywords:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; this is the title of the test. It should be concise but also detailed enough to understand what it’s testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Given:&lt;/strong&gt; the keyword used for preconditions of the tests. This is the test step that will need to run before the actual test begins.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When:&lt;/strong&gt; the keyword used before the test steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Then:&lt;/strong&gt; This keyword marks the expected result of the test.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The beauty here is that the entire test is extremely easy to read by anybody, not just technical people or automation testers. And also, anybody can write this type of scenario without understanding the inner workings of a test automation framework.&lt;/p&gt;

&lt;p&gt;And thanks to the SpecFlow extension, for any new Gherkin steps written, you can generate the code steps, by right-clicking on the steps and selecting Define steps. You’ll get something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoH7xfYj64Je4YzS0KTYDQg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoH7xfYj64Je4YzS0KTYDQg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you’ll have to write the implementation for the steps. This brings us to the Steps Definition class. The first part contains the packages used in the class:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using SpecFlow.Actions.Selenium;
using TechTalk.SpecFlow;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We are using Selenium, SpecFlow, SpecFlow Actions, and NUnit, which I use for the test’s assertions.&lt;/p&gt;

&lt;p&gt;Then, using NUnit’s Parallelizable attribute, I define that 4 tests from the same assembly can run in parallel (so all the tests from the example, since we have 2 tests and 2 browser configurations). To learn more about &lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel execution with SpecFlow, NUnit, and Selenium&lt;/a&gt;, please go through the following video:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/910006FVRTY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now comes the actual implementation. The [&lt;em&gt;Binding&lt;/em&gt;] attribute marks the class as a step implementation class.&lt;/p&gt;

&lt;p&gt;The first thing you need to do is create a constructor, and instantiate an IBrowserInteractions variable (this is the SpecFlow Actions equivalent of Selenium’s IWebDriver):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private readonly IBrowserInteractions _browserInteractions;
        public AddItemsToCartStepDefinitions(IBrowserInteractions browserInteractions)
        {
            _browserInteractions = browserInteractions;
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, use the [&lt;em&gt;BeforeScenario&lt;/em&gt;] hook, which marks the following method to run before each scenario. I prefer using this type of hook instead of writing an explicit Gherkin step for starting the app because, while this step is mandatory before any other steps, I don’t find that it reflects a part of the user behavior:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[BeforeScenario]
        public void SetUp()
        {
            _browserInteractions.GoToUrl("https://ecommerce-playground.lambdatest.io/");
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The following methods will be the test steps. For each method to be bound to the correct feature step, it needs to have a matching attribute (Given / When / Then), followed by a regular expression that matches the Gherkin step. For example, the&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Given(@"I select the (.*) category")]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Regular expression matches both&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given I select the Software category
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given I select the Tablets category
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The (.*) pattern means that my expression will match any value. Then the method needs to have a parameter of the relevant type — string in this case, and int and string in the last step.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I should get (.*) results for (.*)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The actual implementation is fairly similar to a Selenium implementation, except this time we are using the methods provided by SpecFlow Actions. To identify elements, you need to use &lt;em&gt;WaitAndReturnElement&lt;/em&gt; (for a single element) and &lt;em&gt;WaitAndReturnElements&lt;/em&gt; (for a list of elements), and then to interact with them, you can use Click() and SendKeys() — the same way you would if you would use Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;For this particular SpecFlow automation tutorial, I used the &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath locator&lt;/a&gt; for the web elements on the page because the web elements do not have unique IDs. XPath is one of the most used locators in &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; for navigating across a page’s HTML structure. Any element on a web page can be located using the HTML DOM framework for both HTML and XML documents.&lt;/p&gt;

&lt;p&gt;The basic fundamental format of an XPath is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//tagname[@attribute=’value’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;//: indicates the active node;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tagname: indicates the node’s tag (for example, a for hyperlinks, button for buttons, etc.);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The @ character marks the node’s attribute;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attribute: the name of the node’s attribute;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Value: the chosen attribute’s value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get the elements’ XPath, you can use the Developer Tools provided by the browser (right-click on the element and select Inspect) and build it based on its attributes.&lt;br&gt;
You can even select Copy → XPath, although this might not always return the best XPath or even a unique one. You can also use Chrome extensions that help identify the best locator for web elements, I use and recommend &lt;a href="https://www.lambdatest.com/blog/selectorshub-the-next-gen-xpath-css-selectors-tool/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;SelectorsHub&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;You can use the Console to see how many elements are returned for a specific XPath:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AukEdlI_8jWUfjVe344ba0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AukEdlI_8jWUfjVe344ba0Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use the Console to see how many elements are returned for a specific XPath:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AukEdlI_8jWUfjVe344ba0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AukEdlI_8jWUfjVe344ba0Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5eWDc_FSW6xBsiy0zPcn3Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5eWDc_FSW6xBsiy0zPcn3Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what you need to do is:&lt;/p&gt;

&lt;p&gt;1- Click on the category button to expand the menu, and then click on the given category (which will be passed as a parameter):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Given(@"I select the (.*) category")]
public void GivenISelectTheCategory(string category)
{
  _browserInteractions.WaitAndReturnElement(By.XPath("(//div[@class='dropdown search-category']/button[@type='button'])[1]")).Click();
  _browserInteractions.WaitAndReturnElement(By.XPath($"(//a[text()='{category}'])[1]")).Click();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;2- Type in the search keyword (also passed a parameter) and click the Search button:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[When(@"I search for (.*)")]
public void WhenISearchForProduct(string product)
{
  _browserInteractions.WaitAndReturnElement(By.XPath("(//input[@name='search'])[1]")).SendKeys(product);
  _browserInteractions.WaitAndReturnElement(By.XPath("(//button[normalize-space()='Search'])[1]")).Click();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;3- Validate that the number of actual results matches the expected number:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Then(@"I should get (.*) results")]
public void ThenIShouldGetResults(int itemsCount)
{
  int actualCount = _browserInteractions.WaitAndReturnElements(By.XPath("//div[@class='carousel-item active']")).Count();
  Assert.AreEqual(itemsCount, actualCount);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, you can use the Assert class from NUnit to compare two values. If the values are equal, the test will pass; if not, the test will fail.&lt;/p&gt;

&lt;p&gt;And that’s all! Now let’s put our tests to work!&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution
&lt;/h2&gt;

&lt;p&gt;You will be able to see the tests in Test Explorer (Test → Test Explorer), just like in any other Visual Studio Project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ac0NmT2qFpRE5tKPYYHE1Hg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ac0NmT2qFpRE5tKPYYHE1Hg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The number of tests will match the number of scenarios defined in the feature file(s) times the number of browser configurations. In this SpecFlow automation tutorial, I have 2 scenarios and 2 browser configurations, so I’ll see 4 tests in the explorer window. The Traits column is populated with the tags I used for the scenarios.&lt;/p&gt;

&lt;p&gt;Now, if you press Run All, you’ll see that the tests start executing, and if you define the parallelization, they will run in parallel. No browser window will open since we’re running the tests on the cloud. Still, you can see the tests running on the LambdaTest Dashboard:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AxZzoW30uyQpKwuIFG1gnHQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AxZzoW30uyQpKwuIFG1gnHQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once they finish running, you can see them in your LambdaTest account, in &lt;em&gt;Automation → Builds&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A--eHHwk3O4w_tzqJZWxJIg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A--eHHwk3O4w_tzqJZWxJIg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To see the details, you can click on each test, where you will find a video recording of the test run, the configuration details, the time it took for the test to run, its result, and the step details with each of their results. You can also click on each step to see the recording at that exact time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A6OmWyFGK8A-5-hq5RtG6fw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A6OmWyFGK8A-5-hq5RtG6fw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are you a tester looking to hone your skills? Prove your worth by earning the Selenium C# 101 certification by LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;How to inspect elements on iPhone? Read the blog to know more about &lt;a href="https://www.lambdatest.com/blog/how-to-inspect-elements-on-iphone/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to inspect elemtns on mac&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;, we have seen why SpecFlow is an excellent framework for writing behavior-driven scenarios because the tests can be written in simple English and understood by anyone on the team.&lt;/p&gt;

&lt;p&gt;And on top of this, using SpecFlow Actions can power up your test automation even further since it enables you to run the tests on various browser versions and operating systems and run them in parallel on the &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; cloud.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Perform Web How To Start Running Automated Tests With Selenium C#</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Mon, 21 Nov 2022 14:58:09 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-perform-web-how-to-start-running-automated-tests-with-selenium-c-2ef7</link>
      <guid>https://forem.com/testmuai/how-to-perform-web-how-to-start-running-automated-tests-with-selenium-c-2ef7</guid>
      <description>&lt;p&gt;The Selenium framework itself is a set of different tools, but the most popular and the most useful to new and experienced testers alike is WebDriver. &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; is a free and open-source tool that allows you to interact with a website for web &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;. It also supports popular programming languages like C#, Java, JavaScript, Python, Ruby, and PHP. As per reports, C# is just behind Python, C, Java, and C++ in terms of popularity. I’ve been working mostly with Selenium C# for some time, and I’ll tell you why.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AR3-BifG_S7YkdGF9hgrW0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AR3-BifG_S7YkdGF9hgrW0Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I’m just starting a project, I like to use the same language the development team uses for two main reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The test project can be integrated with the existing solution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The development team can help with improvements in the testing framework.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Selenium is my preferred and one of the &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;best test automation frameworks&lt;/a&gt; since I can use the C# bindings for Selenium to write automated tests. At the time of writing this blog on &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;C# Automation testing&lt;/a&gt;, the latest Selenium version available is 4.2.0, so I’ll be using that version for the following &lt;a href="https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By the end of this Selenium with C# tutorial, you will be in a position to write automated tests that work seamlessly on local and &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So let’s get started!&lt;/p&gt;

&lt;p&gt;Before you get started, you need to have a code editor installed on your machine. For this Selenium C# tutorial, I’ll be using Visual Studio, but you can use any IDE you prefer for editing your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium online&lt;/a&gt; Grid to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create a new Selenium C# project?
&lt;/h2&gt;

&lt;p&gt;The steps to create a new project in Visual Studio are pretty straightforward. Please follow the below steps to create a new project in Selenium with C#.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click “&lt;strong&gt;Create a new project&lt;/strong&gt;” from the splash window:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2An3KqdPlpnChdlQN63mEYZQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2An3KqdPlpnChdlQN63mEYZQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Then select the type of project you want to use. We continue with the “&lt;strong&gt;NUnit Test Project&lt;/strong&gt;” for .NET Core for this blog.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2306%2F1%2ANgIyR_GyZNtB144kvvxb5A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2306%2F1%2ANgIyR_GyZNtB144kvvxb5A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m using &lt;strong&gt;NUnit&lt;/strong&gt; because it’s one of the most used frameworks to automate &lt;a href="https://www.lambdatest.com/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;web testing&lt;/a&gt; and will help simplify our test writing process. You can go through this &lt;a href="https://www.lambdatest.com/learning-hub/nunit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium NUnit tutorial&lt;/a&gt; to learn more about &lt;a href="https://www.lambdatest.com/blog/setup-nunit-environment-with-visual-studio/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;setting up NUnit with Visual Studio&lt;/a&gt;. The latest version of NUnit is 3.13.3. Here are some of my favorite features of NUnit that help me in my Selenium C# projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Annotations&lt;/strong&gt; — These are NUnit attributes (or tags) that tell the code how the methods implemented under it are interpreted. The syntax is the attribute name between square brackets. Some of the commonly used &lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit annotations&lt;/a&gt;, and the most used, in my experience, are:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[SetUp]:&lt;/strong&gt; marks a method that is executed before each test method&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[Test]:&lt;/strong&gt; the attribute that marks a test method&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[TearDown]:&lt;/strong&gt; the method implemented under TearDown will be executed after each test method&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[OneTimeSetUp]:&lt;/strong&gt; an attribute used to indicate that the method will be called once before the tests run&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[OneTimeTearDown]:&lt;/strong&gt; marks a method that will be executed after all the tests finish running&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;[TestFixture]:&lt;/strong&gt; marks a class that contains tests. Starting with NUnit 2.5, it has become optional — a class that contains tests (marked with the &lt;strong&gt;[Test]&lt;/strong&gt; attribute) will be identified even without the TestFixture attribute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Assertions&lt;/strong&gt; — Use &lt;a href="https://www.lambdatest.com/blog/asserts-in-nunit/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit assertions&lt;/a&gt; to validate if the test has the expected result. I usually stick to the “classic” assertions:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assert.IsTrue(): checks that a given condition is true.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assert.IsFalse(): checks that a given condition is false&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assert.AreEqual(): checks that two given objects are equal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parallelization:&lt;/strong&gt; Allows &lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel execution in NUnit&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data-driven testing:&lt;/strong&gt; Using &lt;a href="https://www.lambdatest.com/blog/nunit-parameterized-test-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parameterization in NUnit&lt;/a&gt;, we can run the same test using different datasets.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Select a name and a location for it, and hit “&lt;strong&gt;Create&lt;/strong&gt;”:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2Ai8FUu2ikuI-qpfHIMiYMTA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2Ai8FUu2ikuI-qpfHIMiYMTA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll see that Visual Studio automatically created a test class called &lt;em&gt;UnitTest1.cs:&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;

namespace NUnitTestProject1
{
    public class Tests
    {
        [SetUp]
        public void Setup()
        {
        }

        [Test]
        public void Test1()
        {
            Assert.Pass();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  How to run Selenium C# tests from Visual Studio?
&lt;/h2&gt;

&lt;p&gt;If you want to see and run the tests in the solution, you need to follow the below steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Test Explorer (if it’s not already opened). You can do that from the View menu → Test Explorer. In this panel, you can see all available tests, grouped by project and test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Currently, we only have the one that VS has created for us, but we can right-click on it (or any tree in the node) and run it. We’ll see that it passes and the time it took for the test to run:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AY6pWJBai42GwKMpeFpKwuw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AY6pWJBai42GwKMpeFpKwuw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s move on and see how to write our own Selenium WebDriver automated tests.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UdsGfnBUYSI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;h2&gt;
  
  
  How to run your first Selenium C# test?
&lt;/h2&gt;

&lt;p&gt;It’s time for some action 🙂 Now that I have covered the essentials of Selenium with C#, let’s run a simple &lt;a href="https://www.lambdatest.com/blog/nunit-testing-tutorial-for-selenium-csharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation test with Selenium C#&lt;/a&gt; that uses the NUnit framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’ll use a simple scenario to illustrate how to automate some basic steps using Selenium with C#. Here are the steps I want my test to execute:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;a href="https://www.lambdatest.com/selenium-playground/simple-form-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com/selenium-playground/simple-form-demo&lt;/a&gt; web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a text in the “Enter Message” input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click “Get Checked value”.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Validate that the message is displayed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Al3uaASwRW5DKJg9hGYfFJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Al3uaASwRW5DKJg9hGYfFJg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simple, right? Let’s go!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/s08-pbKaSQM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Testing Tool&lt;/a&gt; Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing Selenium WebDriver using NuGet Package Manager
&lt;/h2&gt;

&lt;p&gt;Before we start interacting with the browser, the web pages, and the WebElements in the DOM, we have to prepare our project.&lt;/p&gt;

&lt;p&gt;For this, we need to add the Selenium.WebDriver NuGet package, which allows the test code to interact with the WebElements on the page using methods that are a part of the package. To add a NuGet package to the project, please follow the below-mentioned steps:&lt;/p&gt;

&lt;p&gt;1- Right-click on the project name in the Solution Explorer → Select “&lt;strong&gt;Manage NuGet packages…&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Athy1dMkSEFhukRHoKqTzlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Athy1dMkSEFhukRHoKqTzlw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open the NuGet packages panel, where you can see the packages already installed on your project and add more.&lt;/p&gt;

&lt;p&gt;2- In the &lt;strong&gt;Browse&lt;/strong&gt; tab, search for “selenium”, and select Selenium.WebDriver from the results. From the details panel on the right-hand side, choose an option from the Version drop-down, then click &lt;strong&gt;Install&lt;/strong&gt;. I’ll be using Selenium version 3.141.0 for this Selenium C# tutorial:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2A0Ha7z46_ZbhnjWldz34nSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2A0Ha7z46_ZbhnjWldz34nSQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, you can install NuGet packages from the command line by running this command in the project location:&lt;/p&gt;

&lt;p&gt;dotnet add package Selenium.WebDriver --version 3.141.0&lt;/p&gt;

&lt;p&gt;Now, if you go to the &lt;strong&gt;Installed&lt;/strong&gt; tab, you will see that Selenium.WebDriver is added to the list of installed packages:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You might need to use Selenium WebDriver commands to automate various browser actions. You can refer to our earlier article on &lt;a href="https://www.lambdatest.com/blog/top-28-selenium-webdriver-commands-in-nunit-for-test-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver Commands in NUnit&lt;/a&gt; to learn more about it, which might come in handy while performing &lt;a href="https://www.lambdatest.com/automated-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated UI testing&lt;/a&gt; with Selenium C#.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8k6blCrD-QoP0XA4ehATwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8k6blCrD-QoP0XA4ehATwg.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding the Browser Driver
&lt;/h2&gt;

&lt;p&gt;Another thing we need to set up before we start writing the test is to add a browser driver. I’ll be performing a &lt;a href="https://www.lambdatest.com/intl/en-in/test-on-chrome-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test on Chrome browser&lt;/a&gt; for now, so I need to add ChromeDriver. It can also be added as a NuGet package, so follow the same steps as before to add &lt;em&gt;Selenium.WebDriver.ChromeDriver&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;One thing to make sure of here — install the same driver version as the browser you have installed on your machine. For example, I have Chrome 101.0.4951.67, so I need to install the same driver version:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxJ9IMZFJe3I5CdO5EP5lZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxJ9IMZFJe3I5CdO5EP5lZA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check the browser version from Help → About Google Chrome.&lt;/p&gt;

&lt;p&gt;You can use the browser of your choice, and you can add the drivers the same way, for example, &lt;em&gt;Selenium.WebDriver.MSEdgeDriver&lt;/em&gt; (for Microsoft Edge), &lt;em&gt;Selenium.WebDriver.GeckoDriver&lt;/em&gt; (for Mozilla Firefox).&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing Selenium C# test
&lt;/h2&gt;

&lt;p&gt;Now, we should be ready to start our Selenium C# test. Let’s use the previously created class, but rename it to something meaningful:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aa0jedT8edKhTcAJ3UErdBA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aa0jedT8edKhTcAJ3UErdBA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is the Selenium C# test for the mentioned scenario:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTutorial
{
    public class SeleniumTests
    {
        private IWebDriver driver;

        [SetUp]
        public void Setup()
        {
            driver = new ChromeDriver();
        }

        [Test]
        public void ValidateTheMessageIsDisplayed()
        {
            driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/simple-form-demo");
            driver.FindElement(By.Id("user-message")).SendKeys("LambdaTest rules");
            driver.FindElement(By.Id("showInput")).Click();
            Assert.IsTrue(driver.FindElement(By.Id("message")).Text.Equals("LambdaTest rules"), "The expected message was not displayed.");
        }

        [TearDown]
        public void TearDown()
        {
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Selenium C# code walkthrough
&lt;/h2&gt;

&lt;p&gt;The used packages are added at the beginning of the test class:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, we need to create a new instance of the IWebDriver:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private IWebDriver driver;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As a precondition to the test, we need to start the browser. I did this in the SetUp method because it’s something that will be used in all future tests, so here is where I instantiate the driver:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [SetUp]
        public void Setup()
        {
            driver = new ChromeDriver();
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, there is our actual test. I used the previously mentioned &lt;em&gt;[Test]&lt;/em&gt; attribute from NUnit, and inside the test method, the test steps:&lt;/p&gt;

&lt;p&gt;To navigate to a specific URL, Selenium with C# uses the method &lt;em&gt;Navigate().GoToUrl()&lt;/em&gt;, with the URL, passed as a string parameter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/simple-form-demo");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, we need to interact with three WebElements on the page, which means we need to locate these elements. For this, we have the &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;em&gt;FindElement() and FindElements()&lt;/em&gt; methods in Selenium WebDriver&lt;/a&gt;. The &lt;em&gt;FindElement()&lt;/em&gt; method returns a web element object, while the FindElements() returns a list of web elements. For the purpose of our test, FindElement() will do the job.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.Locator("Value"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The FindElement() method takes a By method parameter and returns the first element that matches that method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The By class provides the mechanism to find the elements on our web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The locator is the strategy used to identify the element.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AIID9GUw9e86SzYAVH266Cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AIID9GUw9e86SzYAVH266Cw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are several &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; strategies that we can use to identify the web elements based on their attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ID — &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator in Selenium&lt;/a&gt; uses the ID attribute of the element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name — &lt;a href="https://www.lambdatest.com/blog/how-to-use-name-locator-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Name locator in Selenium&lt;/a&gt; uses the Name attribute of the element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LinkText and PartialLinkText — &lt;a href="https://www.lambdatest.com/blog/using-link-text-and-partial-link-text-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LinkText and PartialLinkText locators in Selenium&lt;/a&gt; applies to link elements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ClassName — &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ClassName locator in Selenium&lt;/a&gt; uses the Class attribute of the element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TagName — &lt;a href="https://www.lambdatest.com/blog/locating-elements-by-tagname-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TagName locator in Selenium&lt;/a&gt; uses a tag name to identify the attribute&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CssSelector — &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CssSelector locator in Selenium&lt;/a&gt; combines an element selector and a selector value to find the web element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XPath — &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath locator in Selenium&lt;/a&gt; uses the HTML DOM structure to locate any element in a web page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Value is the string value of that attribute.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can refer to this &lt;a href="https://www.lambdatest.com/blog/selenium-locators-cheat-sheet/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators cheat sheet&lt;/a&gt; to quickly navigate through all the Selenium locators with their easy-to-use syntax.&lt;/p&gt;

&lt;p&gt;When using &lt;em&gt;FindElement()&lt;/em&gt;, it’s a good practice to create a unique locator; otherwise, your test might interact with a different element than the intended one. You can use &lt;a href="https://www.lambdatest.com/blog/top-16-tips-to-use-chrome-dev-tools-for-cross-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Chrome’s Developer Tools&lt;/a&gt; to find the best locator strategy for each element.&lt;/p&gt;

&lt;p&gt;You can right-click on a WebElement on the page and select Inspect. This will open the Elements tab of the Developer Tools, where you can see the element’s information. Here is the code for the input text:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AWPxVmLKtAlg1HQoU-k8HUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AWPxVmLKtAlg1HQoU-k8HUw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The recommended locator is Id because it’s usually faster. Luckily, we have unique Ids on all the elements we need, so we can use them going forward. The &lt;a href="https://www.lambdatest.com/blog/how-to-use-selenium-sendkeys/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;*SendKeys() *method in Selenium C#&lt;/a&gt; is used to enter text in input fields. It takes a string parameter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.FindElement(By.Id("user-message")).SendKeys("LambdaTest rules");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Click() method is used to simulate the mouse click:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; driver.FindElement(By.Id("showInput")).Click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;em&gt;Text&lt;/em&gt; is a string attribute that represents the inner value of the web element, and we use the &lt;em&gt;Assert.IsTrue()&lt;/em&gt; method to validate that the message has the message we expect. I also like my test to display a message if it fails, making it easier to debug:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Assert.IsTrue(driver.FindElement(By.Id("message")).Text.Equals("LambdaTest rules"), "The expected message was not displayed.");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To close the browser at the end of the test, use the TearDown attribute and this method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [TearDown]
        public void TearDown()
        {
            driver.Quit();
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are two similar methods in Selenium WebDriver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;em&gt;Close()&lt;/em&gt; method, which closes the current window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;em&gt;Quit()&lt;/em&gt; method, which closes all windows associated with the driver.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the TearDown, I prefer the second one in case some of the tests open additional windows (remember that the &lt;em&gt;TearDown&lt;/em&gt; method runs after each test).&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Selenium C# test
&lt;/h2&gt;

&lt;p&gt;Now that the test is ready, you can build the project (right-click on the project name and select Build or use the Ctrl+B shortcut) and run the test locally. The test will be visible in the Test Explorer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFxrTEWF_WnxtULwzIi17qw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFxrTEWF_WnxtULwzIi17qw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, you can run it just like you did the previous test. If everything goes well, you will see a browser window open up, navigate the web page, enter the text, and click the button. The test will pass, and close the browser window at the end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AwTEu4f5C_MRN4hEPttnS3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AwTEu4f5C_MRN4hEPttnS3g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Selenium C# tests on cloud Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;What if you want to run the automated tests cross-platform or cross-browser? Or using a setup different from your own machine? These situations will likely happen quite often because we want our applications to work for all our users, and they will have various configurations set up on their computers.&lt;/p&gt;

&lt;p&gt;The solution for this is porting the existing Selenium C# tests to a cloud-based &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; like LambdaTest. Cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platforms like LambdaTest provides an &lt;a href="https://www.lambdatest.com/online-device-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; of 3000+ browsers and operating systems to perform Selenium C# testing at scale. Here’s a glimpse of the LambdaTest cloud Selenium Grid:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The best part is that not much porting effort is involved in porting the existing tests from the local Selenium Grid to the LambdaTest cloud grid.&lt;/p&gt;

&lt;p&gt;Here’s is my version of the code, updated to run the tests in LambdaTest Grid:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.Threading;

namespace SeleniumTutorial
{
    public class SeleniumTests
    {
        private static IWebDriver driver;
        public static string gridURL = "@hub.lambdatest.com/wd/hub";
        public static string LT_USERNAME = "LT_USERNAME"; // Add your LambdaTest username here
        public static string LT_ACCESS_KEY = "LT_ACCESS_KEY"; // Add your LambdaTest access key here

        [SetUp]
        public void Setup()
        {
            var desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browserName", "Chrome");
            desiredCapabilities.SetCapability("platform", "Windows 11");
            desiredCapabilities.SetCapability("version", "101.0");
            desiredCapabilities.SetCapability("screenResolution", "1280x800");
            desiredCapabilities.SetCapability("user", LT_USERNAME);
            desiredCapabilities.SetCapability("accessKey", LT_ACCESS_KEY);
            desiredCapabilities.SetCapability("build", "Selenium C-Sharp");
            desiredCapabilities.SetCapability("name", "Selenium Test");
            driver = new RemoteWebDriver(new Uri("https://" + LT_USERNAME + ":" + LT_ACCESS_KEY + gridURL), desiredCapabilities, TimeSpan.FromSeconds(600));
        }

        [Test]
        public void ValidateTheMessageIsDisplayed()
        {
            driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/simple-form-demo");
            driver.FindElement(By.Id("user-message")).SendKeys("LambdaTest rules");
            driver.FindElement(By.Id("showInput")).Click();
            Assert.IsTrue(driver.FindElement(By.Id("message")).Text.Equals("LambdaTest rules"), "The expected message was not displayed.");
        }

        [TearDown]
        public void TearDown()
        {
            Thread.Sleep(3000);
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Again, we have the packages are added:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.Threading;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, we declare our variables:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static IWebDriver driver;
        public static string gridURL = "@hub.lambdatest.com/wd/hub";
        public static string LT_USERNAME = "LT_USERNAME"; // Add your LamdaTest username here
        public static string LT_ACCESS_KEY = "LT_ACCESS_KEY"; // Add your LamdaTest access key here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When using LambdaTest, you need to make sure you use your username and access key. You can find them on your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. A good idea is to store them as environment variables and read them from there. This way, in case any of the values change, you only need to update them in one place.&lt;/p&gt;

&lt;p&gt;The biggest change, as you can see, is in the Setup:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [SetUp]
        public void Setup()
        {
            var desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browserName", "Chrome");
            desiredCapabilities.SetCapability("platform", "Windows 11");
            desiredCapabilities.SetCapability("version", "101.0");
            desiredCapabilities.SetCapability("screenResolution", "1280x800");
            desiredCapabilities.SetCapability("user", LT_USERNAME);
            desiredCapabilities.SetCapability("accessKey", LT_ACCESS_KEY);
            desiredCapabilities.SetCapability("build", "Selenium C-Sharp");
            desiredCapabilities.SetCapability("name", "Selenium Test");
            driver = new RemoteWebDriver(new Uri("https://" + LT_USERNAME + ":" + LT_ACCESS_KEY + gridURL), desiredCapabilities, TimeSpan.FromSeconds(600));
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;DesiredCapabilities&lt;/em&gt; is a Selenium class used to configure browser attributes for cross-browser testing. You can use &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt; to create your desired setup:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3760%2F1%2AEeUyXfSbX3Y2hgK_3qKq5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3760%2F1%2AEeUyXfSbX3Y2hgK_3qKq5g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The test has remained unchanged, I am still testing the same scenario:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
        public void ValidateTheMessageIsDisplayed()
        {
            driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/simple-form-demo");
            driver.FindElement(By.Id("user-message")).SendKeys("LambdaTest rules");
            driver.FindElement(By.Id("showInput")).Click();
            Assert.IsTrue(driver.FindElement(By.Id("message")).Text.Equals("LambdaTest rules"), "The expected message was not displayed.");
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And in the teardown, I only added a short sleep so the browser doesn’t close too quickly, and I see in the recording what happened:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TearDown]&lt;br&gt;
        public void TearDown()&lt;br&gt;
        {&lt;br&gt;
            Thread.Sleep(3000);&lt;br&gt;
            driver.Quit();&lt;br&gt;
        }&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Executing Selenium C# tests on Cloud&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Now run the test, the same as before, from Visual Studio. This time the browser will not open locally. But if you connect to your LambdaTest account, you will see in the &lt;a href="https://automation.lambdatest.com/build?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Tab&lt;/a&gt; that the test is running:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3834%2F1%2Ay555fIN4b22RRqCArztgkQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3834%2F1%2Ay555fIN4b22RRqCArztgkQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a fairly simple test, so it will finish fast, the same as it did on the local machine. But this time you can also see a recording of the test execution. I find this particularly helpful if the test fails and you want to see why. But I personally like to see the passed tests, too, because I want to make sure that the intended actions have been correctly executed, so I avoid false positives.&lt;/p&gt;

&lt;p&gt;You can use the right-hand panel to navigate to a specific step and see what happened there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3668%2F1%2AvFVObowxi-EFbQ-vdVc9HQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3668%2F1%2AvFVObowxi-EFbQ-vdVc9HQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, you can use multiple setups to validate the scenario on multiple configurations, and, as the project grows, you can take advantage of the ability to run tests in parallel.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5Q0yxvErcCw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can navigate to the &lt;a href="https://analytics.lambdatest.com/test-overview?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt; to use advanced features for analyzing the performance of your tests. From the Test Summary section, you can see all test results, along with their status and the total number of tests passed or failed. From the Test Overview section, you can see the snapshots of recently executed test runs.&lt;/p&gt;

&lt;p&gt;If you are a developer or a tester and want to master the fundamentals of Selenium automation testing with C#, you can take the Selenium C# 101 certification to prove your credibility as a tester.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium C# 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZU85Mjwgv54"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform manual or automated cross browser &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;testing web&lt;/a&gt; on 3000+ browsers online. Deploy and scale faster with the most powerful cross browser testing tool online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using Selenium with C# and NUnit can be a great choice if you are just getting started with test automation. In this Selenium C# tutorial, we covered the main steps for getting started with a test automation project, from selecting the testing framework to identifying the WebElements, interacting with them, and adding validations. We’ve also seen how to run the tests remotely on a different setup and see the results and the recording.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2fN6GcZ3-fs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Select Dropdown In Selenium C#</title>
      <dc:creator>AndreeaDraniceanu</dc:creator>
      <pubDate>Mon, 21 Nov 2022 13:49:57 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-select-dropdown-in-selenium-c-4cml</link>
      <guid>https://forem.com/testmuai/how-to-select-dropdown-in-selenium-c-4cml</guid>
      <description>&lt;p&gt;Dropdowns and multi-selects are extremely common in today’s web pages. Dropdowns can be a great option to allow your users to choose from several options without having to scroll through a whole page. In HTML, these web elements are defined by the tag &amp;lt; select &amp;gt;, with multiple &amp;lt; option &amp;gt; child tags representing the available options to choose from.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/blog/category/selenium-c/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium C# tutorial&lt;/a&gt;, I’ll show you how to select dropdown in Selenium C# and multiple select menus. Here, I will be running tests with different test data and demonstrate how to run them in parallel on the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Upload your app for testing within seconds using the LambdaTest cloud and perform mobile app testing right away. Find bugs early on, improve performance, quality, user experience and make the most of &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Mobile App Testing&lt;/a&gt; on LambdaTest.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started with a Selenium project?
&lt;/h2&gt;

&lt;p&gt;We first need to set up a new &lt;a href="https://www.lambdatest.com/blog/build-and-execute-selenium-projects/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium project&lt;/a&gt; in Visual Studio (or Visual Studio Code). For this Selenium C# tutorial, I will be using NUnit as a test framework. However, there are other frameworks available, such as XUnit or MSTest.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2532%2F1%2AQhPnIYb66iMT7_xeGFJdTA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2532%2F1%2AQhPnIYb66iMT7_xeGFJdTA.png" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Add the Selenium packages we will use in the project. To do this, right-click on the project name in the Solution Explorer pane, and select &lt;em&gt;Manage NuGet packages&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaQ3n4-gAb9xFMLkCV_sq8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaQ3n4-gAb9xFMLkCV_sq8g.png" width="442" height="840"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Search for and install:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.WebDriver&lt;/strong&gt;: we need it to interact with the WebElements on the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.Support&lt;/strong&gt;: it’s the package that enables us to work with dropdowns in Selenium.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.WebDriver.ChromeDriver (or a different driver if you want to test on another browser)&lt;/strong&gt;: allows the interaction with the browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will then have them in the list of installed packages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMqdjS0LvERzxPR6suySNXA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMqdjS0LvERzxPR6suySNXA.png" width="681" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UdsGfnBUYSI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In the next section of this article on how to select dropdown in Selenium C#, we will learn about the SelectElement Class in Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  The SelectElement Class in Selenium C
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;SelectElement&lt;/strong&gt; class in Selenium C# is part of the Selenium.Support NuGet package. It allows us to interact with the dropdown and multiple select menus on web pages.&lt;/p&gt;

&lt;p&gt;It also allows you to select and deselect options from the dropdown, validate if it allows multiple selections, see all the available options, and see what options are currently selected.&lt;/p&gt;

&lt;p&gt;To understand how to select dropdown in Selenium C#, let me show how a dropdown looks in the Inspector from Developer Tools:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ab7b-1l70FkWdNZhz5wX8oQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ab7b-1l70FkWdNZhz5wX8oQ.png" width="800" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a simple dropdown that allows you to choose a day of the week.&lt;/p&gt;

&lt;p&gt;Methods in the SelectElement class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SelectByValue()&lt;/strong&gt;: will select the option based on the value from the HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SelectByText()&lt;/strong&gt;: used to select the dropdown option based on the displayed text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SelectByIndex()&lt;/strong&gt;: selects the option based on index. The index starts from 0, not 1!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SelectedOption()&lt;/strong&gt;: returns the selected WebElement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AllSelectedOptions()&lt;/strong&gt;: returns a list of the selected WebElements. It should be used only on multiple selections.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IsMultiple()&lt;/strong&gt;: a boolean attribute with the value True if the selection allows multiple selections and False if it doesn’t.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DeelectByValue()&lt;/strong&gt;: will deselect the option based on its value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DeselectByText()&lt;/strong&gt;: used to deselect the dropdown option based on the text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DeselectByIndex()&lt;/strong&gt;: deselects the option based on index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DeselectAll()&lt;/strong&gt;: will deselect all previously selected options.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the main things you need to know while you are learning how to select dropdown in Selenium C#. Now let’s see it in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to select dropdown in Selenium C# with an example?
&lt;/h2&gt;

&lt;p&gt;I’m going to demonstrate how to select dropdown in Selenium C# with a simple scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;a href="https://www.lambdatest.com/selenium-playground/select-dropdown-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Playground Dropdown Demo&lt;/a&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Wednesday from the dropdown.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the text displays the selected day of the week.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before you get started, make sure you create a new NUnit test project in Visual Studio or Visual Code, and add the following NuGet packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.WebDriver&lt;/strong&gt; — I’m using version 3.141.0 in this tutorial.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.Support&lt;/strong&gt; — should have the same version as Selenium.WebDriver.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium.Support.ChromeDriver, Selenium.WebDriver.IEDriver, Selenium.Firefox.WebDriver, etc.&lt;/strong&gt;— depending on the browser you want to use in your test. Going forward, I will use Google Chrome for my tests, but feel free to choose your favorite browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, in a new class, we need to write the following Selenium C# code to perform the dropdown test:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using OpenQA.Selenium.Remote;

namespace SeleniumTutorial
{
    public class DropDown
    {
        private static IWebDriver driver;
        public static string gridURL = "@hub.lambdatest.com/wd/hub";
        public static string LT_USERNAME = "LT_USERNAME";
        public static string LT_ACCESS_KEY = "LT_ACCESS_KEY";

        [SetUp]
        public void Setup()
        {
            var desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browserName", "Chrome");
            desiredCapabilities.SetCapability("platform", "Windows 11");
            desiredCapabilities.SetCapability("version", "101.0");
            desiredCapabilities.SetCapability("screenResolution", "1280x800");
            desiredCapabilities.SetCapability("user", LT_USERNAME);
            desiredCapabilities.SetCapability("accessKey", LT_ACCESS_KEY);
            desiredCapabilities.SetCapability("build", "Selenium C-Sharp");
            desiredCapabilities.SetCapability("name", "Selenium Test");
            driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), desiredCapabilities, TimeSpan.FromSeconds(600));
        }

        [Test]
        public void ValidateDropDownSelection()
        {
            string dayOfTheWeek = "Wednesday";
            driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
            SelectElement dropDown = new SelectElement(driver.FindElement(By.Id("select-demo")));
            dropDown.SelectByValue(dayOfTheWeek);
            string actualText = driver.FindElement(By.CssSelector(".selected-value.text-size-14")).Text;
            Assert.True(actualText.Contains(dayOfTheWeek), $"The expected day of the week {dayOfTheWeek} was not selected. The actual text was: {actualText}.");
        }

        [TearDown]
        public void TearDown()
        {
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let me guide you through the lines of code to get a clear picture of how to select dropdown in Selenium C#.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using OpenQA.Selenium.Remote;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This part contains the packages used in the class.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static IWebDriver driver;
public static string gridURL = "@hub.lambdatest.com/wd/hub";
public static string LT_USERNAME = "LT_USERNAME";
public static string LT_ACCESS_KEY = "LT_ACCESS_KEY";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The first line, above, is where I declare the WebDriver, and the next variables are related to my LambdaTest account.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that allows you to perform &lt;a href="https://www.lambdatest.com/c-sharp-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium C# automation testing&lt;/a&gt; at scale over an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating systems. With LambdaTest, you can run your automated C# test scripts faster and more efficiently by running them in parallel on the fastest cloud-based infrastructure. Therefore, you can test more in less time and ship quality products faster.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Replace LT_USERNAME and LT_ACCESS_KEY with your own credentials, i.e., username and the access key from your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[SetUp]
public void Setup()
{
      var desiredCapabilities = new DesiredCapabilities();
      desiredCapabilities.SetCapability("browserName", "Chrome");
      desiredCapabilities.SetCapability("platform", "Windows 11");
      desiredCapabilities.SetCapability("version", "101.0");
      desiredCapabilities.SetCapability("screenResolution", "1280x800");
      desiredCapabilities.SetCapability("user", LT_USERNAME);
      desiredCapabilities.SetCapability("accessKey", LT_ACCESS_KEY);
      desiredCapabilities.SetCapability("build", "Selenium C-Sharp");
      desiredCapabilities.SetCapability("name", "Selenium Test");
      driver = new RemoteWebDriver(new Uri($"https://{LT_USERNAME}:{LT_ACCESS_KEY}{gridURL}"), desiredCapabilities, TimeSpan.FromSeconds(600));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Using the [SetUp] &lt;a href="https://www.lambdatest.com/blog/nunit-annotations-for-selenium-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;annotation in NUnit&lt;/a&gt;, I let my code know that this method needs to be run before each of my tests. Then, inside it, I set the driver’s capabilities based on the browser type, version, OS, and screen resolution I want to use in my tests.&lt;/p&gt;

&lt;p&gt;I use the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Capabilities Generator&lt;/a&gt; from LambdaTest, so I don’t have to enter them by hand:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3772%2F1%2AxrEsaXTKal_YwofL4XlMmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3772%2F1%2AxrEsaXTKal_YwofL4XlMmw.png" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, I just select my configuration, select the C# language, and simply copy them into my code.&lt;/p&gt;

&lt;p&gt;Then, in the new driver instance, I use the capabilities I copied before and the URL created by combining my username, access key, and the LambdaTest Selenium Grid URL. I like using string interpolation because it reads much easier than concatenation.&lt;/p&gt;

&lt;p&gt;Moving on to the test, let me break it down a bit more:&lt;/p&gt;

&lt;p&gt;The [Test] annotation marks the method beneath it as a test method. After the project is built, I can see this test in the Test Explorer and run it from there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ar3MqT3wZG0C9-6PgfUnM9A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ar3MqT3wZG0C9-6PgfUnM9A.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string dayOfTheWeek = "Wednesday";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This one is pretty straightforward. I created a string variable to store the value I want to test because I am using it in more than one place, and I don’t want to update it in multiple places if the value changes.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Navigate() method in Selenium C# instructs the browser to navigate to a specific location, in my case, to the given URL (using the GoToUrl() method).&lt;/p&gt;

&lt;p&gt;The next part is the actual dropdown selection, which shows how to select dropdown in Selenium C#.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SelectElement dropDown = new SelectElement(driver.FindElement(By.Id("select-demo")));
dropDown.SelectByValue(dayOfTheWeek);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The dropdown web element in Selenium C# has the type SelectElement and has to be declared as a new instance of the SelectElement class. The dropdown web element has an Id value, so I will use the Id locator.&lt;/p&gt;

&lt;p&gt;You can use the browser’s Developer Tools to inspect an element (right-click on the element and select Inspect, and you will see its HTML attributes):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3822%2F1%2AJqBdrZ5ntf9pL_VqpiTv_g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3822%2F1%2AJqBdrZ5ntf9pL_VqpiTv_g.png" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re not familiar with Selenium C# element interaction, you can check out my previous tutorial on &lt;a href="https://www.lambdatest.com/blog/selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing with Selenium C#&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I prefer to use SelectByValue() or SelectByText() for selecting the dropdown value, which in this particular case would accept the same parameter. Using SelectByIndex() also works, but then I would need to know the exact order of the options and ensure that the order doesn’t change. For a day of the week dropdown, that’s fine, but in most cases, the available options might change.&lt;/p&gt;

&lt;p&gt;The last part is the validation, where I verify that the app works as expected:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string actualText = driver.FindElement(By.CssSelector(".selected-value.text-size-14")).Text;
Assert.True(actualText.Contains(dayOfTheWeek), $"The expected day of the week {dayOfTheWeek} was not selected. The actual text was: {actualText}.");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I identified the text displayed based on its &lt;a href="https://www.lambdatest.com/blog/selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selector&lt;/a&gt;, then used the Assert class from NUnit to check that it contains the day of the week I previously selected. In case the &lt;a href="https://www.lambdatest.com/blog/asserts-in-nunit/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit assertion&lt;/a&gt; fails, the test will display a message — I am using string interpolation to insert the string variables in the text.&lt;/p&gt;

&lt;p&gt;The final method is executed after each test, and what it does is close all driver instances:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TearDown]
public void TearDown()
{
    driver.Quit();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Testing&lt;/a&gt; Grid to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to select dropdown in Selenium C# and run the test in parallel?
&lt;/h2&gt;

&lt;p&gt;In this section of this article on how to select dropdown in Selenium C#, I will show you how you can run the same test with different data. The steps will remain the same, so we want to use the same method with different parameters.&lt;/p&gt;

&lt;p&gt;With NUnit, this is achieved with the TestCase attribute. And since we will have more tests now, it’s a good idea to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;, so they don’t take so long to execute. For this, we have the Parallelizable attribute. However, &lt;a href="https://www.lambdatest.com/blog/parallel-execution-with-specflow-nunit-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NUnit parallelization&lt;/a&gt; is not thread-safe, so the tests in a class share the same instance of the driver which might result in unexpected failures.&lt;/p&gt;

&lt;p&gt;So the test method now should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
[TestCase("Monday")]
[TestCase("Tuesday")]
[TestCase("Wednesday")]
[TestCase("Thursday")]
[TestCase("Friday")]
[TestCase("Saturday")]
[TestCase("Sunday")]
[Parallelizable(ParallelScope.All)]
public void ValidateDropDownSelection(string dayOfTheWeek)
{    driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
    SelectElement dropDown = new SelectElement(driver.FindElement(By.Id("select-demo")));
    dropDown.SelectByValue(dayOfTheWeek);
    string actualText = driver.FindElement(By.CssSelector(".selected-value.text-size-14")).Text;
    Assert.True(actualText.Contains(dayOfTheWeek), $"The expected day of the week {dayOfTheWeek} was not selected. The actual text was: {actualText}.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
[TestCase("Monday")]
[TestCase("Tuesday")]
[TestCase("Wednesday")]
[TestCase("Thursday")]
[TestCase("Friday")]
[TestCase("Saturday")]
[TestCase("Sunday")]
[Parallelizable(ParallelScope.All)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With these lines of code, we instruct the test to run once for each day of the week string value.&lt;/p&gt;

&lt;p&gt;The [Parallelizable(ParallelScope.All)] line means that the test can be run in parallel with other tests at the same level — in our case, the method level.&lt;/p&gt;

&lt;p&gt;There are other scopes of parallelization in NUnit:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqNPmBnI4olxk5b6Fpb1RJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqNPmBnI4olxk5b6Fpb1RJg.png" width="495" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;All&lt;/strong&gt;: the test and its children can run in parallel with others at the same level.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Children&lt;/strong&gt;: the scope is defined at the class or assembly level, and child tests of the class or assembly can run in parallel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fixtures&lt;/strong&gt;: fixtures can run in parallel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Self&lt;/strong&gt;: the test itself can run in parallel with other tests.&lt;/p&gt;

&lt;p&gt;public void ValidateDropDownSelection(string dayOfTheWeek)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test method also takes a parameter now. You can see I removed the line:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string dayOfTheWeek = "Wednesday";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is because the value of the dayOfTheWeek variable now comes from the TestCase attribute.&lt;/p&gt;

&lt;p&gt;Everything else stays the same. Now you will see seven tests available in the Test Explorer. When you run them on the &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt;, they will also run in parallel:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALmBBvh2ZpO5sbnK5belypw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALmBBvh2ZpO5sbnK5belypw.png" width="447" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the tests in LamdaTest in real-time while they are running and also see the video recordings afterwards:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3810%2F1%2AtvUoEUcd0fsaDBhyiefiGg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3810%2F1%2AtvUoEUcd0fsaDBhyiefiGg.png" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the left-hand side, there is the recording, and the right side displays the test steps, the step duration, and the result. If you click on the timestamp of a step, the video will jump to that point so you can see the action in the recording.&lt;/p&gt;

&lt;p&gt;You can analyze your test performance through the &lt;a href="https://analytics.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The Test Summary section shows all test results, their status, and the total number of tests passed or failed. The Test Overview section shows snapshots of recently executed test runs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD-mwRfy-PJpjcBqAubAXGg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD-mwRfy-PJpjcBqAubAXGg.gif" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest also provides some advanced features like &lt;a href="https://www.lambdatest.com/hyperexecute?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;HyperExecute&lt;/a&gt;, which helps in achieving up to 70% faster execution of your Selenium NUnit test cases. HyperExecute is a blazing fast test end-to-end test orchestration cloud that allows you to group and distribute tests intelligently across runner environments.&lt;/p&gt;

&lt;p&gt;So far, we have seen how to select dropdown in Selenium C#. In the next section, we will learn to handle multiple select menus.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5Q0yxvErcCw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to handle multiple select in Selenium C#?
&lt;/h2&gt;

&lt;p&gt;In this section of this article on how to select dropdown in Selenium C#, I want to show you how to work with a multi select dropdown using Selenium C#. We’ve already discussed the available methods, so let’s jump in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;a href="https://www.lambdatest.com/selenium-playground/select-dropdown-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Playground Dropdown Demo&lt;/a&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify that the Multi-Select List Demo allows multiple selections — if not, display a message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If it does allow multiple selections, select Florida, New York, and Texas&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deselect all values.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The SetUp and TearDown methods are the same as before, so I will just show you the test method code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Test]
public void ValidateMultipleSelection()
{
    driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
    string[] selectedStates = { "Florida", "New York", "Texas" };
    var multiSelect = new SelectElement(driver.FindElement(By.Id("multi-select")));
    Assert.IsTrue(multiSelect.IsMultiple, "The Select does not allow multiple selection.");
    foreach (var state in selectedStates)
    {
        multiSelect.SelectByText(state);
    }
    multiSelect.DeselectAll();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first few lines don’t have anything new. We need to navigate to the web page (the same as before), create an array of strings with the values we want to select, and declare the multiSelect dropdown using the &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;FindElement() method in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.Navigate().GoToUrl("https://www.lambdatest.com/selenium-playground/select-dropdown-demo");
    string[] selectedStates = { "Florida", "New York", "Texas" };
    var multiSelect = new SelectElement(driver.FindElement(By.Id("multi-select")));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In Developer Tools, you can see that the select element has an ID, which I used above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2046%2F1%2A5upb8SFToyx73mJbmExDvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2046%2F1%2A5upb8SFToyx73mJbmExDvw.png" width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I want to validate that the SelectElement allows multiple selections. As I previously mentioned, the IsMultiple attribute will let me know if I can select multiple options or not.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Assert.IsTrue(multiSelect.IsMultiple, "The Select does not allow multiple selection.");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If this assertion fails, the test will simply fail and stop executing the following steps. Of course, I expect it to pass, and if multiple selections is allowed, I want to perform the next actions:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach (var state in selectedStates)
{
    multiSelect.SelectByText(state);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is a simple loop that goes through each value of the selectedStates array, and then selects the value, using the text this time — once again, the text and the value of the options are the same.&lt;/p&gt;

&lt;p&gt;The last step deselects all the previously selected values:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;multiSelect.DeselectAll();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Are you a tester looking to hone your craft? Prove your worth by earning the Selenium C# 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium C# 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZU85Mjwgv54"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov21_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Automation&lt;/a&gt; Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you followed this tutorial blog on how to select dropdown in Selenium C#, you should now know how to select or deselect a dropdown value using Selenium C#, how to work with multiple selects, and also how to run the same test with different test data in NUnit.&lt;/p&gt;

&lt;p&gt;And as a bonus, you could also see how to parallelize the tests and run them on the remote Selenium grid to save the test execution time.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
