Backend Development 11 min read

API Testing with Robot Framework, Jenkins CI/CD Integration, and Docker/Kubernetes Deployment

This guide explains how to perform interface testing using Robot Framework, set up the required environment, design test cases for order placement, integrate the tests into Jenkins CI/CD pipelines, expose them via a Flask API, containerize with Docker, and deploy the solution on Kubernetes.

Fulu Network R&D Team
Fulu Network R&D Team
Fulu Network R&D Team
API Testing with Robot Framework, Jenkins CI/CD Integration, and Docker/Kubernetes Deployment

Interface testing validates data exchange, transmission, and logical dependencies between system components, offering higher test ROI and lower maintenance compared to UI automation.

Framework Selection

Among many options (JMeter, Postman+Newman, Python unittest), Robot Framework (RF) is chosen for its keyword‑driven approach, supporting UI, mobile, and API automation with extensible libraries such as RequestsLibrary.

Environment Setup

Install Python 3+ (required by RF)

Install Robot Framework (see reference link)

Configure Jenkins for scheduling RF test execution

Use GitLab as code repository

Requirements

Implement an order‑placement scenario that involves three APIs: order creation, order status query, and token generation. The tests must run against multiple environments (test, pre‑release) and be integrated into the CI/CD pipeline.

Overall Architecture

The implementation layer uses RF with the built‑in RequestsLibrary for HTTP requests and custom Python keywords for business logic. Jenkins triggers RF execution, generates an API endpoint for the job, and the endpoint is called from the project's gitlab-ci.yml to close the automation loop.

RF Test Case Implementation

Built‑in keyword:

RequestsLibrary constructs HTTP requests (GET, POST, etc.)

Custom keywords (examples):

# Retrieve environment domain from configs.ini
import configparser

def getEnv(path, env):
    config = configparser.ConfigParser()
    config.read(path)
    passport = config[env]['passport']
    stock = config[env]['stock']
    finance = config[env]['finance']
    SUP = config[env]['SUP']
    publicApi = config[env]['publicApi']
    publicOrder = config[env]['publicOrder']
    data_dict = {
        'passport': passport,
        'stock': stock,
        'finance': finance,
        'SUP': SUP,
        'publicApi': publicApi,
        'publicOrder': publicOrder
    }
    return data_dict
# Read test data from Excel and filter by environment
import xlrd

def getExcelDate(path, sheet_name, env):
    bk = xlrd.open_workbook(path)
    sh = bk.sheet_by_name(sheet_name)
    row_num = sh.nrows
    data_list = []
    for i in range(1, row_num):
        row_data = sh.row_values(i)
        data = {}
        for index, key in enumerate(sh.row_values(0)):
            data[key] = row_data[index]
        data_list.append(data)
    data_list1 = []
    for x in data_list:
        if x.get('env') == env:
            data_list1.append(x)
    return data_list1
# Generate token for order API
*** Keywords ***
getToken
    [Arguments]    ${client_id}    ${client_secret}    ${url_domain}
    Create session    postmain    ${url_domain}
    ${auth}=    Create dictionary    grant_type=client_credentials    client_id=${client_id}    client_secret=${client_secret}
    ${header}=    Create dictionary    content-type=application/x-www-form-urlencoded
    ${addr}=    Post Request    postmain    /oauth/token    data=${auth}    headers=${header}
    Should Be Equal As Strings    ${addr.status_code}    200
    ${responsedata}=    To Json    ${addr.content}
    ${access}=    Get From Dictionary    ${responsedata}    access_token
    ${token}=    Set Variable    bearer ${access}
    Set Test Variable    ${token}
    Delete All Sessions

Demo test case (excerpt):

*** Settings ***
Test Template
Resource          引用所有资源.txt

*** Test Cases ***
01 下单卡密直储商品
    [Tags]    order
    LOG    ---------------------获取下单前的数量、余额------------------------------------------
    getAllData    0
    ${Cardnum1}=    Set Variable    ${Cardnum}
    ${FPbalance1}=    Set Variable    ${FPbalance}
    ... (additional variable setups) ...
    ${CustomerOrderNo1}=    Evaluate    random.randint(1000000, 9999999)    random
    ${Time}=    Get Time
    log    ------------------------下单操作-------------------------------------------------------
    getToken    100xxxx    295xxxx    ${casUrl}
    ${input_cs}=    Create Dictionary    memberId=${j_merchant_id}    clientId=1xxx079    ...
    postRequests    ${publicOrderUrl}    ${input_cs}    /api/Order    ${token}
    ... (assertions and post‑order checks) ...

CI/CD Integration

Jenkins job is parameterized for IT and PRE environments; a Flask service exposes two HTTP endpoints ( /test/it and /test/pre ) that trigger the Jenkins job via the Python jenkins library.

from flask import Flask, jsonify
import jenkins

server = jenkins.Jenkins('http://10.0.1.xxx:80', username='xxx', password='fuluxxxx')
app = Flask(__name__)

@app.route('/test/it', methods=['GET'])
def robot_Test_It():
    server.build_job('CI_FuluOrder', {'environment': 'IT'})
    return jsonify({'result': 'success'})

@app.route('/test/pre', methods=['GET'])
def robot_Test_Pre():
    server.build_job('CI_FuluOrder', {'environment': 'PRE'})
    return jsonify({'result': 'success'})

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, debug=True)

The Flask service is containerized with a Dockerfile, built into an image, and deployed on a Kubernetes cluster (service name ordermiddle ) to provide external access for triggering tests.

FROM python:3.6
WORKDIR /app
EXPOSE 80
COPY . .
RUN pip install -r requirements.txt
ENTRYPOINT ["python", "robotTestApi.py"]

In the target project's gitlab-ci.yml , a step calls the appropriate endpoint after deployment (allowing ~30 seconds for container startup) and the test report is sent back to stakeholders.

DockerCI/CDKubernetesJenkinsAPI testingrobot-framework
Fulu Network R&D Team
Written by

Fulu Network R&D Team

Providing technical literature sharing for Fulu Holdings' tech elite, promoting its technologies through experience summaries, technology consolidation, and innovation sharing.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.