[VB] [Application of Testing Technology] automated Web screen testing based on interaction between VB and IE (using VB to fill in the content and submission form of controls in IE)

Source: Internet
Author: User

VB interacts with IE to automatically test web images (use VB to fill in the content and submission form of controls in IE) 

Reading this file requires the foundation of VBA programming.

During the WEB Project test, we wasted a lot of time to test the same content repeatedly input on IE. we can think about this problem. The screen test is similar to the JUnit test. You just need to click the mouse to complete the test without having to do anything. the answer is yes.

My idea is to use Excel VBA technology to set the desired value on the web page, simulate clicking a button or submitting a form, and divide it into three steps to complete the automatic test .:

Step 1: Prepare test data and predict test results... list the data and expected test results in execl.

Step 2: perform database data initialization. Clear the data of these tables and insert the above data into the corresponding table.

Step 3: test implementation. use Excel VBA technology to set the desired value on the webpage and simulate clicking a button or submitting a form.

Step 4: Compare the test results. Compare the expected data with the actual data in the database. If the values are the same, the test is successful. If the values are different, the program is faulty.

In the above four points, if you know how to use VBA for database programming, there should be no problem in the initial stage of database data and the comparison of test results. the problem lies in the test implementation. how can I enable the controls on the webpage to automatically assign values and submit forms. I will describe the possibility of implementing this technology.

HTML source code:

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">

<HTML>
<Head>
<Title> testpage </title>
</Head>

<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>
& Lt; TD width = "69%" align = "Left" & gt;
<Input name = "loginname" type = "text" id = "loginname" size = "12">
</TD>
</Tr>
<Tr>
<TD width = "31%" align = "center"> password: </TD>
& Lt; TD width = "69%" align = "Left" & gt;
<Input name = "loginpassword" type = "password" id = "loginpassword" size = "12">
</TD>
</Tr>
</Table>
<Input type = "Submit" id = "clickme" value = "Submit">
</Form>
</Body>
</Html>

 

On the simple page, there is a login form, a username input box loginname, a password input box loginpassword, and a submit button clickme.



Then open the page with IE. Note that the title of the page is set to testpage.



Open VBA and reference Microsoft Internet controls in the project:

 

Private sub commandementclick ()
Dim ielist as new shellwindows
Dim Browser
Dim Doc

On Error resume next

'Traverse the current local browser window
For each browser in ielist
'Locate the required ie window
If browser. Document. Title = "testpage" then
'Get the file objects in the browser.
Set Doc = browser. Document

'Fill In the username 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
Next
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.