CAPABILITY GENERATOR

LambdaTestAutomation Testing ● SpecFlow Selenium: Run Automation Scripts on Online Grid Using SpecFlow Testing Framework

SpecFlow Selenium: Run Automation Scripts on Online Grid Using SpecFlow Testing Framework


LambdaTest offers support with Selenium WebDriver to help you instantly execute your automation test scripts. LambdaTest is a cloud-based, cross browser testing tool offering a Selenium grid consisting of 2000+ browsers and browser versions running on real operating systems to pace up automation testing of your web-app or website. In this topic, you will learn how to automate your website testing using SpecFlow Selenium on LambdaTest.

In this topic you will be learning:

  1. How to run a sample SpecFlow Selenium script on LambdaTest Selenium Grid.
  2. How to specify which browsers to run the test on.
  3. How to run your test cases in parallel to reduce build times.
  4. How to test your locally hosted pages.
  5. How to leverage LambdaTest’s Advanced capabilities.

Prerequisites For Running SpecFlow Selenium


Inorder to run automation scripts on online grid using SpecFlow testing framework, make sure to keep following things ready:

  • Make sure you work with latest version of C#.
  • Download and Install Selenium WebDriver from the official website.
  • .Net framework to deliver guidelines while developing a range of application using C#.
  • You can download and install SpecFlow Selenium packages from the NuGet Gallery.
  • Have a project set up in Microsoft Visual Studio.
  • Visit the Library Package Manager → Manage Nuget Package for Solution → Hit Online & then Next.
  • Search for SpecFlow in the Search Packages & hit Install. Refer to their official documentation for more detail.
  • Download Selenium WebDriver Language Binding for C# and extract them to appropriate folder.
  • A .NET Core SDK of 2.1 or greater version.
  • You would also need Lambda Tunnel binary file for testing your locally hosted or privately hosted projects.

Getting Started With SpecFlow Testing Framework and LambdaTest


The first step in using the LambdaTest platform is to understand LambdaTest’s Selenium Grid capabilities. Our Selenium Grid uses remote WebDriver instead of normal Selenium client browser drivers. So if you are migrating from locally run Selenium, you would have to invoke LambdaTest Selenium remote WebDriver.

Next, you need to specify in your code, which browser, browser versions, operating systems, and resolution you wish to run your test on, along with defining LambdaTest specific capabilities. You can check out LambdaTest Capabilities Generator tool to understand more about how you can define running browser environments and leverage advanced LambdaTest capabilities.

First Test With SpecFlow Testing Framework


Let us begin with a simple Selenium Remote Webdriver test first. The C# script with SpecFlow Selenium below tests a simple to-do application with basic functionalities like mark items as done, add items in a list, calculate total pending items, etc. You can also find this at our SpecFlow GitHub repository.

Below are steps to help us execute our first test with SpecFlow testing framework:

Step 1: Download the sample SpecFlow GitHub repository and open the “SpecFlow Lambda Sample.sln“.

Step 2: The “sln” or “solution” will automatically open the project in Visual Studio. Make sure you have installed all the required dependencies that are required to run our test.

Step 3: Now we need to update the packages.config file to maintain all the required configurations. Below is the updated packages.config file code:

Step 4: Next we need to update the App.config file to update the Platform Configuration to specify the desired capabilities for browser/platform combination we want for our test. We can specify any configuration as per our need in this file and step.

In the C# code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object.

Our Capabilities Generator will automatically generate the program, based on your provided input.

For Instance, if you select the below configurations:

FIELDS
SELECTED VALUES
Operating System
Windows 10
Browser
Google Chrome
Browser Version
71.0
Resolution
1920 x 1080
Selenium Version
3.13.0

Then, LambdaTest Capabilities Generator will automatically generate the below program:

The most important capabilities to understand here are ‘browserName’, ‘versions’, and ‘platform’. They define which browser environment you wish to run the test on. Rest of the capabilities are important in test management and debugging. We have a inbuilt capabilities generator tool as well that you use to generate capabilities code for your test suite.

Below is the complete and updated code for the same.

You can also checkout our documentation on Selenium Automation Capabilities to understand more about individual capabilities.

Step 5: Next we need to update the Hooks.cs file. In this file, we will bind all the configurations mentioned in the above steps together and then call a remote Selenium WebDriver instance as per the required capability.

Below is the updated code for the same:

Step 6: Next we need to update the TodoAppSteps.cs file which contains the sample test that we will be running in SpecFlow testing framework.
Below is the updated code for the same:

Step 7: Now we have updated all the required files in our solution, which is required to run our first test. All we need to do now is to execute the test.

Inorder to execute the tests, open the Test Explorer from Test menu -> Windows -> Test Explorer in Visual Studio.

In the test explorer:

  • Select the test which you want to execute.
  • Click on second green “Run Selected Tests” button on the top left corner, to execute the selected tests.

  • You can see each test getting executed in the Test Explorer, along with their status (pass/fail).

Step 8: Now we have successfully run out first test in SpecFlow testing framework integrated with LambdaTest. Therefore, we can also see the status of our tests in our Automation Dashboard. LambdaTest Dashboard will help you view all your text logs, screenshots and video recording for your entire Selenium tests.

Below is the attached screenshot of the automation dashboard showing the test executed in the above step using Test Explorer.

Testing Locally Hosted Projects using SpecFlow Framework


With LambdaTest, you can even perform cross browser testing on your locally stored web pages with the help of Lambda Tunnel. Lambda Tunnel establishes an SSH(Secure Shell) connection from your local machine to LambdaTest cloud servers. Test your website on local and identify bugs before your customer do it for you. Lambda Tunnel also allows you to perform cross browser testing of your locally hosted web pages through various IP addresses belonging to different parts of the globe. Lambda Tunnel also helps in testing those web-apps or websites that are only permissible inside your specific corporate firewall. Wish to know more about Lambda Tunnel?

Follow our documentation on Lambda Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.

After downloading, open cmd (Command Prompt) / terminal and route the pointer to the same location where you extract the downloaded binary zip file. Then, type the below command and hit Enter to launch Lambda Tunnel.

For example, If you have the following:

Fields
Example Value
Login Email
LoremIpsum@lambdatest.com
Access Key
987zyx987

Then, the command would be:

The above command will set up Lambda Tunnel successfully! Now, for performing automation testing using C# with SpecFlow framework, you need to add the below to your capabilities.

You may also use LambdaTest Capabilities Generator for providing you with the above capability

Tunnel Reference: For a full reference of all tunnel features we support, visit our tunnel page.

Parallel Testing using SpecFlow Testing Framework


Parallel testing can be used to run multiple tests at the same time, thereby reducing the build time and increasing efficiency. In order to run a parallel test, make sure you have written more than one test in the test file. For example, in the TodoAppSteps.cs file, we have added five different tests.

So now to execute these tests in parallel, all we need to do is press the “Run All” button on the top left corner of the Test Explorer.

Below is an instance of the Test Explorer running all the tests written in TodoAppSteps.cs file in parallel:

You can also see this parallel execution in your automation dashboard, as shown below: