now, i can get the static resources' absolute uri.
Next step, i will create appropriate childrenUrl, and put it into the ScriptAdapter. The key point is to get the parent's batch id.
This commit is contained in:
parent
cfe5512763
commit
d2784c7f7d
|
@ -347,7 +347,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
||||||
|
|
||||||
if (contentType.toLowerCase().compareTo("text/html") == 0) {
|
if (contentType.toLowerCase().compareTo("text/html") == 0) {
|
||||||
doTidyCode(HttpTestCase.staticUrlDecode(header.url));
|
doTidyCode(HttpTestCase.staticUrlDecode(header.url));
|
||||||
doParseHtmlContent(respStr);
|
doParseHtmlContent(respStr, header.url);
|
||||||
if (cpRspToStdout)
|
if (cpRspToStdout)
|
||||||
doResponseForStdOut(HttpTestCase.staticUrlDecode(
|
doResponseForStdOut(HttpTestCase.staticUrlDecode(
|
||||||
header.url).trim());
|
header.url).trim());
|
||||||
|
@ -425,7 +425,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
||||||
public abstract void doTidyCode(String paramString)
|
public abstract void doTidyCode(String paramString)
|
||||||
throws Utils.UserException;
|
throws Utils.UserException;
|
||||||
|
|
||||||
public abstract void doParseHtmlContent(String responseContent);
|
public abstract void doParseHtmlContent(String responseContent, String url);
|
||||||
|
|
||||||
public abstract void doHeaders(HeaderValue[] paramArrayOfHeaderValue);
|
public abstract void doHeaders(HeaderValue[] paramArrayOfHeaderValue);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||||
import org.bench4q.share.models.agent.scriptrecord.UserBehaviorModel;
|
import org.bench4q.share.models.agent.scriptrecord.UserBehaviorModel;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
|
@ -46,9 +47,9 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
private int unit = 1;
|
private int unit = 1;
|
||||||
private static Logger logger = Logger.getLogger(Bench4qCodeGenerator.class);
|
private static Logger logger = Logger.getLogger(Bench4qCodeGenerator.class);
|
||||||
// FOR TEST
|
// FOR TEST
|
||||||
public Elements linkElements;
|
public Elements links;
|
||||||
public Elements imgElements;
|
public Elements medias;
|
||||||
public Elements scriptElements;
|
public Elements imports;
|
||||||
|
|
||||||
private static String escapeXmlString(String str) {
|
private static String escapeXmlString(String str) {
|
||||||
for (int i = 0; i < escapes.length; ++i)
|
for (int i = 0; i < escapes.length; ++i)
|
||||||
|
@ -202,7 +203,7 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doParseHtmlContent(String responseContent) {
|
public void doParseHtmlContent(String responseContent, String url) {
|
||||||
// Fulfill it here, extract the dom and static resources
|
// Fulfill it here, extract the dom and static resources
|
||||||
int htmlStart = responseContent.indexOf("<html>");
|
int htmlStart = responseContent.indexOf("<html>");
|
||||||
int htmlEnd = responseContent.indexOf("</html>");
|
int htmlEnd = responseContent.indexOf("</html>");
|
||||||
|
@ -211,12 +212,21 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
}
|
}
|
||||||
String htmlContent = responseContent.substring(htmlStart, htmlEnd + 8);
|
String htmlContent = responseContent.substring(htmlStart, htmlEnd + 8);
|
||||||
Document document = Jsoup.parse(htmlContent);
|
Document document = Jsoup.parse(htmlContent);
|
||||||
Elements linkElements = document.getElementsByTag("link");
|
document.setBaseUri(url);
|
||||||
Elements imgElements = document.getElementsByTag("img");
|
Elements links = document.select("a[href]");
|
||||||
Elements scriptElements = document.getElementsByTag("script");
|
Elements medias = document.select("[src]");
|
||||||
this.linkElements = linkElements;
|
Elements imports = document.select("link[href]");
|
||||||
this.imgElements = imgElements;
|
this.links = links;
|
||||||
this.scriptElements = scriptElements;
|
this.medias = medias;
|
||||||
|
this.imports = imports;
|
||||||
|
for (Element element : medias) {
|
||||||
|
String childAbsoluteUrl = element.absUrl("src");
|
||||||
|
this.getScriptAdapter().getChildrenUrls()
|
||||||
|
.add(ChildrenUrl.createChilldUrl(childAbsoluteUrl, 0));
|
||||||
|
System.out.println(childAbsoluteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.getScriptAdapter().getChildrenUrls().add()
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doResponseForStdOut(String url) {
|
public void doResponseForStdOut(String url) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ChildrenUrl {
|
||||||
this.parentBatchId = parentBatchId;
|
this.parentBatchId = parentBatchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChildrenUrl createChilldUrl(String url, int parentBatchId) {
|
public static ChildrenUrl createChilldUrl(String url, int parentBatchId) {
|
||||||
ChildrenUrl ret = new ChildrenUrl();
|
ChildrenUrl ret = new ChildrenUrl();
|
||||||
ret.setParentBatchId(parentBatchId);
|
ret.setParentBatchId(parentBatchId);
|
||||||
ret.setUrl(url);
|
ret.setUrl(url);
|
||||||
|
|
|
@ -23,14 +23,18 @@ public class TestDomGenerator {
|
||||||
@Test
|
@Test
|
||||||
public void testDomParser() throws IOException {
|
public void testDomParser() throws IOException {
|
||||||
URL url = this.getClass().getResource("testcase.html");
|
URL url = this.getClass().getResource("testcase.html");
|
||||||
System.out.println(url.getPath());
|
|
||||||
this.getCodeGenerator().doParseHtmlContent(
|
this.getCodeGenerator().doParseHtmlContent(
|
||||||
FileUtils.readFileToString(new File(url.getPath())));
|
FileUtils.readFileToString(new File(url.getPath())),
|
||||||
assertNotNull(this.getCodeGenerator().imgElements);
|
"http://localhost:8080/Bench4QTestCase/testcase.html");
|
||||||
assertNotNull(this.getCodeGenerator().linkElements);
|
assertNotNull(this.getCodeGenerator().medias);
|
||||||
assertNotNull(this.getCodeGenerator().scriptElements);
|
assertNotNull(this.getCodeGenerator().links);
|
||||||
assertTrue(this.getCodeGenerator().imgElements.size() == 3);
|
assertNotNull(this.getCodeGenerator().imports);
|
||||||
assertTrue(this.getCodeGenerator().linkElements.size() == 3);
|
assertTrue(this.getCodeGenerator().medias.size() == 5);
|
||||||
assertTrue(this.getCodeGenerator().scriptElements.size() == 2);
|
assertTrue(this.getCodeGenerator().links.size() == 0);
|
||||||
|
assertTrue(this.getCodeGenerator().imports.size() == 3);
|
||||||
|
|
||||||
|
assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls()
|
||||||
|
.size() == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue