groovy 使用CURL命令发送请求并使用JavaScript从响应中仅获取变量值

zvms9eto  于 2022-11-01  发布在  Java
关注(0)|答案(1)|浏览(195)

我的卷发请求:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X GET "https://api-cloud.browserstack.com/app-automate/sessions/22dbfb187486090d974a11ac91t65722988e0705.json"

我得到的回应:

{
  "automation_session": {
    "name": "login_test",
    "duration": 39,
    "os": "android",
    "os_version": "9.0",
    "browser_version": "app",
    "browser": null,
    "device": "OnePlus 6T",
    "status": "passed",
    "hashed_id": "22dbfb187486090d974a11ac91t65722988e0705",
    "reason": "CLIENT_STOPPED_SESSION",
    "build_name": "SampleBuild",
    "project_name": "SampleProject",
    "logs": "https://app-automate.browserstack.com/builds/g0726012b6rb0a4c79122d6048c7b8767677ad61/sessions/22dbfb187486090d974a11ac91t65722988e0705/logs",
    "browser_url": "https://app-automate.browserstack.com/builds/g0726012b6rb0a4c79122d6048c7b8767677ad61/sessions/22dbfb187486090d974a11ac91t65722988e0705",
    "public_url": "https://app-automate.browserstack.com/builds/g0726012b6rb0a4c79122d6048c7b8767677ad61/sessions/22dbfb187486090d974a11ac91t65722988e0705?auth_token=9876563e667cd765467e6fea5a834121e568be899505699b",
    "appium_logs_url": "https://api.browserstack.com/app-automate/builds/g0726012b6rb0a4c79122d6048c7b8767677ad61/sessions/22dbfb187486090d974a11ac91t65722988e0705/appiumlogs",
    "video_url": "https://app-automate.browserstack.com/sessions/22dbfb187486090d974a11ac91t65722988e0705/video?token=ZnN6cGt1WTY4UlJrdTVzcE5xcGhWTldvZGVlRydys4aWc9PSaHVkTS84UnNhdU54aWtmVU9lWHFPVWt3TM5UjJXdkNmSjdHUGxuLzBmQWFXamcyS3htM3l0tc0xZempkdnVlQ3BrN1A5OWFILzNZdz09--37203d41d45d3d42e1fb75266e527721af3ab65d&source=rest_api&diff=60060.827966758",
    "device_logs_url": "https://api.browserstack.com/app-automate/builds/g0726012b6rb0a4c79122d6048c7b8767677ad61/sessions/22dbfb187486090d974a11ac91t65722988e0705/devicelogs",
    "app_details": {
      "app_url": "bs://c8ddcb5649a8280ca800075bfd8f151115bba6b3",
      "app_name": "com.sample.loginapplication",
      "app_version": "1.0",
      "app_custom_id": "LoginApp",
      "uploaded_at": "2020-09-09T18:14:20.000Z"
    }
  }
}

从上述值仅需要java脚本变量中的public_url才能显示相同的值

或者,如果可能,请在Groovy Script For Pipeline中提供建议。

jq6vz3qz

jq6vz3qz1#

下面是JavaScript:
未经测试。

fetch('https://api-cloud.browserstack.com/app-automate/sessions/22dbfb187486090d974a11ac91t65722988e0705.json', {
    headers: {
        'Authorization': 'Basic ' + btoa('YOUR_USERNAME:YOUR_ACCESS_KEY')
    }
});
.then((response) => response.json())
.then((data) => console.log(data));

相关问题