How RIDE calls functions in custom Python files

1. How to write a Python function from scratch?

Refer to another article: https://my.oschina.net/u/942203/blog/1786979

2. How does IDEA call the written Python file?

a. Put the written Python file into a folder of a project in RIDE for storing the Custom Library

b. Import the python file corresponding to Import in the Edit Page of Directory or Test Suite or Test Case Level as library

The black Library indicates that the reference is successful.

Red indicates that the reference fails (usually the file path is wrong, or the file is compiled incorrectly).

The blue ones refer to keywords or defined variable resources.

3. How are the functions in the Python file added to the Test Step and called?

As shown in the figure below, my PreparePremia.py has been added to the Attribution Test Suite level, so all Test Cases under this Test Suite can parse the functions in this python, let's see how "save_monthly_premia_data" is used in Test Step middle:

The last line of the Test Step keyword "Save Monthly Premia Data" calls the keyword in the file:

You can press F5 to view:

4. How are functions in Python files called by Test Suite?

When we open Test Case, we can see the table where Test Step is added, and we can clearly see how to call functions in python.

But opening the Test Suite panel, what do we see?

There are only Settings, variables and Metadata areas. . .

In the screenshot, I called a custom keyword "Get Input Params" in Suite Setup, and passed two parameters "${SUITE NAME}" and "RiskAttributionCalculation". How did this keyword come from?

You can see that this custom keyword actually calls the "parse_input_params" function in the "ExcelUtil.py" file:

And also set a Suite level global variable "${input_params}".

so:

Suite Setup means:

Call the custom keyword "Get Input Params" to get a global variable "${input_params}".

therefore:

The Test Suite level refers to custom keywords to initialize certain values. And this custom keyword will call the function in the Python file.

5. How are the obtained Suite-level variables called?

Because MonthlyPremia is a Test Case under the Attribution Suite, this Case can directly call "${input_params}"~~.

The input_params I returned is a dict, so I need to pass in the key to get the corresponding Value.

The writing is very straightforward. If you have any questions, you can leave a message. Thank you for reading.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325486282&siteId=291194637