Selenium using C# by Yogesh Kumar
- 2. Setting up the project - Step1
Download and Install Visual Studio
- 3. .
Selenium is an open source suite that is used for web applications test
automation.
It allows recording or scripting automated test flows.
It uses a test domain-specific language Selenese.
Tests can be written in a number of popular programming languages,
including C#, Java, PHP, Python, Ruby, Groovy and Scala.
Automation is supported for multiple web browsers as well multiple
platforms.
What is Selenium?
- 4.
Selenium WebDriver is used for creation of robust, browser-based
regression automation suites.
Tests can be run in different browsers.
Selenium WebDriver, simply, accepts programmedcommands, sends
them to a browser and interacts with the HTML elements on the page.
Before driver can interact with the element, it need to be located (find) in
the page.
TheWebDriver’s method findElement() is used for that purpose.
Selenium Web Driver
- 5. The driver can find elements on the web page using several types of
locators:
• By Id
• By Class Name
• By Tag Name
• By Name
• By Link Text
• By CSS
• By Xpath
These locators will search the web page’s HTML and find particular
element(s) based on the supplied Id, XPath, ClassName etc.
After driver, finds element, it is returned as WebElement object.
WebElement objects, expose methods that simulate “human” interaction
with the page. Methods that often used are: click(), sendKeys(), submit(),
getText(), etc.
Locators in Selenium Web Driver
- 6. Why Selenium with C#
NO Major difference between Selenium C# with Java, It’s just the
language difference along with some changes here and there to
support new firefox browser or chrome etc in both of these
languages.
Ease of setting up scripting or running environment
Easy to generate reports with ReportNG.
Easy to start with Nunit.
- 7. Note: In this tutorial we will build an example for Smoke Test on LinkedIn web
application. The scenario
will cover user log in, navigation to the edit profile page, elements validation on
the profile page and log
out.
BUILD SELENIUM TESTS USING
NUNIT FRAMEWORK
- 8. Setting up the project - Step1
Download and Install Visual Studio
- 9. Setting up the project – Step 2
open Visual Studio and create new project
- 10. Setting up the project – Step 3
Select Test and create Unit Test project
- 11. Setting up the project – Step 4
Project will be created like attached screen.
- 12. Setting up the project – Step 5
Now Build the solution, it will create test case
- 13. Setting up the project – Step 6
Go to NuGet Packages to add selenium
- 14. Setting up the project – Step 7
Now, install Selenium Support to add Selenium
- 16. Write Test Script - Step 1
Write this small code:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
IWebDriver driver;
[TestMethod]
public void TestMethod1()
{
- 17. Write Test Script - Step 1
driver = new ChromeDriver();
driver.Url = "http://www.google.co.in";
}
}
}
- 20. Running the Test – Step 3
It will open Browser.
In browser, google website will be openend up.
Simple and easy
- 21. Playing with the Code
Find Element.
Perform operation on Element.
Run the test.