Setting up Selenium in Visual Studio for Automated UI Testing

How Can We Help?

Setting up Selenium in Visual Studio for Automated UI Testing

< Back

Introduction to Selenium

Selenium is a browser automation tool, useful for several tasks, including automating your UI Tests. It can automate a number of browsers and run on Windows, MacOS and Linux, but for this document we’ll be focusing on setting it up in Windows and automating Chrome. You can find more information at their website here: https://selenium.dev/

Creating the Project

You can set up Selenium either as a new Solution or add it as a Project to an existing Solution. Adding it as a Project to an existing Solution is useful when you want your tests to run in your Azure pipeline, but if you don’t need it to, creating it as a stand-alone Solution works just as well. Either way, you’ll want to set up as a NUnit Test Project (.NET Core)

 

 

Getting NuGet packages

You’ll need a couple of NuGet packages to run Selenium. Go to your project’s NuGet Package manager and install the latest stable versions of:

  • Selenium.RC
  • Selenium.Support
  • Selenium.WebDriver
  • Selenium.WebDriverBackedSelenium

The NUnit packages should already be installed, but if not, also grab:

  • NUnit
  • NUnit3Test Adapter

Your installed packages should look like this once you’re done:

 

 

Grabbing WebDrivers

To get Selenium to run a browser, you will need the WebDriver for that browser. For Chrome, you will need the specific WebDriver for your version of Chrome. You can find which version of Chrome you have by opening Chrome and going to Settings > Help> About Chrome

 

 

You can then find the version of WebDriver that you need from Chrome’s (https://sites.google.com/a/chromium.org/chromedriver/downloads).

Once you have the correct WebDriver, add it to your Selenium Project and set its Build Action to Content and Copy to Output Directory as Copy if Newer

 

 

You’re now ready to start making your UI Tests! You can either write them yourself, or use the Selenium IDE to quickly record your tests and export straight to useable code. There is a KB article called [Using Selenium IDE to create UI Tests] (using-selenium-IDE-to-create-UI-tests) if you’d like to use that, however if you’re making complex tests it’s best to write them yourself.

 

Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X