Bug 40696

Summary: retieve all embeded resources from html pages for CSS images
Product: JMeter - Now in Github Reporter: Cristian Olaru <colaru>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: other   
URL: http://www.nabble.com/retieve-all-embeded-resources-from-html-pages-tf2395397.html

Description Cristian Olaru 2006-10-06 06:56:14 UTC
The problem is this. 

I make assyncrniuos reqests to server and I obtain a list of html div elemnts. 
In a call back method I render this divs in pages. 

I try to test my application with jmeter. I check the option 'Retrieve All 
Embeded Resources from HTML Pages' for make request to my resources. 

Nothing hapened. I change all the parsers in jmeter.properties. I think the 
problem is the way i define the image using CSS - 'background:url'. or is 
because mai responce is not a xhtml valid, just a list of div's. 

An example of some html div response: 

<div class="graph" style="width:275px;height:166px;background:url
('/ews/ewsGetImage.act?id=1160139636046-
distributionByDevice&imageType=DISTRIBUTION_GRAPHIC') no-repeat ;"  ></div>
Comment 1 Alf Hogemark 2007-02-27 05:59:16 UTC
The problem is not that the response is not valid xhtml.

The reason is that the parser that parses the response and looks for embedded
resources, does not look for constructs like <anytag
style="background:url('someurl')"/>.

I am not sure if the parser should look for such embedded resources. If the
stylesheet file references any resources, those will not be downloaded by
jmeter, because jmeter only downloads any stylesheet files referenced, it does
not parse the downloaded stylesheet files and then download all resources
referenced by the stylesheet file.

So if there should be no difference between resources mentioned inside
stylesheet files and resouces mentioned in inline style of the actual document,
then I think this bug should be closed as "invalid".

If you want resources mentioned in inline styling of the document, then the
following code could be added to the bottom of the "parseNodes" method of the
"HtmlParserHTMLParser" seems to do the work :

            String styleTagStr = tag.getAttribute("STYLE");
            if(styleTagStr != null) {
                PatternCompiler compiler = new Perl5Compiler();
                PatternMatcher matcher = new Perl5Matcher();
                Pattern pattern = null;
                PatternMatcherInput input = null;
                try {
                    pattern = compiler.compile("URL\\(('|\")(.*)('|\")\\)", 
                        Perl5Compiler.CASE_INSENSITIVE_MASK |
Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK);
                    input = new PatternMatcherInput(styleTagStr);
                    while (matcher.contains(input, pattern)) {
                        MatchResult match = matcher.getMatch();
                        // The value is in the second group
                        String styleUrl = match.group(2);
                        urls.addURL(styleUrl, baseUrl.url);
                    }
                } catch (MalformedPatternException mpe) {
                    log.warn("Malformed pattern for getting url of style
attribute of a tag");
                }
            }            
Comment 2 Sebb 2007-02-27 07:14:17 UTC
Agreed that JMeter should not parse the content of CSS files when looking for 
embedded resources. [This could be quite tricky, as the CSS file can contain 
definitions that are not used.]

However, if the background image is part of a style attribute in the HTML page 
itself, then it seems sensible to treat this the same as other background 
images.

I'll see about adding this.

Note: there are two related issues: bug 40933 and bug 40945.
Comment 3 Sebb 2007-03-03 03:30:47 UTC
Now fixed in SVN. 

It will be in the next release and the next nightly build at:

http://people.apache.org/builds/jakarta-jmeter/nightly/
Comment 4 The ASF infrastructure team 2022-09-24 20:37:38 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1805