Category Archives: ASP.Net

Creating WebTest in Visual Studio Team System 2008

Creating WebTest in Visual Studio Team System 2008

We can create Test Project using Visual Studio Team System 2008 in that we can add different type of Tests like Web Test, Load test, Unit Test etc.

What is WebTest?

WebTest comprises a series of HTTPRequest. We can see the response which comes from the server and we can use different extraction rules to grab hold of any information from the referrer response that we may need to pass in to the next request. WebTest offers a kind of test with which we can capture/record the HTTP/HTTPS traffic of our website or web server which communicates on HTTP Protocol.

How to Record a WebTest?

First of all we have to create a new Test Project or add a Test Project to Existing Web Application.

clip_image001

Click New Project

clip_image003

Click OK to add the project in the solution.

clip_image004

Adding Web Test to the Test Project – Right click on the Test Project and then Add –> Web Test

clip_image005

Once we click on Web Test menu, Internet Explorer will open with additional tool (Web Test Recorder).

Enter the website address and press Go. It will start recording the test.

Start navigating the site.

clip_image006

Some entries will get added while navigating to the site. Once the navigation is over click on Stop button to stop the recording.

clip_image007

Now Web Test has been recorded. We can enhance the Test by doing parameterization, by adding validation rules etc.

Now we will Test the Web Application using different User ID and Passwords

clip_image008

Add the Data Source –> Right Click on WebTest –> Select Add Data Source

clip_image009

We have three options to set the Data Source Database, CSV File, and XML File.

We can select any Data source based on  data availability.

Here we are going to select Database.

clip_image010

Create new connection by click on New Connection button or Select the Connection from the Combo box if the Connection is already configured in the Project.

Click Next …

clip_image011

Select the login table and Click Finish.

clip_image012

Database will get added in the Test.

 

clip_image013

Here can we assign the Dynamic value(which will come from the database) to the control by selecting Properties.

Select the control (eg. txtUserName) Right Click on it –> Select Properties

 

clip_image014

In properties – Select Value –> Click on the arrow –> Expand DataSource1 –> Expand logindetail table –> select Uname column since we are binding txtUserName textbox with uname column of the database.

Same procedure to be followed for the txtPassword also.

 

clip_image015

After setting the value the fields they will look this.

 

clip_image016

Since we have configured the database to run the tests as many times as records are available in the login table. By default the test will be running once. We have to change the setting to change Number of run iterations.

To change the iterations setting we have to select the Properties of the LocalTestRun.testrunconfig file which will be available in the Solution Explorer.

 

clip_image017

Select Web Test from the List box available in the left side, Click on One run per data source row option of the Number of run iterations group box. Click Apply –> then Close.

 

clip_image018

Now we can start running the Test by click the Run Icon available in the toolbar.

 

clip_image019

In logindetail table we have total 7 records so total 7 times test has been iterated.

Run 3, Run 4, and Run 6 have failed because the logindetail table is having wrong username or password for these records.

 

clip_image020

Now we its time to generate the code for the same WebTest by right clicking on the WebTest1 –> Click on Generate Code..

 

clip_image021

Once the Generate Code is clicked WebTestCoded.cs file will get added in the Project. We can manipulate the code for enhancing the Test.

Link to Download the Code.