Commit 56fff698 authored by 马博's avatar 马博

fix-参数化,重试机制统计不准的问题

parent e496df78
......@@ -318,6 +318,7 @@
<maxRetryCount>0</maxRetryCount>
<ServiceDoctor>false</ServiceDoctor>
<Server>false</Server>
<sendMiria>false</sendMiria>
</systemPropertyVariables>
</configuration>
......
......@@ -42,7 +42,7 @@ public class DingdingResult {
logger.info("属性:"+System.getProperties());
Map<String,String> changeMap=null;
group = duibaGroup.split(",");
changeMap = BeTested.getLatestChanges(duibaGroup.split(","));
// changeMap = BeTested.getLatestChanges(duibaGroup.split(","));
project = "duiba-service";
......@@ -53,9 +53,13 @@ public class DingdingResult {
names.addAll(Arrays.asList(getNames));
Map<String,String> params = new HashMap<>();
params.put("jobName",getJob());
changes = Postman.sendFindTestApp(params);
boolean sendMiria = Boolean.parseBoolean(System.getProperty("sendMiria"));
if(sendMiria){
Map<String,String> params = new HashMap<>();
params.put("jobName",getJob());
changes = Postman.sendFindTestApp(params);
}
GitlabProjectMerges gitlabProjectMerges = GitlabUtils.getMessage("credits-group",changes);
changes = changes+" 提交者:"+gitlabProjectMerges.getAuthor().getName()+" 描述:"+gitlabProjectMerges.getDescription();
......
......@@ -72,10 +72,10 @@ public class MysqlConnPool {
map = new HashMap<String, Object>();
int index = 1;
log.info("bds!=null");
// log.info("bds!=null");
PreparedStatement pstmt = conn.prepareStatement(sql);
log.info("conn!=null");
log.info(conn.toString());
// log.info("conn!=null");
// log.info(conn.toString());
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
......
......@@ -14,6 +14,7 @@ public class RetryToRunCase implements IRetryAnalyzer {
retryCount++;
return true;
}
retryCount = 0;
return false;
}
......
......@@ -2,10 +2,7 @@ package base;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
......@@ -21,25 +18,70 @@ public class TestListener implements ITestListener {
String run = System.getProperty("run");
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
Environment env=context.getBean(Environment.class);
boolean sendMiria = Boolean.parseBoolean(System.getProperty("sendMiria"));
public TestListener() throws UnsupportedEncodingException {
}
public void onFinish(ITestContext context) {
Iterator<ITestResult> listOfFailedTests = context.getFailedTests().getAllResults().iterator();
while (listOfFailedTests.hasNext()) {
ITestResult failedTest = listOfFailedTests.next();
ITestNGMethod method = failedTest.getMethod();
if (context.getFailedTests().getResults(method).size() > 1) {
listOfFailedTests.remove();
logger.info("context.getFailedTests().getResults(method).size() > 1");
// Iterator<ITestResult> listOfFailedTests = context.getFailedTests().getAllResults().iterator();
// while (listOfFailedTests.hasNext()) {
// ITestResult failedTest = listOfFailedTests.next();
// ITestNGMethod method = failedTest.getMethod();
// if (context.getFailedTests().getResults(method).size() > 1) {
// listOfFailedTests.remove();
// logger.info("context.getFailedTests().getResults(method).size() > 1");
// } else {
// if (context.getPassedTests().getResults(method).size() > 0) {
// listOfFailedTests.remove();
// logger.info("context.getPassedTests().getResults(method).size() > 0");
// }
// }
// }
// super.onFinish(testContext);
// List of test results which we will delete later
ArrayList<ITestResult> testsToBeRemoved = new ArrayList<ITestResult>();
// collect all id's from passed test
Set<Integer> passedTestIds = new HashSet<Integer>();
for (ITestResult passedTest : context.getPassedTests().getAllResults()) {
logger.info("PassedTests = " + passedTest.getName());
passedTestIds.add(getId(passedTest));
}
Set<Integer> failedTestIds = new HashSet<Integer>();
for (ITestResult failedTest : context.getFailedTests().getAllResults()) {
logger.info("failedTest = " + failedTest.getName());
// id = class + method + dataprovider
int failedTestId = getId(failedTest);
// if we saw this test as a failed test before we mark as to be
// deleted
// or delete this failed test if there is at least one passed
// version
if (failedTestIds.contains(failedTestId) || passedTestIds.contains(failedTestId)) {
testsToBeRemoved.add(failedTest);
} else {
if (context.getPassedTests().getResults(method).size() > 0) {
listOfFailedTests.remove();
logger.info("context.getPassedTests().getResults(method).size() > 0");
}
failedTestIds.add(failedTestId);
}
}
// finally delete all tests that are marked
for (Iterator<ITestResult> iterator = context.getFailedTests().getAllResults().iterator(); iterator
.hasNext();) {
ITestResult testResult = iterator.next();
if (testsToBeRemoved.contains(testResult)) {
logger.info("Remove repeat Fail Test: " + testResult.getName());
iterator.remove();
}
}
}
private int getId(ITestResult result) {
int id = result.getTestClass().getName().hashCode();
id = id + result.getMethod().getMethodName().hashCode();
id = id + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0);
return id;
}
// Following are all the method stubs that you do not have to implement
......@@ -88,15 +130,17 @@ public class TestListener implements ITestListener {
}
//运行开始,触发互斥功能,用于定时任务
Map<String,String> mapJob = new HashMap<>();
if(sendMiria){
Map<String,String> mapJob = new HashMap<>();
try {
mapJob.put("jobName",getJob());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
mapJob.put("jobName",getJob());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Postman.sendTesting(mapJob);
Postman.sendTesting(mapJob);
}
}
public void serviceDoctor(){
logger.info("duiba-server开始检测");
......
......@@ -64,6 +64,8 @@ public class TestReport implements IReporter{
boolean noticeDD=Boolean.parseBoolean(System.getProperty("noticeDD"));
boolean noticePerson=Boolean.parseBoolean(System.getProperty("noticePerson"));
boolean sendPlatform=Boolean.parseBoolean(System.getProperty("sendPlatform"));
boolean sendMiria = Boolean.parseBoolean(System.getProperty("sendMiria"));
Gson gson=new GsonBuilder().create();
......@@ -78,13 +80,15 @@ public class TestReport implements IReporter{
System.out.println("测试结果通知信息:"+gson.toJson(map));
//触发回调结束服务构建互斥
Map<String,String> mapJob = new HashMap<>();
try {
mapJob.put("jobName",ddResult.getJob());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
if(sendMiria){
Map<String,String> mapJob = new HashMap<>();
try {
mapJob.put("jobName",ddResult.getJob());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Postman.sendFinish(mapJob);
}
Postman.sendFinish(mapJob);
//发送运行结果到自动化数据收集平台
if(sendPlatform)
Postman.sendTestPlatform(map);
......
package ui.cases;
import base.DuibaBaseUi;
import base.DuibaBases;
import base.DuibaLog;
import com.codeborne.selenide.WebDriverRunner;
import com.codeborne.selenide.testng.ScreenShooter;
......@@ -13,6 +14,7 @@ import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import ui.common.ProxyFactory;
......@@ -35,72 +37,20 @@ import static com.codeborne.selenide.Selenide.open;
* Created by mabo on 2018/10/18
*/
//@Listeners({ ScreenShooter.class})
public class test extends DuibaBaseUi {
// StatusCheckor checkor=new StatusCheckor();
// WebDriver driver= WebDriverFactory.createWebDriver(WebDriverType.CHRMOE, ProxyFactory.createProxy());
@Test
public void 中文() throws IOException {
ScreenShooter.captureSuccessfulTests = true;
//StatusCheckor checkor=new StatusCheckor();
// ProxyFactory.addCheckor(checkor);
// WebDriverRunner.setWebDriver(driver);
open("https://www.baidu.com");
Reporter.log("----------------------");
screenshot();
Reporter.log("----------------------");
$(By.id("kw")).setValue("selenium");
Assert.assertEquals(1,2);
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //转换时间格式
// String time = dateFormat.format(Calendar.getInstance().getTime()); //获取当前时间
public class test extends DuibaBases {
@Test(dataProvider = "dp")
// @Test(retryAnalyzer = MyRetryAnalyzer.class,dataProvider = "dp")
public void f(Integer n, String s) {
System.out.println("ssssss:" + s);
Assert.assertFalse(true);
}
@Test
public void test1() throws SQLException {
Map<String,Object> map = jdbc.findSimpleResult("select * from act_com_conf.tb_bet_group_relation where bet_id = 1232");
@DataProvider
public Object[][] dp() {
return new Object[][] { new Object[] { 1, "a" }, new Object[] { 2, "b" },new Object[] { 3, "c" },new Object[] { 4, "d" } };
}
@Test
public void test2(){
Reporter.log("rererfddfdfdfdfdfdf");
Reporter.log("rererfddfdfdfdfdfdf");
Reporter.log("rererfddfdfdfdfdfdf");
Reporter.log("rererfddfdfdfdfdfdf");
Reporter.log("rererfddfdfdfdfdfdf");
Reporter.log("rererfddfdfdfdfdfdf");
Assert.assertEquals(1,2);
}
// @AfterMethod(alwaysRun = true)
// public void afterMethod(ITestResult result) throws Exception {
// if (!result.isSuccess())
// catchExceptions(result);
// }
// public void catchExceptions(ITestResult result) throws IOException {
// File file = new File("C:/image");
// Reporter.setCurrentTestResult(result);
// Reporter.log(file.getAbsolutePath());
// String time = String.valueOf(System.currentTimeMillis());
// Reporter.log("<img src='" + "http://172.16.80.106" + "/" + result.getName() +"_"+time+ ".jpg' hight='600' width='600'/>");
// File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //执行屏幕截取
// FileUtils.copyFile(srcFile, new File(file.getAbsolutePath() + "/" + result.getName() +"_"+time+ ".jpg"));
//
// }
//
// public static void main(String[] args) {
// System.out.println(System.currentTimeMillis());
// System.out.println(Calendar.getInstance().getTimeInMillis());
// System.out.println(new Date().getTime());
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment