- SoapUI Cookbook
- Rupert Anderson
- 387字
- 2021-07-23 20:19:20
Setting properties from an external file
It can be a good idea to maintain your properties externally to your SoapUI project. This can help make your projects more flexible when switching between target environments, especially when running SoapUI from scripts (see Chapter 5, Automation and Scripting). In this recipe, we will see how to do this using the Properties TestStep
.
Getting ready
I have added a sample properties file called test-properties.txt
, which contains the following code:
environmentName=Dev Test invoiceEndpoint=http://localhost:9000 userName=test password=password
There is a completed sample project called PropertiesProject
in the Chapter 2
samples.
How to do it...
First, we create a new empty project, TestSuite
and TestCase
. Then, we add a Property TestStep
to read the properties from the test-properties.txt
file using a project property to store the file's path. Finally, we write a Groovy TestStep
to use property expansions to access the loaded property values from the Property TestStep
, and we then return and log the values. Perform the following steps:
- Create new Generic Project with empty
TestSuite
andTestCase
. - Create a property on the project called
propertiesFile
with the value/soapui-cookbook/chapter2/test-properties.txt
. - Create new
Property TestStep
. You only need to populate the Load From box with${#Project#propertiesFile}
, which refers to the previous project's property. - Create a new
Groovy TestStep
, which contains the following code:def propertiesFile = context.expand('${#Project#propertiesFile}') def environmentName = context.expand('${LoadProperties#environmentName}') def invoiceEndpoint = context.expand('${LoadProperties#invoiceEndpoint}') def userName = context.expand('${LoadProperties#userName}') def password = context.expand('${LoadProperties#password}') return "propertiesFile: ${propertiesFile} environmentName: ${environmentName} invoiceEndpoint=${invoiceEndpoint} userName=${userName} password=${password}"
- Now, run the
TestCase
, and you should see the property data from the file in theTestCase
log!
How it work...
The Properties TestStep
is parameterized to take its filename from a project-level property called propertiesFile
. This is done for easy switching; for example, you can have several properties files, one for each test environment.
The Groovy TestStep
is just there for demo purposes and to illustrate the use of property expansions to access the properties loaded by the Property TestStep
. This step can easily be replaced by a web service request TestStep
, taking the endpoint and credentials as property expansions.
The main learning is that you can avoid hardcoding parameters, and to do this, it's important to have a grasp of the ways to use properties in SoapUI.
See also
- To learn more about how to work with properties, go to http://www.soapui.org/Functional-Testing/working-with-properties.html
- Learning Docker
- Vue.js前端開發基礎與項目實戰
- Visual C++數字圖像模式識別技術詳解
- C語言從入門到精通(第4版)
- C語言實驗指導及習題解析
- PySide GUI Application Development(Second Edition)
- 程序員修煉之道:通向務實的最高境界(第2版)
- Mastering Drupal 8 Views
- Android底層接口與驅動開發技術詳解
- BIM概論及Revit精講
- Learning jQuery(Fourth Edition)
- Scratch3.0趣味編程動手玩:比賽訓練營
- HTML+CSS+JavaScript編程入門指南(全2冊)
- 嵌入式Linux C語言程序設計基礎教程
- C語言從入門到精通