How to Verify Dynamic Links pointing to Live URLs in an Application – MSN

Recently I was browsing MSN India when I encountered a dead link by clicking on a story. How embarrassing!

That set me thinking that there should be a way to automate checking the URLs that are displayed on this content aggregation portal. I think the same is true for all portals that rely on external content for their functionality.

Below, I propose a mechanism to automate testing of such requirement. Some peculiarities of this web portal:

  1. The news article displayed is changed frequently (maybe every few hours)
  2. Alongwith the news article text, the URL of the article will change
  3. We need to verify that the URL is a live URL

We will be using Telerik Test Studio v 2014.1 to do this test. We can start by creating a new project in Telerik Test Studio:

Click on OK.

Right Click on the project name and create a new test of type Web Test. Call this Sports_Section_MainStory_Verification Test.

Double Click on this test to start recording this test. You should be in the “Test” section of the Ribbon. Click on Record button located at the top.


Select the browser you want to record the test in (I am using Internet Explorer):

This will launch a new IE window with automation enabled (notice the small toolbar on the top of the screen). Now type in the MSN URL: and press enter.

Click on “Enable/Disable Hover Highlighting” icon on the Test Studio toolbar. Hover over the Sport Section Main Story Headline (shown in the screenshot below):

Clicking on the blue bubble exposes the “Element Menu” from where you should select “Add to Project Elements”:

Name the element appropriately and click on Add Element:

Now close the browser. We will be working with this element in coded steps. The first step is to correct the identification logic of this element. Go back to Test Studio and highlight the element in the “Element Explorer” of Test Studio:

Right Click and select “Edit Element”. Click on “Find in Live Version” -> New Browser -> Browse and Navigate”:

This will open a new automated window in a browser. We are interested in the “Find Element” window:

Notice the suggestions pane in the left of the screen. We are going to be using HtmlPath this time. Click on HTMLPath to add it to the right section of the screen. By clicking on the one logic present in the right section, you will be able to delete the same. The screen should now look like:

Click on Save to return to the Test Studio. Now add a coded step in Test Studio using the Add menu -> Script Step:

We are going to use C# to author our scripts. Please select C# in the next window. In the bottom pane of Test Studio, you will be able to write your script. A single line of code will do:

SetExtractedValue(“MainSportsLink”, Pages.MSNIndiaNewsCricket.Sports_Section_Main_Headline.HRef);



Next we will need to add Reference to System.Net namespace. To do that go to Project menu ribbon and click on settings:

Click on Add Reference and select the System.Net.dll located here: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5

Then Click on Open, followed by OK in the Project Settings Window. Next, click on the below shown icon to view the entire code behind file in the “Code Viewer” section.

Scroll to the top of the code file, and add:

using System.Net;

Next add a new coded step and copy the following code there:

string urlloc = (string)GetExtractedValue(“MainSportsLink”);

System.Net.HttpWebRequest browurl = (System.Net.HttpWebRequest) WebRequest.Create(urlloc);

using (WebResponse response = browurl.GetResponse())


Assert.AreEqual<string>(“OK”, ((HttpWebResponse)response).StatusDescription);


Save the test and Run the test by using the Start button. The test would pass!

Congratulations, you have now automated verification of dynamic content with its associated URL using Test Studio. One can similarly author different tests for each section of the webpage and accordingly verify of the links are active.

If you want to take the next step, think about data driving the find expression of each of the elements. Interesting??


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.