Setting Up Visual Studio Environment for Selenium

Preconditions

  • Visual Studio (VS) has been installed.
    A successful installation of VS 2017 needs to contain the following workloads:
    Universal Windows Platform development
    .Net desktop development
    ASP.Net and web development
    .Net Core cross-platform development
  • Ensure the following folder structure exists on you main OS drive.  In INDOT's case this is the C: driver.
    Selenium_Testing\Projects
    Our current standard is to then provide the project or sub-project name, then "Branches", then the current release and the normal VS solution structure.  So in the case of Lab Buddy the structure is the following:
    \Selenium_Testing\Projects\FieldAssistant_LabBuddy\Branches\Release4

Create Project

Once a successful Visual Studio (VS) installation has occurred, you will want to create an new VS 
1) Select File -> New -> then Project...

2)The "New Project" dialog window is displayed.  Setup a C# Console App (.Net Framework) and Name it something like "projectName_QATesting". In the case of Lab Buddy, I used "LabBuddyAutomatedTesting".

3) Make sure you save all of this work.

Install or Upgrade Firefox

Now you will need to update or get the latest Firefox browser.
1) Open any browser other than Firefox and type in "www.firefox.com" for the URL. 
2) Once the site opens, click the green "Free Download" button.


3) Save and run the downloaded file to install or upgrade Firefox.
4) Once Firefox is installed successfully, make sure the Firefox version is 53 or higher.  Select the 3 horizontal bars in the upper right-hand corner of the Firefox browser, then click the question mark and select "About Firefox".  This will display the about dialog box with the version.

Install Selenium Dlls

Turning back to the Visual Studio environment, now install the needed Selenium dlls.
1) From the "Solution Explorer" select the starting or main project, right mouse click the selected project and select "Manage NuGet Packages...".

2) The NuGet manager will appear, select "Browse" and enter "selenium" in the search area and select enter.  You will see, several Selenium packages but only select the Selenium.WebDriver, Selenium.Support, Selenium.Chrome.WebDriver, Selenium.Firefox.WebDriver, Selenium.WebDriver.IEDriver and click "Install" for each one.

3) You will be prompted with a preview of the needed changes, select "OK".

4) From the "Output" window, make sure you see the "Successfully installed each package.  For example, the 'Selenium.WebDriver 3.8.0' to projectName" in this output for a successful installation.

Download and Place Gecko Driver

1) Open up a browser and go to "https://github.com/mozilla/geckodriver/releases". Download the  current Windows 32 gecko driver, to your PC.

2) Using Windows Explorer, move the downloaded file to the packages folder for this project solution.  

3) Open the .zip file and COPY the "geckoDriver.exe to the "Debug" folder under your project. In the example I have been using the location is:

Simple Test Case

1) Ensure Selenium was install in the correct project by selecting the project within the Solution Explorer, opening References and make sure WebDriver is within References.

2) Now open the "Program.cs" for editing and the completed should look like the image below.
3) Add the using references by adding OpenQA.Selenium and OpenQA.Selenium.Firefox; to the bottom of the using references.
4) Add the diver code to Main as show below.
5) Make sure you save your work.

Run Test

1) Now click "Start" from the button bar and run the test.  It may take a while to instantiate the web driver and  gecko driver so please be patient.  The web driver will open a gecko command window open that looks like the following:

2) Then wait a bit for the gecko driver to open a Firefox window.


Comments

Popular posts from this blog

Debug VBScript / VBS files in Visual Studio 2010

A good use of Common Table Expressions