In this post, I am going to explain you how to automate the testing of web application using the selenium.
There are 2 ways of doing this.
- Use Selenium IDE plugin. Only available in Mozilla.
- Write the custom test cases using selenium
Let me explain you both the options in detail.
Custom Test Case Writing using Selenium
Selenium IDE
The plugin is available on Mozilla. You can add it and start recording the test cases. It is very simple and easy to understand.
- Type in the website URL for which you are recording the test cases.
- Click on the RED button on top right of the screen.
- Perform the test action on the site. In the background, selenium IDE will record your test and when you complete the test cases, click on the RED button again to stop recording.
- You can test the test case by clicking on the “Play” button and you have the leverage to slow and fast the execution of the test case.
Custom Test Case Writing using Selenium
To write the custom test cases using selenium, you need to build the environment on your machine by installing few dll’s. Details of each dll is provided as below
- Selenium Web Driver
- Download the browser driver. Use http://www.seleniumhq.org/download/ URL to get the right driver.
Let’s get started
In this example, I am going to use the internet explorer browser to test the test cases. I have downloaded the “IEDriverServer.exe” driver from selenium site and placed on my desktop.
- Add new unit test project in Microsoft Visual Studio 2013.
- Add “Selenium WebDriver” using NuGet package.
- In your unit test class, add the following namespaces
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
4. Declare a webdriver variable and create the object.
static IWebDriver driverIE;
[TestInitialize]
public void Initilization()
{
driverIE = new InternetExplorerDriver(@"C:\Users\UserName\Desktop");
}
5. Write your first test case. Here I am writing the test case for the login
[TestMethod]
public void TestMethodIELogin()
{
driverIE.Url = "http://localhost:8181/web pages/login.aspx";
driverIE.FindElement(By.Id("txtUserName")).SendKeys("UserName");
driverIE.FindElement(By.Id("txtPwd")).SendKeys("test123");
driverIE.FindElement(By.Id("btnLogin")).SendKeys(Keys.Enter);
}
6. Run the test case by pressing the Ctrl+R+T or you can just right click on any test case and select “Run Tests”
No comments:
Post a Comment