Selenium!

What is Selenium?

Selenium is a piece of software that can be used to automate web browsers, for both user interface and application testing. Selenium is widely used in the industry and has support from many companies, frameworks and other APIs.

There are 2 main parts of Selenium; Selenium WebDriver, which does exactly what it says on the tin and is used to automate browsers and finally we have the IDE which is useful for quickly creating scripts to reproduce bugs and exploratory testing via a Chrome/Firefox add on that can record and playback your browser interactions.

Languages/Platforms

Because Selenium is an open-source, web automation tool it can support a wide range of operating systems and browsers, allowing testers to use languages such as: Java, C#, Python, .NET, ruby, PHP and perl for coding tests.

Because the work we’ve done in this project so far is for use in Visual Studio with the .NET framework we will be using C# to write our tests. This allows it to be integrated with other applications using the .NET framework.

What do we need to get started?

  1. After installing Visual Studio navigate to the NuGet Package Manager under tools and search for Selenium.WebDriver(.NET bindings for the Selenium WebDriver API). Select the project you have running and install!
  2. Search again, this time for NUnit; the NUnit testing framework is supported by both VS and Selenium and is one of the most popular frameworks for .Net applications. This framework presents the results from your tests in a readable format and allows them to be easily debugged. If you have used Selenium or other Java based test frameworks then you will recognise that it functions very much like JUnit.
  3. Finally, search for and install the NUnitTestAdapter in the same way, this test adaptor is an extension for visual studio that allows your test executions to be integrated.
  4. That’s the basic setup complete! You’re now ready to create a class for your tests and get scripting.

Note: don’t forget to download the chromedriver, if you haven’t got it already it will automatically give you the url to the latest version when you try and build your project. you’ll have to put the location of your chromeDriver.exe when declaring your driver in tests.

How do we interact with the browser?

Okay so we have our basic set up but how do we actually automate a test and send commands to interact with the browser? Well, in C# we use the interface ‘IWebDriver’ for browser commands, there are 3 main types: browser commands, web element commands and drop down commands.

The names of these are fairly self explanatory but we will go over them and the test formats in more detail tomorrow (25th Jan). For now, find some simple examples below of initialising the web driver, opening a url and closing it again. Then secondly we will demonstrate identifying an element via x path on a site and interacting with it via a click command. We will then explore more complicated test solutions as well as the components they’re made of.