mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
change: add StartTransaction/EndTransaction method
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## v0.3.0 (2021-12-22)
|
## v0.3.0 (2021-12-22)
|
||||||
|
|
||||||
- feat: implement transaction mechanism for load test
|
- feat: implement `transaction` mechanism for load test
|
||||||
- feat: support `--continue-on-failure` flag to continue running next step when failure occurs, default to failfast
|
- feat: support `--continue-on-failure` flag to continue running next step when failure occurs, default to failfast
|
||||||
- refactor: fork [boomer] as sub module
|
- refactor: fork [boomer] as sub module
|
||||||
- feat: report GA events with version
|
- feat: report GA events with version
|
||||||
|
|||||||
@@ -11,6 +11,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"teststeps": [
|
"teststeps": [
|
||||||
|
{
|
||||||
|
"name": "transaction 1 start",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "start"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "get with params",
|
"name": "get with params",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -64,6 +71,13 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "transaction 1 end",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "end"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "post json data",
|
"name": "post json data",
|
||||||
"request": {
|
"request": {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ config:
|
|||||||
varFoo1: ${gen_random_string($n)}
|
varFoo1: ${gen_random_string($n)}
|
||||||
varFoo2: ${max($a, $b)}
|
varFoo2: ${max($a, $b)}
|
||||||
teststeps:
|
teststeps:
|
||||||
|
- name: transaction 1 start
|
||||||
|
transaction:
|
||||||
|
name: tran1
|
||||||
|
type: start
|
||||||
- name: get with params
|
- name: get with params
|
||||||
request:
|
request:
|
||||||
method: GET
|
method: GET
|
||||||
@@ -43,6 +47,10 @@ teststeps:
|
|||||||
assert: equals
|
assert: equals
|
||||||
expect: "34.5"
|
expect: "34.5"
|
||||||
msg: check args foo2
|
msg: check args foo2
|
||||||
|
- name: transaction 1 end
|
||||||
|
transaction:
|
||||||
|
name: tran1
|
||||||
|
type: end
|
||||||
- name: post json data
|
- name: post json data
|
||||||
request:
|
request:
|
||||||
method: POST
|
method: POST
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ var demoTestCase = &hrp.TestCase{
|
|||||||
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
|
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
|
||||||
}),
|
}),
|
||||||
TestSteps: []hrp.IStep{
|
TestSteps: []hrp.IStep{
|
||||||
|
hrp.NewStep("transaction 1 start").StartTransaction("tran1"), // start transaction
|
||||||
hrp.NewStep("get with params").
|
hrp.NewStep("get with params").
|
||||||
WithVariables(map[string]interface{}{ // step level variables
|
WithVariables(map[string]interface{}{ // step level variables
|
||||||
"n": 3, // inherit config level variables if not set in step level, a/varFoo1
|
"n": 3, // inherit config level variables if not set in step level, a/varFoo1
|
||||||
@@ -35,6 +36,7 @@ var demoTestCase = &hrp.TestCase{
|
|||||||
AssertLengthEqual("body.args.foo1", 5, "check args foo1"). // validate response body with jmespath
|
AssertLengthEqual("body.args.foo1", 5, "check args foo1"). // validate response body with jmespath
|
||||||
AssertLengthEqual("$varFoo1", 5, "check args foo1"). // assert with extracted variable from current step
|
AssertLengthEqual("$varFoo1", 5, "check args foo1"). // assert with extracted variable from current step
|
||||||
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
||||||
|
hrp.NewStep("transaction 1 end").EndTransaction("tran1"), // end transaction
|
||||||
hrp.NewStep("post json data").
|
hrp.NewStep("post json data").
|
||||||
POST("/post").
|
POST("/post").
|
||||||
WithBody(map[string]interface{}{
|
WithBody(map[string]interface{}{
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# NOTE: Generated By HttpRunner v3.1.6
|
||||||
|
# FROM: hrp/examples/demo.json
|
||||||
|
|
||||||
|
|
||||||
|
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseDemo(HttpRunner):
|
||||||
|
|
||||||
|
config = (
|
||||||
|
Config("demo with complex mechanisms")
|
||||||
|
.variables(
|
||||||
|
**{
|
||||||
|
"a": 12.3,
|
||||||
|
"b": 3.45,
|
||||||
|
"n": 5,
|
||||||
|
"varFoo1": "${gen_random_string($n)}",
|
||||||
|
"varFoo2": "${max($a, $b)}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.base_url("https://postman-echo.com")
|
||||||
|
)
|
||||||
|
|
||||||
|
teststeps = [
|
||||||
|
Step(
|
||||||
|
RunRequest("get with params")
|
||||||
|
.with_variables(**{"b": 34.5, "n": 3, "varFoo2": "${max($a, $b)}"})
|
||||||
|
.get("/get")
|
||||||
|
.with_params(**{"foo1": "$varFoo1", "foo2": "$varFoo2"})
|
||||||
|
.with_headers(**{"User-Agent": "HttpRunnerPlus"})
|
||||||
|
.extract()
|
||||||
|
.with_jmespath("body.args.foo1", "varFoo1")
|
||||||
|
.validate()
|
||||||
|
.assert_equal("status_code", 200)
|
||||||
|
.assert_equal('headers."Content-Type"', "application/json")
|
||||||
|
.assert_equal("body.args.foo1", 5)
|
||||||
|
.assert_equal("$varFoo1", 5)
|
||||||
|
.assert_equal("body.args.foo2", "34.5")
|
||||||
|
),
|
||||||
|
Step(
|
||||||
|
RunRequest("post json data")
|
||||||
|
.post("/post")
|
||||||
|
.validate()
|
||||||
|
.assert_equal("status_code", 200)
|
||||||
|
.assert_equal("body.json.foo1", 5)
|
||||||
|
.assert_equal("body.json.foo2", 12.3)
|
||||||
|
),
|
||||||
|
Step(
|
||||||
|
RunRequest("post form data")
|
||||||
|
.post("/post")
|
||||||
|
.with_headers(
|
||||||
|
**{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
|
||||||
|
)
|
||||||
|
.validate()
|
||||||
|
.assert_equal("status_code", 200)
|
||||||
|
.assert_equal("body.form.foo1", 5)
|
||||||
|
.assert_equal("body.form.foo2", "12.3")
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
TestCaseDemo().test_start()
|
||||||
@@ -174,6 +174,28 @@ func (s *StepRequest) CallRefCase(tc *TestCase) *StepTestCaseWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartTransaction starts a transaction.
|
||||||
|
func (s *StepRequest) StartTransaction(name string) *StepTransaction {
|
||||||
|
s.step.Transaction = &Transaction{
|
||||||
|
Name: name,
|
||||||
|
Type: TransactionStart,
|
||||||
|
}
|
||||||
|
return &StepTransaction{
|
||||||
|
step: s.step,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EndTransaction ends a transaction.
|
||||||
|
func (s *StepRequest) EndTransaction(name string) *StepTransaction {
|
||||||
|
s.step.Transaction = &Transaction{
|
||||||
|
Name: name,
|
||||||
|
Type: TransactionEnd,
|
||||||
|
}
|
||||||
|
return &StepTransaction{
|
||||||
|
step: s.step,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// StepRequestWithOptionalArgs implements IStep interface.
|
// StepRequestWithOptionalArgs implements IStep interface.
|
||||||
type StepRequestWithOptionalArgs struct {
|
type StepRequestWithOptionalArgs struct {
|
||||||
step *TStep
|
step *TStep
|
||||||
|
|||||||
Reference in New Issue
Block a user