Transferred from: http://blog.csdn.net/tulituqi/article/details/21888059
Selenium2library is basically sufficient when we actually test the Web page, but there will be some cases that will be out of selenium2library control and cannot be manipulated. For example, when downloading files, to choose where to save the file, such as uploading files, to choose which file to upload, these in the selenium2library is not a good way to deal with. But the combination of the autoitlibrary, it can be very good to deal with. Combined with the content of Autoitlibrary 2, the previous article describes the Autoitlibrary installation use and dialog box processing, the introduction of this article upload download.
Two specific demos and testcase I packed together, please download here, http://download.csdn.net/detail/tulituqi/7570453
Download unzip directly with ride open the inside tests see Code or run a case.
1. Test upload
A, standard control upload.
For example, the following upload control, if it is manual operation, with the mouse click Browse to select the file.
In selenium2library there is a keyword for handling this control, and that is choose File.
The case script is as follows:
With this keyword, the file path will be downloaded directly to the previous text box.
I am just an example, normal should have an additional upload button to click on the real upload (the following are the same).
B, non-standard control upload.
For example, the following is only one button, csdn blog upload pictures of the Select File button is also this.
Only click the button in the pop-up box to select the file, this time you can use the autoitlibrary.
Because my Demo page This button example is found on the Internet, in the specific implementation of the Click button to find how can not pop up to choose File box, helpless under my stupid way to achieve click button, code more, but there is effect.
PS: This method can also be useful for clicking on the Flash button.
Say the idea of clicking the button:
1) Get the coordinates of the object first by Selenium2library
2) then get the coordinates of IE page by autoitlibrary
3) Then get the real coordinates of IE window by autoitlibrary
4) Calculate the actual coordinates of the button to be clicked
5) Click the left mouse button of the specified coordinates by autoitlibrary
The script for this idea is from line 3rd to line 16th, such as
After you have selected the box to load the file, you can do it in 17 rows to 21 rows. The previous article does not handle the text box can look at the 19th line here.
2. Test download
Click on the page to download the test, will pop up such a file download prompt box, presumably we also often encounter (). Let's start by looking at how the manual operation is done.
A, click on the page to download the test link, pop up the following page click Save
b, click Save to pop up the Save As box, you can select the directory, or enter a path in the file name to save.
Because I'm doing a fixed path, each download is a file of the same name to the demo directory, so there will be a confirmation of the file with the same name.
If you do not want this, you have to find a way to save the file name of each time a different file, otherwise it is necessary to consider the processing of this process.
C, save the file with the same name as the confirmation Save as processing
All right, here's the case script for the specific implementation.
Where A's script is lines 3rd through 7th, B's script is 9th line to 12th Line, C's script is 14th line to 16th line.
A lot of sleep in the middle of the wait, it is autoitlibrary script execution is too fast, in order to ensure the success rate of the demo, I temporarily added, we can try other programs do not sleep, as the practice of this article.
Well, this two introduction selenium2library combined Autoitlibrary article is finished, autoitlibrary there are many other keywords, we can use their own according to needs, I do not specifically introduced.
The autoitlibrary itself can be used as a program Automation test for the C/s architecture, as is the case with the official calculator. Except that he only applies to standard Win32 controls, and non-standard Win32 controls are generally not suitable for autoitlibrary. How to know whether the standard Win32 control, use Au3Info.exe to identify the object, as long as the control below the class appears is normal English name can be recognized, such as Edit/button.
Last wrote the article after a long time to write new content, so that everyone wait, and later try to ensure that the introduction of new content quickly.
Next notice, probably will be the introduction of the use of databaselibrary, please look forward to ~
Robot framework--13 rfs+autoitlibrary test Web upload download