Contents
A basic introduction to Selenium Webdriver, asp .net technology, and the concept of web drivers. Then, will create a new project in the visual studio, add libraries to it. Add web drivers to the system, in this particular example will install chromedriver. using installed libraries and NuGet package will access the chrome via chromedriver and will test a URL on the chrome. The exact sample of it is given below in the following diagram. The steps involved in the installation process are as:
Selenium testing tool is an automation testing specifically for the web application to test the application on cross-browsers. What it means is that the feature you are developing can be tested on multiple browsers by generating scripts hence, you have automated the testing process. To be a bit more specific, you test the performance and UI/UX of the application. Now Selenium testing offers three tools: Selenium Webdriver, Selenium Grid, and Selenium IDE. Selenium Webdriver helps to test the application using drivers for browsers which means is that you write the application of the programming language of the choice, then add selenium webdriver libraries then write the script using them and test the performance on cross-browsers via browser-specific drivers. The below image makes it clearer.
Before Selenium Webdrivers, there was Selenium Remote Control where RC was a proxy server, so the browser used to send requests to the proxy server first where then the output was tested on the browser. You can just imagine the nature of complicated architecture here. But with Selenium Webdriver, the browsers were controlled at the operating system level itself using the drivers. Multiple browsers are supported by Selenium Webdriver like Chrome, Firefox, Edge, Internet Explorer, Opera, Safari, but this example will work with chromedriver.
1.Check the version of google chrome.
Help->About Google Chrome-> Check the version
2.Download the chrome driver from the chrome driver
3.Create a folder in the system and access the drivers from there
C:/WebDriver/bin
4.If you get a screen like this then the driver is just working fine.
Here we are adding dot net core 2.2 MVC project in Visual Studio 2017 followed by Selenium Webdriver NuGet package manager. You need not make an MVC project only, can definitely use your choice of web application it would be the same. Here the code also is being added to the index method only to keep the focus on logic than architecture.
using WebApplication1.Models;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ChromeOptions options = new ChromeOptions();
options.BinaryLocation="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(ChromeOptions.Capability, options);
ChromeDriver driver = new ChromeDriver("C:\\WebDriver\\bin", options);
driver.Navigate().GoToUrl(@"https://engineerdiaries.com");
} }}
On debugging, If the code launches the browser chrome and then navigate to the URL. Then you have successfully done with Selenium Webdriver installation using C#.1.Binary locations are in fact optional if your visual studio is unable to access chrome. Which was the error in our case. So, add the location of chrome.exe in your system.
2.Main code starts from chromeDriver as above we were setting options to access chrome only. The first parameter we give the path to the chromedriver which we installed in the previous step. If you debug it and reach this point and cmd opens then the driver is working just fine.
3.driver.navigate() to access the webpage or website for which you want to automate.