VB and IE Interactive implementation of Web screen automatic test (with VB fill in the content of the control in IE and submit the form)
This document needs to have VBA programming Foundation.
When we were doing Web project testing, we wasted a lot of time trying to test a point to enter the same content repeatedly on IE. we can think of a problem where the screen test can be as good as a JUnit test. Just click on the mouse and do nothing to complete the test. The answer is yes.
My idea is: Use Excel VBA technology to set the value you want to set to the Web page and simulate clicking on a button or submitting a form, divided into three steps to complete the automated test.:
The first step, test data preparation and test results are expected. List the data required for testing and test results in EXECL
In the second step, the database data is initially initialized. Empty the data from these tables and insert the above data into the appropriate table
The third step, test implementation. Use Excel VBA technology to set the value you want to set to a Web page and simulate clicking on a button or submitting a form
The fourth step, compare the test results. Comparing the expected data with the actual data in the database, the same words indicate that there is no problem. The same indicates that the test passed, and the difference is that there is a problem with the program.
In the above four points, if you know how to use VBA for database programming, then the database data initially and test results should be no problem. The problem is in the test implementation. How to automatically assign and submit a form to a control on a Web page. I will explain the possibilities of this technology implementation.
HTML Source: <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
< HTML >
< head >
< title > Testpage </title >
< BODY >
< FORM name =chh method = "POST" action = "Login.asp" >
< table width = "100%" border = "0" cellspacing = "0" cellpadding = "2" >
< tr >
< td width = "31%" align = "center" > User: </td >
< td width = "69%" align = "left" >
< input name = "LoginName" type = "text" id = "LoginName" size = "All" >
</td >
</TR >
< tr >
< td width = "31%" align = "center" > Password: </td >
< td width = "69%" align = "left" >
< input name = "Loginpassword" type = "password" id = "Loginpassword" size = "All" >
</td >
</TR >
</table >
< input type = "Submit" id = "ClickMe" value = "Commit" >
</FORM >
</Body >
</HTML >
Very simple page, on which there is a login form, a user name input box loginname, a password input box Loginpassword and a Submit button ClickMe
Then use IE to open this page, note that the title of the page is set to Testpage.
Then open VBA and reference Microsoft Internet controls in your project:
Private Sub Command1_Click ()
Dim Ielist as New shellwindows
Dim Browser
Dim Doc
On Error Resume Next
' Traverse the current browser window
For each browser in Ielist
' Find the IE window that needs to
If Browser. Document.title = "Testpage" Then
' Get browser to document object
Set Doc = browser. Document
' Fill in the User Name field
Doc.body.All ("LoginName"). Value = "Eddie"
' Fill in the password field
Doc.body.All ("Loginpassword"). Value = "123456"
' Submit
Doc.body.All ("ClickMe"). Click
End If