Creating selenium tests in VS 2019

Rajiv Kumar 21 Reputation points
2020-09-22T14:52:35.273+00:00

Hi, can you guide how can I create selenium based test projects in visual studio 2019. Right now when I create a project and try to add latest selenium package to it through nuget, it gives error stating that selenium is not compatible with .net core 3.1. How can I create a .net 4.5 based project as selenium needs that framework?

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
336 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 28,951 Reputation points Microsoft Vendor
    2020-09-23T04:02:26.067+00:00

    Hello Rajiv,

    Which kind of project did you use? And which version of selenium package did you install?

    On my side, I tested with Microsoft Unit Test Project. After creating a “MSTest Test Project(.NET Core)” which was based on .NET Core 3.1, I installed the Selenium.WebDriver NuGet package(version: 4.0.0-alpha05 or Latest stable 3.141.0) and it installed successfully and worked well. I also tried with a “Unit Test Project (.NET Framework)” which was based on .NET Framework 4.5, the Selenium.WebDriver NuGet package also installed and worked well.

    To create selenium based test projects in Visual Studio 2019, please launch VS 2019 > create a new project for example Unit Test Project > right-click your project > Manage NuGet Packages… > install related NuGet packages for example “Selenium.WebDriver” package.

    Here are some details:

    1. If you want to use selenium in Visual Studio 2019, you just need to download and install selenium NuGet packages. You can download them by right-clicking the project > Manage NuGet Packages… > Browse > select and install (note to choose the proper versions).
    2. If you need to use project based on .NET Core, please remember to install corresponding .NET Core SDK from here: Download .NET, and the “.NET Core cross-platform development” workload from VS Installer. If you need to use project based on .NET Framework 4.5, you should check if .NET Framework 4.5 has been installed on your machine.

    To create a .NET 4.5 based project, you can change the version of .NET Framework on the “Configure your new project” page when you click File > New > Project… > Framework. If you have created a project, you can also change the version of .NET Framework by right-clicking your project > Properties > Application > select .NET Framework 4.5 under Target framework.

    For your issue(selenium is not compatible with .net core 3.1), could you share some screenshots which include error message and some detailed reproduced steps with me for further check?

    • Update1:

    Please also try to follow steps below to clear cache of NuGet.

    1. From Tools > Options > NuGet Package Manager > General > click “Clear All NuGet Cache(s)”.
    2. Download the recommended latest nuget.exe from https://www.nuget.org/downloads > add the folder where you placed nuget.exe to your PATH environment variable > start “CMD” > type “cd XXXX\XXXX” to this folder > type “nuget .exe locals all -clear” > Enter.

    Also follow these steps to troubleshoot.

    1. Delete the bin, obj and the hidden .vs folder.
    2. Try to update VS to the latest version from VS Installer.

    Sincerely,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rajiv Kumar 21 Reputation points
    2020-09-23T12:56:36+00:00

    Hi Tianyu,

    I followed the steps mentioned by you in your answer and create a “MSTest Test Project(.NET Core)” which was based on .NET Core 3.1

    Am getting the following error when I try to install selenium through Nuget

    27191-vs-screenshot1.png


  2. Rajiv Kumar 21 Reputation points
    2020-09-24T08:47:38.48+00:00

    Hi Tianyu, as suggested I cleared the NuGet cache and now am able to download selenium packages into my project. I tested with 2 Console projects ,one based in .net Core 3.1 and other on .net 4.5 .

    I have recently installed and updated VS2019. Hence I think I don't need to follow the following steps

    Download the recommended latest nuget.exe from https://www.nuget.org/downloads > add the folder where you placed nuget.exe to your PATH environment variable > start “CMD” > type “cd XXXX\XXXX” to this folder > type “nuget .exe locals all -clear” > Enter.
    Also follow these steps to troubleshoot.
    Delete the bin, obj and the hidden .vs folder.
    Try to update VS to the latest version from VS Installer.

    Also can you please explain why the problem with NuGet happened and what steps do I need to take to prevent it from occurring again.

    This NuGet issue certainly took a lot of my time. Hence I wholeheartedly thank you for your very useful help and guidance.

    Regards,
    Rajiv