You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Robot Framework结果导入Xray失败:请求数据缺失排查求助

问题:Robot Framework测试结果同步Xray失败提示“缺少测试结果数据”

问题详情

使用Robot Framework 7.0在GitLab CI执行测试后,尝试将output.xml同步到Xray Cloud时,始终收到错误:

{"error":"Missing data in the robot results import request"}

相关配置

gitlab-ci.yml中的同步命令

- echo "Uploading output.xml to Xray..."
- >
  curl --trace-ascii - \
       -H "Authorization: Bearer $XRAY_TOKEN" \
       -F results=@reports/output.xml \
       "https://eu.xray.cloud.getxray.app/api/v2/import/execution/robot?projectKey=BC&testPlanKey=BC-8"

Robot生成的output.xml片段

<?xml version="1.0" encoding="UTF-8"?>
<robot generator="Robot 7.0 (Python 3.9.22 on linux)" generated="2025-07-01T12:59:01.526616" rpa="false" schemaversion="5">
<suite id="s1" name="Frontend-Test" source="/builds/tounsisabrine/bookcart-robot/frontend-test">
<suite id="s1-s1" name="Login.Feature" source="/builds/tounsisabrine/bookcart-robot/frontend-test/login.feature.robot">
<test id="s1-s1-t1" name="BC-7: Successful login with valid credentials" line="8">
<kw name="Begin Test" owner="common" type="SETUP">
<kw name="Set Selenium Speed" owner="SeleniumLibrary">
<arg>.2s</arg>
<doc>Sets the delay that is waited after each Selenium command.</doc>
<status status="PASS" start="2025-07-01T12:58:09.692484" elapsed="0.000472"/>
</kw>

GitLab CI执行错误输出

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 46003  100    60  100 45943     84  64416 --:--:-- --:--:-- --:--:-- 64429
{"error":"Missing data in the robot results import request"}
Cleaning up project directory and file based variables

根因分析

  1. 表单字段名错误:Xray Cloud的v2导入API要求表单字段名为robot,而非当前使用的results,导致Xray无法识别上传的测试数据。
  2. Robot schema版本不兼容:Robot Framework 7.0生成的是schemaversion=5的XML,Xray默认可能未自动适配该新版本,需要明确指定schema版本参数。
  3. 文件路径验证缺失:未确认reports/output.xml文件是否存在、可读,可能存在路径错误或文件生成失败的情况。

解决方案

1. 修正curl表单字段名

将-F results=@reports/output.xml改为-F robot=@reports/output.xml,这是Xray API要求的字段名。

2. 指定schema版本参数

在请求URL中添加&schemaVersion=5,明确告知Xray使用Robot 7.0的schema版本:

- >
  curl --trace-ascii - \
       -H "Authorization: Bearer $XRAY_TOKEN" \
       -F robot=@reports/output.xml \
       "https://eu.xray.cloud.getxray.app/api/v2/import/execution/robot?projectKey=BC&testPlanKey=BC-8&schemaVersion=5"

3. 验证文件存在性

在同步命令前添加检查步骤,确保文件生成正常:

- echo "Checking output.xml existence..."
- ls -la reports/
- cat reports/output.xml | head -20

4. 权限验证

确认XRAY_TOKEN具备以下权限:

  • 向指定项目(projectKey=BC)导入测试结果的权限
  • 关联测试计划(testPlanKey=BC-8)的权限

内容的提问来源于stack exchange,提问作者sabrine tounsi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 19:07:34