Qtp for automated testing

Source: Internet
Author: User

Qtp9.0 is the tool used to catch up with the automation test project progress in the past two days. This automated test project is faced with a B/S structure system, with a large number of tables to be entered on the IE page. At first, the progress was smooth. After the script was recorded, it could be played back smoothly at the beginning, and the checkpoint could work normally at 100%. I thought it was okay to check in. However, a problem was found during playback the next day, which was troublesome. The last two days were simply described as a nightmare.

The recorded script contains the following operations: 1. Click a static cell with text in the table on the IE page; 2. Copy the numeric area from the Excel Data File (the method you have written); 3. Use the sendkeys method to paste the copied content into the IE table. It was very smooth during script recording, but when the script was opened the next day, it was found that the script could not be played back. When the sendkeys method is used, the script cannot paste the data to the IE interface. The most surprising thing is that the performance of each failure is different. Sometimes, the system prompts "the page entry value is invalid ", it is determined that this is caused by incorrect copy area and paste area cells. Sometimes the system prompts "no data on the Clipboard". However, if the script is stopped at this time, press Ctrl + V to paste it, this indicates that the copy is valid, but an error occurred while pasting.

We can't blame the qtp for the above phenomenon alone. After all, if the test environment changes, it will affect the playback of the qtp script. However, this is depressing to me: the script is the same as the script, and the environment is the same, but after 12 hours (Shutdown From to AM ), this problem occurs in the result script.

Now that the problem has occurred, let's solve it. We can't tell the boss that qtp is not good. After all, qtp is just a tool. If the job fails, we still need to find quality reasons. Haha. First, based on the problem, it is determined that the pasting step has an error, so open the Lib library and review it row by row.CodeIn the original code, the method used to read Excel is

Set Excel =   GetObject ( " H: src1.1databudget Indicator Management .xls " )
Set Sheet = Exce .........

Think about writing this way. Although the script can run successfully at first, it is different from the writing method in the document, so it is changed to the Createobject method.

Set Excel =   Createobject ( " Excel. Application " )
Set Workbook = Excel. Workbook. Open (filename) ' Filename is the directory of the file.
Set Sheet = Workbook. worksheets (sheetname) ' Sheetname is the worksheet name in Excel.
Sheet. Activate 'activate the current Worksheet

After writing the script, save it, re-open the script, open the software, run the script, OK, and pass it, and the script can be smoothly played back, then, write your name, time, reasons for modification, and methods on the Lib function, and send the updated files to other people in the project team.

However, at this time, I still have some doubts, because from the code execution point of view, there is no essential difference between GetObject and Createobject. Even if there is, it should not affect the data pasting operation. Because the sendkeys method is used, the script for accessing Excel has been executed. For the sake of security, we still need to confirm this problem. So I re-opened the script yesterday, restored the code to the status before modification, then opened the tested system, and clicked run to run the script. I found that this script was actually passed.

I am crazy at this time! Oh, my God, why are you doing this to me! Why are the results of running the same script on the same machine and at a very short interval completely different. I am the executor of the script, but it cannot be said that it is a matter of character. Now it is estimated that other people in the project team are wondering: Why should I modify the script. However, this is not my fault. I did encounter a script running failure, and it can indeed run after modification. The ghost knows what the script is. I felt a little unwilling, so I ran the script again, OK, and pass completely.

Now I am helpless. I ran the modified script three times again to confirm that the script was correct and can pass it. I thought it was over here, but it was still better.

The third day was a Saturday. Considering that the script was recorded smoothly, I didn't go to work overtime. I used my notebook to record the script, working in the dormitory or in the company is the same. In the morning, I was too lazy to stretch out my waist, habitually open qtp, open the tested system, open the script, click run, and then casually watched the script run. I was prepared to brush my teeth, A prompt box pops up on the screen, showing that the clipboard has no data!

I collapsed. I almost didn't throw my dental cylinder out of my hand, but considering that it was my notebook, I finally got rid of my anger! It seems that something has been done again today.

After washing your face, brush your teeth and return to the computer. To see this situation, we first consider the sendkeys problem. As a function to simulate keyboard input, sendkeys is inherently unstable. Because when this function is called, if the focus changes, it will also be very idiotic to send the prepared content. However, this situation has nothing to do with the sendkeys method. Since it prompts that the clipboard has no data, it should be that excel has not been copied. So I tried to press "Ctrl + V" and found that the copy was completed, and there was data in the clipboard. Rely on me!

The subsequent things are simple: code modification, running, and failure; code modification, debugging, success, running, and failure; then modify the code, debug, successful, run, successful, re-run, successful, re-run, failed ....... Throughout the entire day, we have been constantly modifying and Running code. From half past seven am to AM, I tried all the suspicious places, visited msdn countless times, and run the code countless times. However, the success rate of running is less than 100%. The last modified script cannot be run. When running, the system prompts "no data on the Clipboard ". So I started to try the last scenario, using my laptop as a server, and moving the script runtime environment to my desktop. Open qtp on the desktop, open the script that ran the error just now, open the tested system, click Run, OK, and run full pass. For the sake of security, I had to loop this script for 100 times and kept it on the computer. When the script was running for 22 times, there was still no problem. It was completely pass!

At this time, no language on the earth can describe my mood at this time. When the Red Army crossed the lawn, it was a kind of feeling of survival and victory. After Lai Changxing fled to Canada, it was a kind of luck. After Wang Hao defeated Liu chengmin, it is a joy of fighting, paying, and enjoying the harvest. In my case, I am like a fool who seems to have been turned around by qtp. I will tell you that the script failed to run in a short time, and I will be told that the script runs smoothly in a short time. I can see that the number of loops has reached 35 and it still runs normally, I am not excited in my heart. What I want most now is the MSN or email of the qtp project team. If they have Chinese users, I would hate to call them, I want to talk to them about my two days of ups and downs. I want to ask them whether this is my own script or the design defect of qtp; I want to talk to them about the direction of qtp improvement in the future, and think about it. I don't know why I suddenly laughed, and I was very happy, but it was very slow. If there was someone next to me, he must have said that I am a neurology, a madman.

I saw my head crazy ......

 

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.