介面自動化測試(使用testng,reportng,maven,jenkins)
文章記錄關鍵的幾個步驟
1.testng中使用reportng的測試報告,配置在測試檔案的xml中
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
可以通過這種方式進行引數傳遞
testng的測試xml中
<parameter name="openReport" value="true"/>
程式碼中
@BeforeSuite
@Parameters({"openReport"})
public static void beforeSuite(String openReport)
pom檔案
<properties>
<maven.filepath>PartnerEssentialtest.xml</maven.filepath>
<testip></testip>
<testport></testport>
<testpath></testpath>
</properties>
build的全部引數
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<systemPropertyVariables>
<org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
<interface.test.property.ip>${testip}</interface.test.property.ip>
<interface.test.property.port>${testport}</interface.test.property.port>
<interface.test.property.path>${testpath}</interface.test.property.path>
</systemPropertyVariables>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<suiteXmlFiles>
<suiteXmlFile>${project.basedir}\testcase\${maven.filepath}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
jenkins 中增加
reportng的原始碼中新增了 可以縮放的功能, 顯示json串的時候可以收縮
reportng.js
增加
function zoom(e)
{
var div = e.nextSibling;
if(div.style.display=='none')
{
div.style.display='block';
e.innerText='Response: - ';
}else
{
div.style.display='none';
e.innerText='Response: { ..... } ';
}
}
java程式碼中 增加
Reporter.log("<pre ><div onclick=zoom(this)>Response: { ..... } </div><div name='json' style='display:none;'>" + res + "</div></pre>");