From: http://blog.csdn.net/tulituqi/article/details/7592711
I. Edit
Accessing the front-end, re-opening our ride, you will find that the last resourcefile res1.txt is missing? In fact, it still exists in the Windows directory.
The main reason is that we didn't load this resource.
1. First, check the test suite. Select the test suite and check the Edit page in the workspace on the right.
The source in the first line lists the testsuite paths.
Next, there is a settings, which hides the content. Click it to display the specific setting. Next, we will introduce settings.
You can further divide it into three parts.
(1): Load External files
Add Library: load the Test Library, mainly the Test Library in the [Python Directory] \ Lib \ Site-packages
Add Resource: loads resources, mainly resource files related to your project.
Add variables: loads the variable file. This is never used. I will try again later.
(2): Define internal variables
Add scalar: defines Variables
Add list: defines list variables.
(3): Metadata Definition
Add metadata: define metadata. I directly translated the file. This is a newly added part. I probably checked that the defined content is displayed in the report and log files. The format is the same as that of document.
Add the lost resource and click Add Resource,
Enter the complete file name: res1.txt and click OK.
The blue chain-connected res1.txt is loaded successfully. If the path or file name is wrong, it is black.
When we look at the left side, we will find that our res1.txt has come out again, and the previous position is in the external resource, which is now under the project.
This is because we have a testsuite that loads resources, so they are in a project, so they will be displayed together.
2. For the project or directory testsuite, the Edit page of the workspace is basically the same as the file-type testsuite. The difference is only in settings.
In fact, the workspace editing of resources is not much different from that of testsuite, that is, the workspace editing without metadata is available in the other two parts.
3. For testcase and user keyword, the workspace editing page on the right is basically the same, and the difference is only in settings.
Testcase
User keyword
We can see that this area is the same as that of an Excel table. This is where we mainly write scripts.
4. Before writing a script, we need to load the Test Library. The test library can be added anywhere, because the initialization setting of selenium2lib is global, in this way, the operation will take effect globally.
[Python]View plaincopyprint?
- Robot_library_scope = 'global'
So, for this project, we can add both the test kit and res1.txt. If only one script is added, the script written under the one without the Test Library is black. If the keyword is not found, the script will still work during running.
Add the test suite first, click test suite, and click Add library in his workspace,
Enter selenium2library and click OK.
The loading is not successful yet. The success mark is to press F5 to bring up the search keywords interface.
Click the drop-down list after the source, and the selenium2library is displayed in the list. If the loading is not successful according to the above method, check your version number. At least we recommend that you start from 0.5.2 when writing this article.
Now you can write the script. First, write an open browser and run it.
Is the color of open browser different? Earlier versions of ride were blue. Now he distinguishes different keywords and can customize colors. Now this is the keyword color of the default Test Library.
5. Run it.
OK. The operation is successful and the webpage is opened. The run page of ride also displays the running process and result.
Careful friends will notice that there are several question marks in the middle. Here we should display four characters in the Chinese test suite. However, because the default RF encoding does not support Chinese, we need to modify the encoding.
=== Rf2.6 ===-- take the content from the previous introduction.
• Encoding in [pythondir] \ Lib \ Site-packages \ robot \ utils. in The py file, right-click the file and choose edit with idle to open the file. Find def _ get_output_encoding (): the original encoding is 'cp437' and changed it to 'cp936' (Simplified Chinese, GBK ).
=== Rf2.7 ===
If you upgrade to 2.7 like me, the path is still under [pythondir] \ Lib \ Site-packages \ robot \ utils,
However, you cannot find this content in encoding. py because they have updated it. Where did I go? The name is encodingsniffer. py.
Right-click the file and select Edit with idle to open the file. Just change cp437 to cp936 and save it.
After the update, execute the script again.
This operation is normal.
Ii. Settings
This section mainly describes the settings in the workspace. Some common settings can help us better plan the running of cases.
1. prj or directory-type testsuite
======================================
Edit settings: you can click the text box or edit
Clear settings: Click Clear
======================================
Documentation: A document. Each item has a document. You can add instructions to the current object.
You can also set a simple format here. The text in the middle of two "*" will be bold, the text in the middle of the two "_" will be set to italic, And the URL will be converted to clickable links.
[Plain]View plaincopyprint?
- * Bold * _ italic _
- Http://www.baidu.com
For example, if the above content is written, it will be displayed as follows:
The following setup and teardown indicate start and stop respectively, that is, you can set a keyword in the corresponding text box, then the specified event will be executed when triggered.
For example, Suite setup indicates that a keyword is executed when the test suite is started. Test teardown refers to executing a keyword at the end of the case.
To demonstrate how to set a keyword, as shown above, I have set sleep | 5sec in Suite setup, which means waiting for 5 seconds. Note that the keyword parameters should be separated by |, if you want to use | instead of letting it separate parameters, use \ |.
The others are the same. Here we will not give an example one by one.
Force tags: In the end, we will talk about this forced tag. This is a good setting. It should also be added recently. It can help us easily set up tags in batches. What is the use of tags? You can select the tag case to run later. After force tags is set here, he will forcibly add these tags to all its child elements. First, set the previous tag and name the prj force I wrote casually. Then we can see the effect.
2. settings of file suite
First, we should see the red force tags. This is just when we set the prj force tag in the test at the previous layer, it will be forcibly passed to all child elements, including the following testcase.
The settings page is similar to the directory type. If you repeat the page, let's talk about the more pages.
Test template: test template. You can specify a keyword as the template for all testcase files in this test suite. In this way, all testcase files only need to set the input parameters of this keyword.
This is available in the demo of selenium2library. You can take a look at the shoes you want to know.
Test Timeout: set the time-out time for each test case. If the time-out is exceeded, the case fails and stops running. This prevents cases from getting stuck and failing.
Force tags: In File suite, you can add force tags to the child element, but it cannot delete the tags set by the parent element.
Default tags: the default tag. In fact, it is no different from force tags. The effects are the same, but the colors are different.
Here we add another tag:
3. settings of testcase
We can see that all the added tags are added here, which is very convenient for lazy people. In the past, it was difficult to set one by one. Now at least you can set them in batches, then, if not, you can set a unique tag for a single case.
In my opinion, the difference between Force tags and default tags is only a bit different in color. Other differences are not found at the moment.
Here, the setup, teardown, timeout, and template are added with a test, which is the same as that in the file suite. This is omitted because it is already in test case.
4. settings of Resource
Not to mention, there is only one documentation.
5. User keywords settings
Compared with testcase, it does not have tags, nor setup and template, and two new settings are arguments and return value.
In fact, the shoes that have a little programming basics should all know that the input parameters and return values.
In this way, it seems that user keywords are actually a function. Furthermore, the keywords of Bulletin and the keywords in testlib are also functions in different layers. The last two are code-level encapsulation. functions written in Python code are encapsulated into callable keywords, while user keywords further encapsulate these callable keywords, it can be understood as an application-layer encapsulation and can be encapsulated layer by layer.
Later, you will find that you are dealing with user keywords most of the time. It is much easier to make good use of user keywords.
==== Tips ====
When you do not need to set settings frequently, you can click to hide the settings.
================
Iii. Run
This section mainly describes the run page of the workspace. Here we can manually run some settings related to our case.
1. check it out first.
A few days before I wrote this article, ride launched version 0.45. One of the major improvements was to integrate the selected running case area at the bottom left of the figure with our case area. It is much easier to run a single case only. You can simply tick it and run it. In versions 0.44 and earlier, you need to click run first, in the lower-left corner, check the case to be executed and run it again. When there are many cases, you need to move the mouse multiple times.
In the middle, let's talk about it in sequence.
1) Execution profile: select the running mode, which includes pybot, jybot, and custom script. By default, we use pybot to run the case. jybot needs to install Jython support. Custom Script is run by selecting a custom script. For the moment, we don't need to modify it. The default value is pybot. We will study the other two in the future.
2) Start and Stop: Run and stop cases.
3) report and log: Report and log, which can be clicked only after running. What is their difference? I feel that the report is more about the display of results, logs are more about process records, and logs are more about use.
4) autosave: Save automatically. If it is not checked, if it is not saved after the case is modified, the system will prompt whether to save the case. If this option is selected, it is automatically saved during running.
5) arguments: the parameter of pybot (or jybot). For example, a parameter is added later. For full-version parameters, enter pybot. bat -- help in the doc command line.
6) only run tests with these tags: only test cases with these tags are run.
7) skip tests with these tags: Skip the test cases of these tags. 6 and 7 are related to the tags we mentioned earlier. When there are more cases, it is convenient to use tags to manage and run the cases, you can only run some marked cases or skip them as needed. (Of course, the premise is that your case should be able to run independently without mutual dependency. In the future, we need to make the same case design on this premise)
In the last two regions, the options on the left are the running cases. If you do not select the options, the options are all. The area on the right is the output area of the running information. Some output information and running results of the running process are displayed here.
2. Let's run it.
To give a simple demonstration of the arguments just mentioned, I added a parameter-t case. In fact, the effect is the same if it is not added, because we are now using this case, if you add more cases, he will only run the case called case according to the parameters I have given.
In the output area, we can see the running process. At present, no specific process logs are printed in this version. Wu Bo's updated version is added, the operation logs of each page are printed.
In this case, we only have the following scripts:
Open IE, enter the Baidu page, enter in the search bar, and click search.
The no translation for key shown in Figure 2 is displayed for the Chinese I entered, but this does not affect the execution result.
In Figure 2, each case has a result, pass or fail, and a general result is finally given.
The following three rows:
Output: C: \ Users \ Sony \ appdata \ Local \ temp \ ridevrzwbh. d \ output. xml
Log: C: \ Users \ Sony \ appdata \ Local \ temp \ ridevrzwbh. d \ log.html
Report: C: \ Users \ Sony \ appdata \ Local \ temp \ ridevrzwbh. d \ report.html
The first one is output. xml. What is the specific function? At present, we use this file for integration with Jenkins to output reports.
The other two HTML files are associated with the two buttons displayed on the run page. After Figure 2 is completed, the two buttons can also be clicked, the corresponding HTML file is displayed.
3. Click Log.
Normally, we may see this page, which is mainly restricted by the active script in the IE settings. You can manually click the prompt link to select allow, but this will happen again next time.
On the IE tool> Internet Options> Advanced page, you can tick the options that allow the activity content to run in the figure so that the prompt will not be displayed in the future.
Robot framework -- 04 Workspace