هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Setting Environment Parameters of an API Script

Updated on 2025-01-10 GMT+08:00

During automated testing, there are multiple test environments whose parameter values are different, for example, the domain name and account. These parameters are often used in test scripts. If they are bound to test scripts, the scripts will become highly redundant and hard to be reused.

To solve the preceding problems, you can use environment parameters to manage them in a unified manner. In test scripts, environment parameters are referenced in parametrization mode. During execution, you only need to select an execution environment to use the corresponding environment parameter values to complete testing.

Application Scope

The parameters, checkpoints, variables, and URLs of the test steps in each test case of the current project can reference environment parameters.

Reference Format

The reference format of an environment parameter is $${Parameter name}. For example, if the parameter name is hostname, you can use $${hostname} to reference the parameter.

You can configure and manage environment parameters by group as required. For example, the value of hostname in the quasi-production environment is stage.example.com, and the value in the production environment is prod.example.com. The test script uses $${hostname} to reference this parameter. During the test, select different environments to execute the test so that a set of automated API test cases can be reused in all environments.

Procedure

  1. Go to the Scripting tab page and click .

  2. Click New Variable, enter parameter information, and click OK.

    Configuration Item

    Description

    Name

    Parameter name.

    Type

    Parameter type. Multiple types are supported, such as text, random string, random integer, and timestamp.

    Value

    Parameter value.

    Description

    Parameter description.

    Sensitive

    This service encrypts sensitive parameter values during storage and overwrites them with asterisks (*) in test result logs. Sensitive data includes but is not limited to personal and authentication information, such as names, addresses, and usernames.

    Dynamic

    Dynamic parameter setting. The value of a dynamic parameter can be assigned during test case execution. The initial value of a dynamic parameter can be empty. After a value is assigned, the latest value is displayed.

    After you set the value of the Assign Value to Dynamic Environment Parameter column in the Extract Response tab page of the test step, the extracted value is assigned to the dynamic parameter during test execution. For details, see Dynamic Variable Description.

  3. Change the default environment.

    To set another environment as the default environment, click in the upper right corner of the environment card and select Set as Default.

Built-in Functions

  1. You can use built-in functions to configure environment parameters. Note that nested built-in functions are output as they are.
  2. For details about the supported built-in functions, see Table 1.
    Table 1 Supported built-in functions

    No.

    Function

    Description

    1

    $random_string(intA)

    Generate a random string of a specified length

    2

    $random_int(intA, intB)

    Generate a random number in a specified range

    3

    $timestamp()

    Obtain the current timestamp

    4

    $timestamp_format(String A, String B)

    Convert a timestamp into a date

    5

    $uuid()

    Generate a UUID

    6

    $encode_base64(StringA)

    Generate Base64 encoding

    7

    $md5(StringA)

    Generate an MD5 hash value

    8

    $sha512(StringA)

    Generate SHA512 encoding

  3. Examples:
    • The value of $random_string(intA) is output normally.

    • Built-in functions that concatenate strings are parsed as strings, and their output values are strings as they are. For example, the output values of functions aa$random_string(10) and $random_string(10)aa are aa$random_string(10) and $random_string(10)aa.

    • If two parameters are passed while only one parameter is required, for example, $random_string (1,1), an exception will be thrown.

      If the input and required parameter types do not match, for example, $random_string(fff) or $random_string(), an exception will be thrown.

Synchronization

Right-click the parameter to be synchronized and choose Synchronize to other environments from the shortcut menu to synchronize the current parameter to all environments.

Dynamic Variable Description

Multiple test cases in a test suite may have context relationships. The test case that is executed later depends on the result returned by the API in the test case that is executed earlier. For example, all APIs require authentication information, which has a validity period. If it is obtained in each test case, the test procedure of the test case will be redundant and difficult to maintain.

This problem can be avoided by using dynamic global variables. In the first executed test case, the authentication information is obtained and then assigned to the dynamic global variables. In the subsequent executed test cases, the dynamic global variables can be directly used, avoiding obtaining authentication information repeatedly.

  1. Set dynamic variables.

    1. On the test case list of the Auto API Test tab page, click More on the right of the page and choose Environment Parameters.
    2. Select the check box in the Dynamic column and click Save to set a global variable to a dynamic variable.

  2. Assign values to dynamic variables.

    1. In an automated API test case, click the Extract Response tab of the test step, and click the Add button in the Advanced Extraction Type column.

    2. Select a value from the Assign Value to Dynamic Environment Parameter drop-down list box.

  3. Use a dynamic variable.

    • Use the dynamic variable in a test case.

      Reference the dynamic global variable in a test case as required. For details, see Reference Format.

    • Use a dynamic global variable in a test suite.

      Add the test cases in 2 and 3 to a test suite in sequence, and select Serial. In this way, the latest value assigned to the dynamic global variable can be used during the execution of related test cases.

      NOTE:

      You are not advised to use dynamic global variables during parallel execution because the value assigning and sequence of the dynamic variables are uncertain.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback