0

Verifying that the Text from a DataSource Exists in a WebTest Response VSTS

Posted by admin on Jul 5, 2010 in code, productivity, Testing, tips, tools, VSTS
Visual Studio VSTS Logo

Visual Studio Webtest Logo

I use Visual Studio Team Testers Edition everyday at work and one of the things that seemed really strange to me was that Microsoft had missed so many tricks when they decided to release it.

Maybe they just decided to build in reasons for users to upgrade,  knowing that there will always be another version of VSTS around the corner.

One of the things which is sorely missing is the ability to verify HTML source code against a datasource. Sure you can load a data source and then verify what is returned on the page when that row of the data-source is called however there is no functionality to check that the value of the row that you have submitted is returned somewhere in the HTML source (known as the response in VSTS).

So as per usual when you need something doing then, do it yourself, and hence I wrote a small piece of code that looks at the source code and then checks the value of the datasource row to make sure that the item you are submitting is returned in the HTML response.

All the data is dynamic from your source so you can’t just hard code validation rules, as there could be thousands of rows.

For an example take a Google search test. Imagine I want to check that my datasource of 10,000 records is retuned on every response.

So if I search for “System Testers” as a parameter value

“Parameter Name = q” and

“Parameter Value = Google DataSource.Directory_03062010#csv.SearchParams”

In the above QueryString Parameter you can see

the Datasource is called  “Google DataSource”

the Actual FileName is “Directory_03062010″ (and it’s a CSV file)

the Column name is SearchParams

I’ve commented my code to make it easier to understand however if you need any help just ask.

Code Below.

‘———————————————————————
‘Author  = Martin Hall
‘Purpose = To load text from a DataSource and then to compare that text
‘           against the source code on the page your testing.
‘Date = 07th June 2010
‘———————————————————————

Imports System
Imports System.ComponentModel
Imports Microsoft.VisualStudio.TestTools.WebTesting

Namespace RegressionSampleWebTestRules
Public Class RegressionAllHeadingLocationsRule
Inherits Microsoft.VisualStudio.TestTools.WebTesting.ValidationRule

‘———————————————————————
‘ Specify a name for use in the user interface.
‘ The user sees this name in the Add Validation dialog box.
‘———————————————————————
Public Overrides ReadOnly Property RuleName() As String
Get
Return “RegressionAllHeadingLocationsRule”
End Get
End Property
‘———————————————————————
‘ Specify a description for use in the user interface.
‘ The user sees this description in the Add Validation dialog box.
‘———————————————————————
Public Overrides ReadOnly Property RuleDescription() As String
Get
Return “This should Compare text from a datasource parameter in a CSV file against the page sourcecode.”
End Get
End Property

‘ The name of the expected string
Private ExpectedStringValue As String

Public Property ExpectedString() As String
Get
Return ExpectedStringValue
End Get
Set(ByVal value As String)
ExpectedStringValue = value
End Set
End Property

‘———————————————————————
‘ Validate is called with the test case Context and the request context.
‘ These allow the rule to examine both the request and the response.
‘———————————————————————
Public Overrides Sub Validate(ByVal sender As Object, ByVal e As ValidationEventArgs)
Try

Dim result2 As String
‘———————————————————————
‘we only want request2 to match the source code on the returned web page.
‘the SourceCode could be different on the other pages.
‘———————————————————————
result2 = (e.WebTest.Context(“Google DataSource.Directory_03062010#csv.SearchParams”).ToString())

‘———————————————————————
‘This should check the response for text
‘The text in question is the ParamValue we are supplying as new fake
‘parameter name and value
‘———————————————————————

If e.Response.BodyString.ToLower.Contains(result2) = False Then
e.IsValid = False
e.Message = (“fail – - “) & result2
End If

If e.Response.BodyString.ToLower.Contains(result2) Then
e.IsValid = True
e.Message = (“pass – - “) & result2
End If

Catch ex As Exception
End Try
End Sub

End Class

End Namespace

/End Code.

The above script is in Visual Basic.Net and it should work for you and if you need any help in how to install and run it then either send an email or reply in the comments.

One last thing to mention is that the values from the data source are loaded in a fake Parameter Name (Just make one up) which will be ignored by the Website however it will show as a Context Name in the Visual Studio Web Test, so we are really just comparing two Context Names

Good Luck

Martin H

 
0

TaDa Lists (Easy to Use ToDo Lists to make you more productive)

Posted by admin on Jul 14, 2009 in productivity, tools
To Do lists

To Do lists

I’ve been using TADA lists for about 3 months now and I love them. They just do exactly what you would expect.

You set up a list and you can move the priorities around depending on how your plans throughout the day change.

I have lists created for

In Test

In Staging

In Planning (soon to be handed to test)

Handed Back to Developement for defect correction.

Let me make clear that this is not meant to replace any defect management system you may have in place. Its far to basic for that.

However if like me your daily priorities are constantly changing and you need to maybe make other team members aware of what things are being worked on in which environments then I have found this as a quick and easy fix.

It can of course be used for many other things like shopping lists. I’ve taken my mobile phone shopping before and when my wife gets home she jumps on the PC and just updates my TADAlist with any items that she needs that I may have missed off.

I then get an email on my mobile phone and bingo I now have an updated list to walk around the shop with. Yes she could ring me but I’d have to write it down. I just find this just easier.

Maybe on that note in the future I should make a post about the perils of using technology just because its there.

Anyway enough of the digressing I hope you find the tool as useful as I and the people I work with have.

Martin H

 
2

Bookmarklets for a Web-Tester

Posted by admin on Feb 12, 2009 in code, productivity, Testing, tools
Code

Code

In this post I want to give people a nice heads up to some of the tools I use in my daily role.

These are bookmarklets which is just another word for bookmarks which contain javascript.

I use these with firefox although IE and Opera should also fine fine for them also. In Firefox just add them to the bookmark toolbar and you’ll have them at your fingertips.

Zap Cookies! This will clear out any stored cookies for the current page/site

Edit Cookies! This will allow you to edit and stored cookies for the current page/site

View Cookies! This does exactly what it states, it allows you to view and stored cookies for the current page/site

Edit Page

Allows you to edit any page you use this on. All changes are temporary of course and only visible to you.  (will you ever trust a web page screen shot again?). Not yet sure how this fits into the testing arena, however I though I would include it as someone may make decent use out of it.

Find Redirects! This should list any redirects for the current page, however its currently a tiny bit hit and miss and is does not work 100% of the time, it should however suffice for now and I’ll most likely have to rewrite this at some point in the near future.

remove redirects Lets see what happens if we now remove those redirects we just found using the above Bookmarklet.

Wikipedia lookup This allows you to select any text on a page and once clicked it will lookup that text on Wikipedia

Yahoo site search This allows you to select any text on a page and once clicked it will search on Yahoo for more links from that domain with the same text.

Alexa This will carry out a search at Alexa for the domain you were on when you clicked this bookmarklet.

MSN IP Search Firstly I should thank Robert Hansen (RSnake) for this one. Once clicked it will carry out an IP search which can help you detect a wider network for your testing.

numbered list One of my favourites this one. It allows you to make a nice numbered list of all parameters on the page which contain numbers.

show hiddens This and Zap Cookies are my most used Bookmarklets. this one will display all hidden fields on a webpage and also allow you to edit them.

remove maxlength This will remove all the max lenghts from all input fields (think buffer overflows and code boundary issues)

undisable Who says you can’t click that button :-) . This Bookmarklet will enable any disabled objects on the page.

up This will take you up one directory level in the site structure

top This will take you to the top of the domain.

decrement If your URL ends in a number it will reduce it by one every click

increment As above but the opposite

check images This will check the current page for broken images.

view variables This will list all variable types found on the page. This is more for Developers than testers however its still a useful one to have.

view scripts Like above however it will list all scripts what can be called on the current page.

zap images This should clear all of the images from the page. Works about 98% of the time. This script may need a little tweaking if I ever get the time.

full urls as link text Very useful if you want to see where a link is pointing to.

Enjoy

Martin H

Tags: , , ,

Copyright © 2012 The Test Manager Blog All rights reserved. Theme by Laptop Geek.