class TestCaseUpload(HttpRunner): config = Config("test upload file with httpbin").base_url( "${get_httpbin_server()}") teststeps = [ Step( RunRequest("upload file").with_variables( **{ "file_path": "test.env", "m_encoder": "${multipart_encoder(file=$file_path)}", }).post("/post").with_headers( **{ "Content-Type": "${multipart_content_type($m_encoder)}" }).with_data("$m_encoder").validate().assert_equal( "status_code", 200).assert_startswith("body.files.file", "UserName=test")), Step( RunRequest("upload file with keyword").post("/post").upload( **{ "file": "test.env" }).validate().assert_equal("status_code", 200).assert_startswith( "body.files.file", "UserName=test")), ]
class TestCaseLoadImage(HttpRunner): config = Config("load images").base_url("${get_httpbin_server()}") teststeps = [ Step( RunRequest("get png image") .get("/image/png") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("get jpeg image") .get("/image/jpeg") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("get webp image") .get("/image/webp") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("get svg image") .get("/image/svg") .validate() .assert_equal("status_code", 200) ), ]
class TestCaseDemoTestcaseRequest(HttpRunner): config = (Config("request methods testcase with functions").variables( **{ "foo1": "config_bar1", "foo2": "config_bar2", "expect_foo1": "config_bar1", "expect_foo2": "config_bar2", }).base_url("https://postman-echo.com").verify(False).export( *["foo3"])) teststeps = [ Step( RunRequest("get with params").with_variables( **{ "foo1": "bar11", "foo2": "bar21", "sum_v": "${sum_two(1, 2)}" }).get("/get").with_params(**{ "foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v" }).with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}" }).extract().with_jmespath( "body.args.foo2", "foo3").validate().assert_equal( "status_code", 200).assert_equal( "body.args.foo1", "bar11").assert_equal( "body.args.sum_v", "3").assert_equal("body.args.foo2", "bar21")), Step( RunRequest("post raw text").with_variables(**{ "foo1": "bar12", "foo3": "bar32" }).post("/post").with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}", "Content-Type": "text/plain", }). with_data( "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." ).validate().assert_equal("status_code", 200).assert_equal( "body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar21.", )), Step( RunRequest("post form data").with_variables(**{ "foo2": "bar23" }).post("/post").with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}", "Content-Type": "application/x-www-form-urlencoded", }).with_data("foo1=$foo1&foo2=$foo2&foo3=$foo3").validate(). assert_equal("status_code", 200).assert_equal( "body.form.foo1", "$expect_foo1").assert_equal( "body.form.foo2", "bar23").assert_equal("body.form.foo3", "bar21")), ]
class Test_hrun_stu(HttpRunner): @pytest.mark.parametrize("param", Parameters({ "httprunner_version": "$get_httprunner_version()" })) def test_start(self, param): super().test_start(param) config = Config('用来练习的case').base_url('http://127.0.0.1:5000/') # @pytest.mark.parametrize("param", Parameters({"username": [111, 222, 333]})) teststeps = [ Step( RunRequest('测试getUserName接口').get( '/getUserName').extract().with_jmespath( 'body.username', 'var_username') # 新写一份接口case # RunTestCase # 引入一份接口case ), Step( RunRequest('测试joinStr接口').get('/joinStr').with_params( **{ 'str1': 'hello', 'str2': '$httprunner_version' }) # .validate() # .assert_equal('body.result', 'hello $var_username') ), Step(RunRequest('测试string_data接口').get('/string_data').extract()) ]
def __init__(self, testdata): Saver.caseno = testdata['caseno'] testdata['headers'] = Saver.handle_params( json.dumps(testdata['headers'], ensure_ascii=False)) testdata['data'] = Saver.handle_params( json.dumps(testdata['data'], ensure_ascii=False)) self.config = (Config(testdata['caseno'] + '-' + testdata['casename']).variables(**{}).base_url( testdata['baseurl']).verify(False)) self.teststeps = [] running = RunRequest(testdata['casename'])\ .with_variables() \ .setup_hook(testdata['setupfunc']) \ .__getattribute__(testdata['method'].lower())(testdata['url']) \ .with_json(testdata['data'])\ .with_params(**testdata['params'])\ .with_headers(**testdata['headers']) \ .teardown_hook('${afterresponse($response)}') \ .validate() \ for ast in testdata['asserts']: if ast[0] == 'eq': running = running.assert_equal(ast[1], ast[2]) self.teststeps.append(Step(running))
class TestCaseTestCaseMore(HttpRunner): config = ( Config("basic test config(测试接口的依赖)") .variables(**{"user": "******", "pawd": "${password()}"}) .base_url("http://127.0.0.1:8000/api/v1") .export(*["token"]) ) teststeps = [ Step( RunRequest(" test_login") .post("/login/") .with_data({"username": "******", "password": "******"}) .extract() .with_jmespath("body.data.token", "token") .validate() .assert_equal("body.code", 10200) .assert_equal("body.message", "登录成功") ), Step( RunRequest(" test_luck_draw") .post("/luck_draw/") .with_data({"token": "$token"}) .validate() .assert_equal("body.code", 10200) ), ]
class TestCseOBE(HttpRunner): config = ( Config("OBE目标达成度分析-测试教师权限,修改课程环节,请求失败") .base_url("https://courseapi.tongshike.cn") .verify(False) ) # 测试教师权限,修改课程环节,请求失败 teststeps = [ Step( RunRequest("用户登录成功!") .post("/users/login") .with_headers(**{"Content-Type": "application/json"}) .with_json({"loginName": "chenqinggangtea02","password": "******"}) .extract() .with_jmespath("body.authorization", "authorization") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("获取课程列表") .get("/courses") .with_headers(**{"Content-Type": "application/json","Authorization":"$authorization"}) .with_params(**{"keyword":"","publishStatus":"1","type":"1","pn":"1","ps":"15","octypeId":"","lang":"zh"}) .extract() .with_jmespath("body.courseList[0].id", "ocid") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("测试教师权限,修改课程环节,请求失败") .post("/obe") .with_headers(**{"Content-Type": "application/json","Authorization":"$authorization"}) .with_json( { "id": 7, "ocId": "$ocid", "passScore": 1, "linkList": [ { "name": "作业1" } ], "outcomeList": [ { "description": "这是一个目标描述1", "outcomeLinkDTOList": [ { "factor": 1, "code": "A" } ] } ] } ) .validate() .assert_equal("status_code", 403) .assert_equal("body.message", "No permission.") ) ]
class TestCseOBE(HttpRunner): config = (Config("OBE目标达成度分析").base_url("https://courseapi.tongshike.cn"). verify(False).export(*["authorization"])) teststeps = [ Step( RunRequest("用户登录成功!").post("/users/login").with_headers( **{ "Content-Type": "application/json" }).with_json({ "loginName": "chenqinggangtea", "password": "******" }).extract().with_jmespath( "body.authorization", "authorization").validate().assert_equal( "status_code", 200)), Step( RunRequest("获取课程列表").get("/courses").with_headers( **{ "Content-Type": "application/json", "Authorization": "$authorization" }).with_params( **{ "keyword": "", "publishStatus": "1", "type": "1", "pn": "1", "ps": "15", "octypeId": "", "lang": "zh" }).validate().extract().with_jmespath( "body.courseList", "ocid").assert_equal("status_code", 200)) ]
class TestCaseTestCase(HttpRunner): config = Config("basic test config").base_url("http://127.0.0.1:8000/api") teststeps = [ Step( RunRequest(" test_add_event_all_null").post( "/add_event/").with_data({ "eid": "", "limit": "", "address": "", "start_time": "" }).validate().assert_equal("body.status", 10021).assert_equal( "body.message", "parameter error")), Step( RunRequest(" test_add_event_eid_exist").post( "/add_event/").with_data({ "eid": 1, "name": "oneplus", "limit": 2000, "address": "shenzhen", "start_time": "2017", }).validate().assert_equal("body.status", 10022).assert_equal( "body.message", "event id already exists")), Step( RunRequest(" test_add_event_success").post( "/add_event/").with_data({ "eid": 25, "name": "oneplus9", "limit": 2000, "address": "shenzhen", "start_time": "2017-05-10 12:00:00", }).validate().assert_equal("body.status", 10200).assert_equal( "body.message", "add event success")), ]
class TestCaseLogin(HttpRunner): config = ( Config("testcase description") .variables(**getCommonVariables()) .base_url("${get_base_url()}") .verify(False) .export(*["token", "verifyId", "sessionId"]) ) teststeps = [ Step( RunRequest("/ops/api/web/getVerificationCode") .get("/ops/api/web/getVerificationCode?") .with_headers( **getCommonHeaser({ "x-app-id": "$x_app_id", "x-tenant-id": "$x_tenant_id", "sso_sessionid": "", "Token": "", }) ) .extract() .with_jmespath("body.data.verifyId", "verifyId") .validate() .assert_equal("status_code", 200) .assert_equal('headers."Content-Type"', "application/json;charset=UTF-8") .assert_equal("body.code", "000000") .assert_equal("body.msg", "Success") ), Step( RunRequest("/ops/api/web/login") .post("/ops/api/web/login") .with_headers( **getCommonHeaser({ "Accept": "application/json", "x-app-id": "$x_app_id", "x-tenant-id": "$x_tenant_id", "sso_sessionid": "", "Token": "", }) ) .with_json( { "userName": "******", "password": "******", "verifyCode": "$verifyCode", "verifyId": "$verifyId", "regType": "$regType", } ) .extract() .with_jmespath("body.data.token", "token") .with_jmespath("body.data.sessionId", "sessionId") .validate() .assert_equal("status_code", 200) .assert_equal('headers."Content-Type"', "application/json;charset=UTF-8") .assert_equal("body.code", "000000") .assert_equal("body.msg", "Success") ), ]
class Test_hrun_home(HttpRunner): @pytest.mark.parametrize( "param", Parameters({"username-password": "******"})) def test_start(self, param): super().test_start(param) config = Config('HttpRunner的接口case测试').base_url( 'http://127.0.0.1:6666/api/v1/admin') teststeps = [ Step( RunRequest('注册接口测试').post('/register').with_headers( **{ "Content-Type": "application/json" }).with_json({ 'userName': '******', 'passWord': '******' }).validate().assert_equal("status_code", 200).assert_equal( 'headers."Content-Type"', "application/json") # .with_jmespath('body.username', 'var_username')# 新写一份接口case # # RunTestCase # 引入一份接口case ), Step( RunRequest('登录接口测试').post('/login').with_headers( **{ "Content-Type": "application/json" }).with_json({ 'userName': '******', 'passWord': '******' }).validate().assert_equal("status_code", 200).assert_equal( 'headers."Content-Type"', "application/json")), Step(RunRequest('获取时间接口测试').get('/time').extract()) ]
class TestCaseHooks(HttpRunner): config = Config("basic test with httpbin").base_url("${get_httpbin_server()}") teststeps = [ Step( RunRequest("headers") .with_variables(**{"a": 123}) .setup_hook("${setup_hook_add_kwargs($request)}") .setup_hook("${setup_hook_remove_kwargs($request)}") .get("/headers") .teardown_hook("${teardown_hook_sleep_N_secs($response, 1)}") .validate() .assert_equal("status_code", 200) .assert_contained_by("body.headers.Host", "${get_httpbin_server()}") ), Step( RunRequest("alter response") .get("/headers") .teardown_hook("${alter_response($response)}") .validate() .assert_equal("status_code", 500) .assert_equal('headers."Content-Type"', "html/text") .assert_equal('body.headers."Content-Type"', "application/json") .assert_equal("body.headers.Host", "127.0.0.1:8888") ), ]
class TestcaseMustAuth(HttpRunner): config = ( setup_config() ) teststeps = [ Step( RunRequest("获取登录短信验证码") .post("/sendMessage") .with_headers(**merge_headers()) .with_json({"type": 1, "mobile": "13982050830"}) .extract() .with_jmespath("body.data.token", "code_token") .validate() .assert_equal("body.code", 0) .assert_not_equal("body.data.token", None) # .teardown_hook("${set_sms_code_token($response)}", 'code_token') ), Step(RunRequest("用户登陆") .post("/login") .with_headers(**merge_headers()) .with_json({ "code": 111111, "codeToken": "$code_token", "headimgurl": "", "mobile": "13982050830", "nickname": "", "pushId": "", "thirdSystemId": "", "type": 1, "unionid": "" }) .extract() .with_jmespath('body.data.token.token', 'auth_token') .with_jmespath('body.data.token.usercode', 'usercode') .validate() .assert_equal("body.code", 0) .assert_not_equal("body.data.token.token", None) ), Step(RunRequest("获取上传token") .post("/getQiniuToken") .with_headers(**merge_headers()) .with_json({'type': 1}) .extract() .with_jmespath('body.data', 'qiniu_token') .validate() .assert_not_equal('body.data', None) ), Step(RunRequest("测试上传图片") .post("https://upload-z2.qiniup.com/") .upload(**{ "file": "demo.png", 'token': '${qiniu_token}' }) .validate() .assert_not_equal('body.hash', None) ) ]
class TestCaseCustomerLogin(HttpRunner): config = (Config("运行平台登录").base_url("${get_base_url()}").variables( **{ "userName": "******", "password": "******", "verifyCode": "1234", "regType": 4, }).export(*["customer_token", "customer_sessionId", "verifyId" ]).verify(False)) teststeps = [ Step( RunRequest("获取验证码").get( "/ops/api/web/getVerificationCode?").with_headers( **{ "x-app-id": "200", "x-tenant-id": "2", # "sso_sessionid": "", # "Token": "", }).extract().with_jmespath( 'body.data.verifyId', "verifyId").validate().assert_equal( "status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", "000000").assert_equal( "body.msg", "Success")), Step( RunRequest("用户登录").post("/ops/api/web/login").with_params( **{ "userName": "******", "password": "******", "verifyCode": "$verifyCode", "verifyId": "$verifyId", "regType": "$regType", }).with_headers( **{ "x-app-id": "200", "x-tenant-id": "2", "sso_sessionid": "", "Token": "", }).with_json({ "userName": "******", "password": "******", "verifyCode": "$verifyCode", "verifyId": "$verifyId", "regType": "$regType", }).extract(). with_jmespath("body.data.token", "customer_token").with_jmespath( 'body.data.sessionId', "customer_sessionId").validate().assert_equal( "status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", "000000").assert_equal("body.msg", "Success")), ]
class TestCaseValidateWithVariables(HttpRunner): config = ( Config("request methods testcase: validate with variables") .variables(**{"foo1": "session_bar1"}) .base_url("https://postman-echo.com") .verify(False) ) teststeps = [ Step( RunRequest("get with params") .with_variables(**{"foo1": "bar1", "foo2": "session_bar2"}) .get("/get") .with_params(**{"foo1": "$foo1", "foo2": "$foo2"}) .with_headers(**{"User-Agent": "HttpRunner/3.0"}) .extract() .with_jmespath("body.args.foo2", "session_foo2") .validate() .assert_equal("status_code", 200) .assert_equal("body.args.foo1", "$foo1") .assert_equal("body.args.foo2", "$foo2") ), Step( RunRequest("post raw text") .with_variables(**{"foo1": "hello world", "foo3": "$session_foo2"}) .post("/post") .with_headers( **{"User-Agent": "HttpRunner/3.0", "Content-Type": "text/plain"} ) .with_data( "This is expected to be sent back as part of response body: $foo1-$foo3." ) .validate() .assert_equal("status_code", 200) .assert_equal( "body.data", "This is expected to be sent back as part of response body: hello world-$foo3.", ) ), Step( RunRequest("post form data") .with_variables(**{"foo1": "bar1", "foo2": "bar2"}) .post("/post") .with_headers( **{ "User-Agent": "HttpRunner/3.0", "Content-Type": "application/x-www-form-urlencoded", } ) .with_data("foo1=$foo1&foo2=$foo2") .validate() .assert_equal("status_code", 200) .assert_equal("body.form.foo1", "$foo1") .assert_equal("body.form.foo2", "$foo2") ), ]
class TestCseOBE(HttpRunner): config = ( Config("OBE目标达成度分析-获取在线活动列表") .base_url("https://courseapi.tongshike.cn") .verify(False) ) # 测试输入10个正确的环节和目标时,请求成功 teststeps = [ Step( RunTestCase("获取活动ID") .call(TestCseRelationId) .export(*["textbookId1","textbookId2","textbookId3","textbookId4","textbookId5",\ "relationIdexam1","relationIdexam2","relationIdexam3","relationIdexam4","relationIdexam5","relationIdexam6","relationIdexam7","relationIdexam8","relationIdexam9","relationIdexam10",\ "relationIdstudent1","relationIdstudent2","relationIdstudent3","relationIdstudent4","relationIdstudent5","relationIdstudent6","relationIdstudent7","relationIdstudent8","relationIdstudent9","relationIdstudent10",\ "relationIdgroup1","relationIdgroup2","relationIdgroup3","relationIdgroup4","relationIdgroup5","relationIdgroup6","relationIdgroup7","relationIdgroup8","relationIdgroup9","relationIdgroup10",\ "relationIdactivity1","relationIdactivity2","relationIdactivity3","relationIdactivity4","relationIdactivity5","relationIdactivity6","relationIdactivity7","relationIdactivity8","relationIdactivity9","relationIdactivity10",\ "authorization","ocid","authorizationtea","ocidtea",\ "linkList1","linkList2","linkList3","linkList4","linkList5","linkList6","linkList7","linkList8","linkList9","linkList10",\ "outcomeList1","outcomeList2","outcomeList3","outcomeList4","outcomeList5","outcomeList6","outcomeList7","outcomeList8","outcomeList9","outcomeList10",\ "userId1","userId2","userId3","userId4","classId1","classId2" ]) ), Step( RunRequest("修改活动的所属考核环节") # 个人作业 .put("/obe/activityLink") .with_headers(**{"Content-Type": "application/json","Authorization":"${authorization}"}) .with_params(**{"relationId":"${relationIdstudent1}","type":"3","linkId":"${linkList1}"}) .validate() .assert_equal("body.message", "成功") ), Step( RunRequest("修改活动的所属考核环节") # 小组作业 .put("/obe/activityLink") .with_headers(**{"Content-Type": "application/json","Authorization":"${authorization}"}) .with_params(**{"relationId":"${relationIdgroup1}","type":"4","linkId":"${linkList1}"}) .validate() .assert_equal("body.message", "成功") ), Step( RunRequest("修改活动的所属考核环节") # 测验 .put("/obe/activityLink") .with_headers(**{"Content-Type": "application/json","Authorization":"${authorization}"}) .with_params(**{"relationId":"${relationIdactivity1}","type":"5","linkId":"${linkList1}"}) .validate() .assert_equal("body.message", "成功") ), Step( RunRequest("修改活动的所属考核环节") # 考试 .put("/obe/activityLink") .with_headers(**{"Content-Type": "application/json","Authorization":"${authorization}"}) .with_params(**{"relationId":"${relationIdexam1}","type":"2","linkId":"${linkList1}"}) .validate() .assert_equal("body.message", "成功") ) ]
class TestCaseLogin(HttpRunner): config = (Config("商家中心,商家新增授信操作").base_url("${get_base_url()}").variables( **{ "x_app_id": "200", "x_tenant_id": '2', "password": "******", "regType": 4, "userName": "******", "verifyCode": "1234", }).verify(False).export( *["token", "verifyId", "sessionId", "x_tenant_id"])) teststeps = [ Step( RunRequest("/ops/api/web/getVerificationCode").get( "/ops/api/web/getVerificationCode?").with_headers( **{ "x-app-id": "", "x-tenant-id": "", "sso_sessionid": "", "Token": "", }).extract().with_jmespath( "body.data.verifyId", "verifyId").validate().assert_equal( "status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", "000000").assert_equal( "body.msg", "Success")), Step( RunRequest("/ops/api/web/login").post( "/ops/api/web/login").with_headers( **{ "x-app-id": "", "x-tenant-id": "", "sso_sessionid": "", "Token": "", }).with_json({ "userName": "******", "password": "******", "verifyCode": "$verifyCode", "verifyId": "$verifyId", "regType": "$regType", }).extract().with_jmespath("body.data.token", "token"). with_jmespath("body.data.sessionId", "sessionId").with_jmespath( 'body.data.personDetailResDto.tenantId', "x_tenant_id").validate().assert_equal( "status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", "000000").assert_equal("body.msg", "Success")), ]
class TestCaseBasic(HttpRunner): config = Config("basic test with httpbin").base_url("https://httpbin.org/") teststeps = [ Step( RunRequest("headers").get("/headers").validate().assert_equal( "status_code", 200).assert_equal("body.headers.Host", "httpbin.org")), Step( RunRequest("user-agent").get( "/user-agent").validate().assert_equal("status_code", 200).assert_startswith( 'body."user-agent"', "python-requests")), Step( RunRequest( "get without params").get("/get").validate().assert_equal( "status_code", 200).assert_equal("body.args", {})), Step( RunRequest("get with params in url").get( "/get?a=1&b=2").validate().assert_equal("status_code", 200).assert_equal( "body.args", { "a": "1", "b": "2" })), Step( RunRequest("get with params in params field").get( "/get").with_params(**{ "a": 1, "b": 2 }).validate().assert_equal("status_code", 200).assert_equal( "body.args", { "a": "1", "b": "2" })), Step( RunRequest("set cookie").get( "/cookies/set?name=value").validate().assert_equal( "status_code", 200).assert_equal("body.cookies.name", "value")), Step( RunRequest( "extract cookie").get("/cookies").validate().assert_equal( "status_code", 200).assert_equal("body.cookies.name", "value")), Step( RunRequest("post data").post("/post").with_headers( **{ "Content-Type": "application/json" }).with_data("abc").validate().assert_equal( "status_code", 200)), Step( RunRequest("validate body length").get( "/spec.json").validate().assert_length_equal("body", 9)), ]
class TestCaseHardcode(HttpRunner): config = ( Config("request methods testcase in hardcode") .base_url("https://postman-echo.com") .verify(False) ) teststeps = [ Step( RunRequest("get with params") .get("/get") .with_params(**{"foo1": "bar1", "foo2": "bar2"}) .with_headers(**{"User-Agent": "HttpRunner/3.0"}) .validate() .assert_equal("status_code", 200) ), Step( RunRequest("post raw text") .post("/post") .with_headers( **{"User-Agent": "HttpRunner/3.0", "Content-Type": "text/plain"} ) .with_data("This is expected to be sent back as part of response body.") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("post form data") .post("/post") .with_headers( **{ "User-Agent": "HttpRunner/3.0", "Content-Type": "application/x-www-form-urlencoded", } ) .with_data("foo1=bar1&foo2=bar2") .validate() .assert_equal("status_code", 200) ), Step( RunRequest("put request") .put("/put") .with_headers( **{"User-Agent": "HttpRunner/3.0", "Content-Type": "text/plain"} ) .with_data("This is expected to be sent back as part of response body.") .validate() .assert_equal("status_code", 200) ), ]
class TestCaseValidateWithFunctions(HttpRunner): config = ( Config("request methods testcase: validate with functions").variables( **{ "foo1": "session_bar1" }).base_url("https://postman-echo.com").verify(False)) teststeps = [ Step( RunRequest("get with params").with_variables( **{ "foo1": "bar1", "foo2": "session_bar2", "sum_v": "${sum_two(1, 2)}" }).get("/get").with_params(**{ "foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v" }).with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}" }).extract().with_jmespath( "body.args.foo2", "session_foo2").validate().assert_equal( "status_code", 200).assert_equal("body.args.sum_v", "3")), ]
class TestCaseDeviceAuthActive(HttpRunner): @pytest.mark.parametrize( "param", Parameters({ "uuid-actived": "${parameterize(test_data/normal_device_data.csv)}", "status_code-ok-status-code-data": [[200, 1, "ok", 200, "active success"]], }), ) def test_start(self, param): super().test_start(param) config = Config("tange-iiCam365 激活设备").base_url("${ENV(DV_test_url)}") teststeps = [ Step( RunRequest("激活设备").post("device/auth/active").with_headers( **{ "Content-Type": "application/json" }).with_json({ "uuid": "$uuid", "actived": "$actived" }).validate().assert_equal( "status_code", "$status_code").assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.ok", "$ok").assert_equal( "body.status", "$status").assert_equal("body.code", "$code").assert_equal( "body.data", "$data")), ]
class TestCaseGetcitylist(HttpRunner): config = Config("testcase description").base_url("${ENV(BASE_URL_PRE)}").verify(False) teststeps = [ Step( RunTestCase("登录") .call(TestCaseLoginbyemailpassword) ), Step( RunRequest("获取城市列表") .get( "/3/7.5.28/bplapi/user/v1/getCityList" ) .with_headers( **{ "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 isp/unknown network/WIFI prokanqiu/7.5.28 iPhone11,6", } ) .validate() .assert_equal("status_code", 200) .assert_equal("body.status", 200) ), ]
class TestCaseRequestWithTestcaseReference(HttpRunner): config = (Config("request methods testcase: reference testcase").variables( **{ "foo1": "testsuite_config_bar1", "expect_foo1": "testsuite_config_bar1", "expect_foo2": "config_bar2", }).base_url("https://postman-echo.com").verify(False)) teststeps = [ Step( RunTestCase("request with functions").with_variables( **{ "foo1": "testcase_ref_bar1", "expect_foo1": "testcase_ref_bar1" }).setup_hook("${sleep(0.1)}").call(RequestWithFunctions). teardown_hook("${sleep(0.2)}").export(*["foo3"])), Step( RunRequest("post form data").with_variables(**{ "foo1": "bar1" }).post("/post").with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}", "Content-Type": "application/x-www-form-urlencoded", }).with_data("foo1=$foo1&foo2=$foo3").validate().assert_equal( "status_code", 200).assert_equal("body.form.foo1", "bar1").assert_equal( "body.form.foo2", "bar21")), ]
class TestCaseshttprunner(HttpRunner): config = (Config("login").base_url("https://b2.51ias.com")) teststeps = [ Step( RunRequest("login").get("/api.php").with_params( **{ "password": "******", "pid": "${ENV(pid)}", "type": "${ENV(type)}", "version": "${ENV(version)}", "username": "******", "deviceid": "${ENV(deviceid)}", "language": "${ENV(language)}", "lz": "${ENV(lz)}", "hwdeviceid": "${ENV(hwdeviceid)}", "m": "User", "a": "login", }).teardown_hook( "${WriteToEnv($response)}").extract().with_jmespath( "content.user_info.device_info.login_token", "token").with_jmespath("body.ret", "ret").validate().assert_equal( "status_code", 200).assert_equal( "body.ret", 0)), ]
class TestCaseCreate_doc(HttpRunner): """使用如下功能需要修改testcase中标记为2020.08.17新增""" _config = Config("create_doc") _conf = _config.conf() _headers_get = _config.headers_get() _headers_post = _config.headers_post() _cookies = _config.cookies() config = _config.verify(False).variables(**_conf) teststeps = [ Step( RunRequest("/api/list/create_doc") .with_variables(**{"length": "17", "referer": "https://${host}/list"}) .post("https://${host}/api/list/create_doc") .with_headers(**{"Content-Type": "${ContentType}",}, **_headers_post) .with_cookies(**_cookies) .with_data({"folderId": "0", "type": "0"}) .extract() .with_jmespath("body.data.id", "id") .validate() .assert_equal("status_code", 200) .assert_equal("body.code", 0) .assert_equal("body.msg", None) ) ]
class TestCase查看待分配订单明细(HttpRunner): config = Config("testcase description").verify(False) teststeps = [ Step( RunRequest("/wms/saleoutDetail/selectListSaleoutIdBygood.do").post( "http://api.wms.jc-test.cn/wms/saleoutDetail/selectListSaleoutIdBygood.do" ).with_headers( **{ "Accept": "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "32", "Content-Type": "application/x-www-form-urlencoded", "Host": "api.wms.jc-test.cn", "Origin": "http://pc.wms.jc-test.cn", "Referer": "http://pc.wms.jc-test.cn/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36", "loginToken": "17362313866PC269F5565F33DA9A750D44602B9A79FD7", "optDevice": "PC", }).with_data({ "reqParam": '{"id":687283}' }).validate().assert_equal("status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", 200).assert_equal("body.msg", "成功!")), ]
class TestCaseToolsSim(HttpRunner): @pytest.mark.parametrize( "param", Parameters({ "username-pwd-platform-pkgname-push_id-push_channel-version-language": "${parameterize(test_data/normal_device_bind_data.csv)}", "status_code-ok-status-code-ids": [[200, 1, "ok", 200, 0]], }), ) def test_start(self, param): super().test_start(param) config = Config("物联网卡工具页").base_url("${ENV(api_url)}") teststeps = [ Step( RunTestCase("获取登录token").call(AppUserLogin).export( *["id", "token"])), Step( RunRequest("物联网卡工具页").get( "//tools/sim?user_id=$id&version=$version&platform=$platform&pkgname=$pkgname&language=$language&token=$token" ).with_headers(**{ "Content-Type": "application/json" }).with_json(None).validate().assert_equal("status_code", "$status_code")), ]
class TestCseOBE(HttpRunner): config = (Config("OBE目标达成度分析-获取在线活动列表").base_url( "https://courseapi.tongshike.cn").verify(False)) teststeps = [ Step( RunTestCase("用户登录成功") .call(TestCseUserLogin) .export(*["authorization","ocid","authorizationtea","ocidtea",\ "linkList1","linkList2","linkList3","linkList4","linkList5","linkList6","linkList7","linkList8","linkList9","linkList10",\ "outcomeList1","outcomeList2","outcomeList3","outcomeList4","outcomeList5","outcomeList6","outcomeList7","outcomeList8","outcomeList9","outcomeList10",\ "userId1","userId2","userId3","userId4","classId1","classId2"]) ), Step( RunTestCase("获取课件ID") .call(TestCseRelationId) .export(*["textbookId2"]) ), Step( RunRequest("修改活动的关联课程目标") .put("/obe/activityOutcome") .with_headers(**{"Content-Type": "application/json","Authorization":"$authorization"}) .with_params(**{"relationId":"${textbookId2}","type":"1","outcomeId":"${outcomeList1}"}) .validate() .assert_equal("body.message", "成功") ) ]
class TestCaseshttprunner(HttpRunner): @pytest.mark.parametrize("param", Parameters({ "username-password": "******" })) def test_start(self, param): super().test_start(param) config = (Config("login").base_url("https://b2.51ias.com")) teststeps = [ Step( RunRequest("login").get("/api.php").with_params( **{ "password": "******", "pid": "${ENV(pid)}", "type": "${ENV(type)}", "version": "${ENV(version)}", "username": "******", "deviceid": "${ENV(deviceid)}", "language": "${ENV(language)}", "lz": "${ENV(lz)}", "hwdeviceid": "${ENV(hwdeviceid)}", "m": "User", "a": "login", }).extract().validate().assert_equal("status_code", 200).assert_equal( "body.ret", 0)), ]
class TestCaseUserLogin(HttpRunner): @pytest.mark.parametrize("param", Parameters( { "title": ["demo1"], "user": ["user1", "user2"], "title-user": [("demo4", "4"), ("demo5", "5"), ("dmeo6", "6")], } ), ) config = ( Config("OBE目标达成度分析-新建OBE设置信息") .variables(loginNameadmin="${ENV(LoginNameCourseAdmin)}",loginNametea="${ENV(LoginNametea)}",password="******",HOST="${ENV(TestHOST)}") .base_url("https://${HOST}") .verify(False) .export(*[]) ) teststeps = [ Step( RunRequest("用户登录成功!") .post("/users/login") .with_headers(**{"Content-Type": "application/json"}) .with_json({"loginName": "${loginNameadmin}","password": "******"}) .extract() .with_jmespath("body.authorization", "authorization") .validate() .assert_equal("status_code", 200) ) ]