上海线下接口测试进阶课总结

主要回顾

上节课主要学习了:

1,测试工具使用进阶(PostMan/JsonPath)
2,接口自动化用例设计与实现
接口自动化项目实战
接口自动化框架原理介绍
接口自动化的使用

###基础自动化用力编写总结

 
    @Test
    public void testCase() throws Exception {
        Log.logs("CaseName:登录创建Bug->搜索获取bugId->检查Bug是否创建");
        String bug_title="testBug-"+System.currentTimeMillis();
        String description ="test";
        JSONObject json= Commons.createBug( bug_title, version_id, module_id,  description , project_id,httpGet);
        if(json.getString("message").equals("添加成功")){
            Log.logs("response:"+json.toString());
            JSONObject searchBug= Commons.searchBug( project_strId, bug_title, 0);
            Log.logs("response:"+searchBug.toString());
            if(searchBug.get("data")!=null){
                Log.logs("Bug 创建成功 BugId:"+ JsonPath.JsonPath(searchBug.toString(),"$.data[0].bug_id"));
                Log.logs("用例执行成功");
            }else{
                Log.logs("用例执行失败");
            }
        }else{
            Log.logs("用例执行失败");
        }
    }

Common封装:

package Common;

import Trigger.httpclient;
import net.sf.json.JSONObject;

public class Commons {
\tprivate String url="";
\t
\tpublic String geturl() {
\t\treturn url;
\t}

\t/**
\t *
\t * @param bug_title
\t * @param version_id
\t * @param module_id
\t * @param description
\t * @param project_id
     * @return
     * @throws Exception
     */
\tpublic static  JSONObject createBug(String bug_title,int version_id,int module_id,String description ,String project_id,httpclient httpGet)  {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/save-bug.do";
\t\tString Parameter="bug_title="+bug_title+"&version_id="+version_id+"&module_id="+module_id+"&priority=1&handle_member_id=610&description="+description+"&project_id="+project_id;
\t\tJSONObject json=httpGet.sendPost(Url,Parameter);
\t\treturn json;
\t}




\t/**
\t *
\t * @param bug_title
\t * @param version_id
\t * @param module_id
\t * @param description
\t * @param project_id
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject editBug(String bug_title,int version_id,int module_id,String description ,String project_id,String bug_id,httpclient httpGet)  {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/edit-bug.do";
\t\tString Parameter="bug_title="+bug_title+"&version_id="+version_id+"&module_id="+module_id+"&priority=1&description="+description+"bug_id="+bug_id+"&pid="+project_id;
\t\tJSONObject json=httpGet.sendPost(Url,Parameter);
\t\treturn json;
\t}





\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject getBugList(String projectId) throws Exception {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/get-my-create.do";
\t\tString Parameter="projectId="+projectId;
\t\thttpclient httpGet= new  httpclient();
\t\tJSONObject json=httpGet.sendGet(Url,Parameter);
\t\treturn json;
\t}


\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject getAssignorme(String projectId) throws Exception {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/get-assign-for-me.do";
\t\tString Parameter="projectId="+projectId;
\t\thttpclient httpGet= new  httpclient();
\t\tJSONObject json=httpGet.sendGet(Url,Parameter);
\t\treturn json;
\t}


\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject searchBug(String projectId,String keyword,int last_status) throws Exception {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/get-all-bug.do";
\t\tString Parameter="projectId="+projectId+"&keyword="+keyword+"&priority=0&last_status="+last_status+"&create_member_id=0&handle_member_id=0&module_id=0&version_id=0";
\t\thttpclient httpGet= new  httpclient();
\t\tJSONObject json=httpGet.sendGet(Url,Parameter);
\t\treturn json;
\t}

\t/**
\t *
\t * @param status
\t * @param handle_id
\t * @param description
\t * @param BugId
\t * @param assign_id
\t * @return
     * @throws Exception
     */
\tpublic static  JSONObject updateBugState(String status,String handle_id,String description,int  BugId,int  assign_id) {
\t\tString Url="http://www.hibug.cn/api/ebugs/project-bug/assign.do";
\t\tString Parameter="status="+status+"&handle_id="+handle_id+"&description="+description+"editor1=&bug_id="+BugId+"&assign_id="+assign_id;
\t\thttpclient httpGet= new  httpclient();
\t\tJSONObject json=httpGet.sendPost(Url,Parameter);
\t\treturn json;
\t}



\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject addVersion(String project_id,String  version_name)  {
\t\tString Url="http://www.hibug.cn/api/ebugs/project/add-version.do";
\t\tString Parameter="project_id="+project_id+"&version_name="+version_name;
\t\thttpclient httpGet= new  httpclient();
\t\tJSONObject json=httpGet.sendPost(Url,Parameter);
\t\treturn json;
\t}






\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject login(String email,String password,httpclient httpGet)  {
\t\tString Url="http://www.hibug.cn/api/ebugs/member/login.do";
\t\tString Parameter="email="+email+"&password="+password;
\t\tJSONObject json=httpGet.sendPost(Url,Parameter);
\t\treturn json;
\t}


\t/**
\t *
\t * @return
\t * @throws Exception
\t */
\tpublic static  JSONObject loginOut(httpclient httpGet) throws Exception {
\t\tString Url=" http://www.hibug.cn/api/ebugs/member/logout.do";
\t\tString Parameter="";
\t\tJSONObject json=httpGet.sendGet(Url,Parameter);
\t\treturn json;
\t}
}


###框架设计回顾


作业

大家通过 testNG+ ReportNG 两种方式把这后面两个用例写好
另外大家使用自动化框架的模式也写一个demo的数据文件(类似框架的 workspace目录下的 demo文件的写法)

下节课我们讲源码的细节,大家提前熟悉使用哈 加油哈

关闭