Friday 1 June 2007

Get random test data into Clipboard

OK,

Then we know how to get random data from SQL Server. Would be nice to build a public web page around this where testers easily can get test data for immidiate pasting into the AUT.

Something like this maybe:

1. Specify data to get and from which test environment
2. Click on a button and display the test data and put automaticly in clipboard
3. Paste into the AUT

Solution:
Create a web form and include

vbscript


Sub GetTestData
'Set test environment and test data
strTestEnvironment = formname.TestEnvironment.Value'Form reference not used in this example
intTestDataIndex = formname.RandomTestData.SelectedIndex

If intTestDataIndex = 0 Then
strSQL = "SELECT top 1 testdata1 FROM table where testdatatype1 is not NULL ORDER BY NEWID()"
ElseIf intTestDataIndex = 1 Then
strSQL = "SELECT top 1 testdata2 FROM table where testdatatype2 is not NULL ORDER BY NEWID()"
End If
'****** Initialization ******

'Set test environment parameters
strDataBase = "DRIVER=SQL Server; DATABASE=[databasename];APP=[testtool];SERVER=[servername];Description=Testconnection"
'****** Data base call ******
Dim objDB

Set objDB = CreateObject("ADODB.Connection")
objDB.Open(strDataBase)
Set objRecordSet = objDB.Execute(strSQL)
Dim strResult
If objRecordSet.BOF = True And objRecordSet.EOF = True Then
strTestData = ""
Else
strResult = objRecordSet.GetString
strTestData = Left((Trim(strResult)),Len(Trim(strResult))-1)'Format data
End If
objDB.Close
Set objDB = Nothing
formname.TestData.Value = strTestData
End Sub


and finally

JavaScript


function copytestdata(input) {
GetTestData();
window.clipboardData.setData('Text',input.value);
}

Start the sequence by using the tag

INPUT TYPE="button" NAME="cmdGetTestData" VALUE="GetTestData" onclick="copytestdata(formname.TestData)"

Done!

No comments: