顺德网站优化公司,温江建设网站,沈阳网站制作公司,怎么查看网站的ftp#x1f345; 点击文末小卡片#xff0c;免费获取软件测试全套资料#xff0c;资料在手#xff0c;涨薪更快一、原理及特点参数放在XML文件中进行管理用httpClient简单封装一个httpUtils工具类测试用例管理使用了testNg管理#xff0c;使用了TestNG参数化测试#xff0c;…点击文末小卡片免费获取软件测试全套资料资料在手涨薪更快一、原理及特点参数放在XML文件中进行管理用httpClient简单封装一个httpUtils工具类测试用例管理使用了testNg管理使用了TestNG参数化测试通过xml文件来执行case。测试报告这里用到第三方的包ReportNG 项目组织用Maven二、准备使用工具eclipse,maven用到的第三方jar包dom4j、reportng、testng理解难点httpUtils和xmlUtil工具类的封装dom4j使用CookieStore的应用三、框架构思1、项目结构2、用例执行流程3、接口调用流程4、调度脚本流程四、框架实现1、输入参数1.1 参数放在XML文件中进行管理例这里测试获取角色的接口输入参数为page和rowsmapRole.xml内容如下?xml version1.0 encodingUTF-8? map bean beanNameGetRole !--Locator lists -- locator namepage value1/locator locator namerows value10/locator /bean /map1.2 封装一个xmlUtil工具类负责读取XML,使用第三方的jar包dom4j1.2.1 xmlUtil中readXMLDocument方法返回值为HashMapString, Stringpublic static HashMapString, String readXMLDocument(String beanName,String xmlName){ }2、返回参数2.1 创建一个接口返回对象ResponseBean对象ResponseBean包括status、statusCode、contentType、body、url、method、cookies2.2 在工具类中在创建一个ReponseUtil工具类ReponseUtil工具类负责将请求的返回数据CloseableHttpResponse 转换成ResponseBeanpublic ResponseBean setResponseBean(CloseableHttpResponse httpResponse) { }3、测试用例测试用例管理使用了TestNG管理 使用了TestNG参数化测试通过xml文件来执行case3.1 测试case脚本public class GetRoleTest { static CookieStore cookieStore ; static CookieUtil cookieUtilnew CookieUtil() ; CloseableHttpClient client; HttpUtils httpUtilsHttpUtils.getInstance(); Parameters({ url, objBean ,statusCode,xmlName}) BeforeSuite /* * 登录进入系统获取JSESSIONID放入到CookieStore中 * */ public void TestLoginIn(String url ,String objBean, String statusCode,String xmlName) { MapString,String paramsxmlUtil.readXMLDocument(objBean,xmlName); client HttpClients.createDefault(); CloseableHttpResponse httpResponse httpUtils.post(url, params, client, cookieStore); //cookieUtil.printResponse(httpResponse); cookieStorecookieUtil.setCookieStore(httpResponse); } Parameters({ url, objBean ,statusCode,body,xmlName}) Test(priority 2) public void TestGetRole(String url ,String objBean, String statusCode,String body,String xmlName) { MapString,String paramsxmlUtil.readXMLDocument(objBean,xmlName); client HttpClients.custom().setDefaultCookieStore(cookieStore).build(); CloseableHttpResponse httpResponse httpUtils.post(url, params, client, cookieStore); ResponseBean rbnew ReponseUtil().setResponseBean(httpResponse); // add Assert Assert.assertEquals(OK, rb.getStatus()); Assert.assertEquals(statusCode, rb.getStatusCode()); Assert.assertEquals(true, rb.getBody().contains(body)); } AfterSuite public void closeClient(){ try { // 关闭流并释放资源 client.close(); } catch (IOException e) { e.printStackTrace(); } } }[注] 因为API接口测试时每次都要校验Cookie所有我们每次都先执行登录操作去获取Cookie3.2 xml文件的编写?xml version1.0 encodingUTF-8? !DOCTYPE suite SYSTEM http://testng.org/testng-1.0.dtd suite nameTestGetRole parallelclasses thread-count5 parameter nameurl value/sys/login / parameter nameobjBean valueloginIn / parameter namestatus valueOK / parameter namestatusCode value200 / parameter namexmlName valuemapRole / test nameTestGetRole preserve-ordertrue parameter nameurl value/json/getRoleInfo / parameter nameobjBean valueGetRole / parameter namestatus valueOK / parameter namestatusCode value200 / parameter namebody valueroleName / classes class namecom.lc.testScript.GetRoleTest methods include nameTestGetRole / !--include nameTestGetRole2 /-- /methods /class /classes /test /suite右键-run as -TestNG Suite,这个场景的的测试用例就可以运行了4、测试报告和项目组织测试报告这里用到第三方的包ReportNG 项目组织用Mavenproject xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd modelVersion4.0.0/modelVersion .......................................... .......................................... .......................................... properties project.build.sourceEncodingUTF-8/project.build.sourceEncoding xmlFileName1TestGetRole.xml/xmlFileName .................这里写testNG对应的XML名称---------------------- xmlFileName10TestGetUser.xml/xmlFileName /properties dependencies .......................... /dependencies build plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-surefire-plugin/artifactId version2.19/version configuration suiteXmlFiles suiteXmlFilesrc/test/java/testSuites/${xmlFileName}/suiteXmlFile .................略............ ..............这里的和properties中的xmlFileName想对应............ suiteXmlFilesrc/test/java/testSuites/${xmlFileName10}/suiteXmlFile /suiteXmlFiles /configuration /plugin !-- 添加插件,添加ReportNg的监听器修改最后的TestNg的报告 -- plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-surefire-plugin/artifactId version2.5/version configuration properties property nameusedefaultlisteners/name valuefalse/value /property property namelistener/name valueorg.uncommons.reportng.HTMLReporter/value /property /properties workingDirectorytarget//workingDirectory /configuration /plugin plugin artifactIdmaven-compiler-plugin/artifactId version3.5.1/version configuration source1.8/source target1.8/target /configuration /plugin /plugins /build /project[注] 因为是maven的项目所以要将testSuite的xml文件放在maven的test目录下这样右键pom.xml文件maven test,所有的测试用例就开始执行了测试报告框架目前存在的不足。最后感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走这些资料对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴我走过了最艰难的路程希望也能帮助到你凡事要趁早特别是技术行业一定要提升技术功底。