Forum Discussion
- frank_vanderstrContributor
If I am understanding your question correctly you want to make sure that the data displayed in your web fields matches the database entry that's associated with that field.
If that's the case, one way to do that is to do a compare between the data found on your web page, and the data in your database.
Here's come C# pseudo to help demonstrate what you might be trying to do.
here we have the web object that is mapped in testcomplete and we set a variable to its displayed information.
var webfield = Aliases.MappedWebField;
var webfieldval = webfield.innerText;
Now here is the more tricky part, I just figured out recently how to connect and work with databases. The connection string is what was stopping me for a while, but I figured out how to use TestComplete's Stores object to get a connection string it would accept.
The ADO object has worked best for me and my purposes so far.
Qry = ADO.CreateADOCommand();
Qry["ConnectionString"] = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DatbaseName;Data Source=DatabaseServerName"
After this you can run SQL statements to interact with your database.
Qry["CommandText"] = "SELECT webfieldvalue FROM WebValues WHERE WebValues.fieldid = 3";
Qry.CommandType = cmdText;
var exec = Qry["Execute"]();
var dbval = exec.Fields.Item("webfieldvalue").Value;From here you just do a comparison of dbval and webfieldval to see if they're identical.
I hope this helps, and if there's anything that's unclear feel free to ask.
- Colin_McCraeCommunity Hero
"From here you just do a comparison of dbval and webfieldval to see if they're identical."
Possibly a slight over-simplification.
The website may be doing some parsing and re-formatting of values. For instance, a bit field in a SQL DB will look like a Bool when viewed through the management studio, but the ADO object returns a -1, not a 1, for these fields when you query it with script. And it will probably be used to trigger something onscreen as a bit value is not something you really display.
Date/time fields may be reformatted. etc etc.
As a rough guide, yes. But you need to be careful with the data type and format. It's not always as simple as a straight compare.
(I discovered this from doing EXACTLY this type of testing!)
Related Content
- 5 years ago
- 2 years ago
- 13 years ago
- 5 years ago
Recent Discussions
- 22 hours ago
- 2 days ago