From 76ae0969c4196430085ea165cf91350699ca0193 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 7 Aug 2020 11:25:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=BA=E6=99=AF=E5=86=85cookie?= =?UTF-8?q?=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/dto/scenario/Scenario.java | 1 + .../api/test/components/ApiScenarioForm.vue | 7 +++++++ .../src/business/components/api/test/model/JMX.js | 9 +++++++++ .../components/api/test/model/ScenarioModel.js | 11 ++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java index 0d33151293..654689f7ff 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java @@ -10,6 +10,7 @@ public class Scenario { private String name; private String url; private String environmentId; + private Boolean enableCookieShare; private List variables; private List headers; private List requests; diff --git a/frontend/src/business/components/api/test/components/ApiScenarioForm.vue b/frontend/src/business/components/api/test/components/ApiScenarioForm.vue index a1882d8aac..461e398ab3 100644 --- a/frontend/src/business/components/api/test/components/ApiScenarioForm.vue +++ b/frontend/src/business/components/api/test/components/ApiScenarioForm.vue @@ -21,6 +21,9 @@ + + {{'共享 Cookie'}} + @@ -168,4 +171,8 @@ font-weight: 600; } + .cookie-item { + margin-top: 15px; + } + diff --git a/frontend/src/business/components/api/test/model/JMX.js b/frontend/src/business/components/api/test/model/JMX.js index 7e0839883a..952eb15b62 100644 --- a/frontend/src/business/components/api/test/model/JMX.js +++ b/frontend/src/business/components/api/test/model/JMX.js @@ -328,6 +328,15 @@ export class HTTPSamplerArguments extends Element { } } +export class CookieManager extends DefaultTestElement { + constructor(testName) { + super('CookieManager', 'CookiePanel', 'CookieManager', testName); + this.collectionProp('CookieManager.cookies'); + this.boolProp('CookieManager.clearEachIteration', false, false); + this.boolProp('CookieManager.controlledByThreadGroup', false, false); + } +} + export class DurationAssertion extends DefaultTestElement { constructor(testName, duration) { super('DurationAssertion', 'DurationAssertionGui', 'DurationAssertion', testName); diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index f1567a281d..76b03cc935 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -1,5 +1,5 @@ import { - Arguments, + Arguments, CookieManager, DubboSample, DurationAssertion, Element, @@ -174,6 +174,7 @@ export class Scenario extends BaseConfig { this.environmentId = undefined; this.dubboConfig = undefined; this.environment = undefined; + this.enableCookieShare = false; this.set(options); this.sets({variables: KeyValue, headers: KeyValue, requests: RequestFactory}, options); @@ -765,6 +766,8 @@ class JMXGenerator { this.addScenarioHeaders(threadGroup, scenario); + this.addScenarioCookieManager(threadGroup, scenario); + scenario.requests.forEach(request => { if (!request.isValid()) return; let sampler; @@ -822,6 +825,12 @@ class JMXGenerator { } } + addScenarioCookieManager(threadGroup, scenario) { + if (scenario.enableCookieShare) { + threadGroup.put(new CookieManager(scenario.name)); + } + } + addScenarioHeaders(threadGroup, scenario) { let environment = scenario.environment; if (environment) {