diff --git a/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/AbstractCodeGenerator.java b/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/AbstractCodeGenerator.java index 82471592..467de1fe 100644 --- a/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/AbstractCodeGenerator.java +++ b/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/AbstractCodeGenerator.java @@ -330,7 +330,8 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator, return; } - String respStr = new String(response).toLowerCase(); + String responseWithProperCase = new String(response); + String respStr = responseWithProperCase.toLowerCase(); String respCode = parseResponseCode(respStr); String contentType = parseContentType(respStr); @@ -347,7 +348,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator, if (contentType.toLowerCase().compareTo("text/html") == 0) { doTidyCode(HttpTestCase.staticUrlDecode(header.url)); - doParseHtmlContent(respStr, header.url); + doParseHtmlContent(responseWithProperCase, header.url); if (cpRspToStdout) doResponseForStdOut(HttpTestCase.staticUrlDecode( header.url).trim()); diff --git a/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/Bench4qCodeGenerator.java b/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/Bench4qCodeGenerator.java index 3f21107f..0d1078a7 100644 --- a/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/Bench4qCodeGenerator.java +++ b/src/main/java/org/bench4q/master/scriptrecord/httpcapture/generator/Bench4qCodeGenerator.java @@ -218,11 +218,15 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator { childAbsoluteUrl = element.absUrl("href"); } System.out.println(childAbsoluteUrl); + int parentBatchId = this.getScriptAdapter() + .getParentBatchIdWithParentUrl(rootUrl); + if (parentBatchId == -1) { + continue; + } this.getScriptAdapter() .getChildrenUrls() .add(ChildrenUrl.createChilldUrl(childAbsoluteUrl, - this.getScriptAdapter() - .getParentBatchIdWithParentUrl(rootUrl))); + parentBatchId)); } } diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java b/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java index e20442b0..8ca70307 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java +++ b/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java @@ -19,13 +19,17 @@ public class TestDomGenerator extends TestRecordBase { @Test public void testDomParser() throws IOException { + this.getCodeGenerator() + .getScriptAdapter() + .insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); this.getCodeGenerator().doParseHtmlContent( FileUtils.readFileToString(new File(url.getPath())), parentUrl); assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() .size() == 8); for (ChildrenUrl childrenUrl : this.getCodeGenerator() .getScriptAdapter().getChildrenUrls()) { - assertTrue(childrenUrl.getParentBatchId() == -1); + assertTrue(childrenUrl.getParentBatchId() == 0); } } @@ -47,4 +51,21 @@ public class TestDomGenerator extends TestRecordBase { assertTrue(childrenUrl.getParentBatchId() == 1); } } + + @Test + public void testDomParserWithIncorrectParentUrl() throws IOException { + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getCodeGenerator().doParseHtmlContent( + FileUtils.readFileToString(new File(this.url.getPath())), + parentUrl + "error"); + assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() + .size() == 0); + } + + public void testChildUrlWithNotProperCase() { + + } } diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java b/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java index b95b97c5..93d8e9d4 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java +++ b/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java @@ -15,6 +15,7 @@ public abstract class TestRecordBase { private Bench4qCodeGenerator codeGenerator; protected static String parentUrl = "http://localhost:8080/Bench4QTestCase/testcase.html"; protected static String independentUrl = "www.baidu.com"; + protected static String childrenUrl1 = "http://localhost:8080/Bench4QTestCase/script/agenttable.js"; protected IScriptAdapter getAdpater() { return adapter;