Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I have been given the task of validating that we do not have any http:// URLs in our CSS or HTML documents. I've created a selenium IDE test that looks at src & href attributes as well as script tags for http: but I'm not sure how to test a style sheet.

As I'm not trying to test specific selectors, it could be in any attribute in the document. For instance, a random div tags background:

I've thought about putting this in java and attempting to pull resources and parse them, but that seems a bit over the top.

share|improve this question
    
Welcome to SQA, Lucas. Do you need to worry about Javascript-induced changes, or is a static analysis good enough? –  user246 Dec 11 '12 at 17:50
    
JavaScript would be nice to have, but not necessary. –  Lucas Holt Dec 11 '12 at 18:05
    
How about creating a simple script in bash/Perl that lists all occurences of such incorrect resources? e.g. cat *.css | grep 'http://'? –  dzieciou Dec 11 '12 at 18:07
    
Unfortunately, I don't have access to the flat files because they're a resource served as part of a custom CMS product for university giving. As users change the CSS, the URL to the CSS changes. Otherwise, that's a great idea. –  Lucas Holt Dec 11 '12 at 18:13
add comment

1 Answer 1

up vote 4 down vote accepted

You can create a regular expression for URLs (you should be able to find a few online), and search for the pattern in your HTML or CSS file. You just need to read the file in to a String (break it if the file is too long), and try pattern matching. You can do this without the overhead of Selenium or any other testing tool if you are familiar with either of Perl, Python, Bash, Ruby, etc. or just use Java.

share|improve this answer
    
Interesting idea, but the CSS files happen to be included within a CMS like product. I don't have file system access to them. They also get included as part of components within the CMS and have changing file names. –  Lucas Holt Dec 11 '12 at 18:09
    
I guess then you can use Selenium to get the text from the css file, and use regex for search/match. –  Suchit Parikh Dec 11 '12 at 18:14
    
@Lucas, is CSS stored in HTML file or in external files referenced in HTML file? –  dzieciou Dec 11 '12 at 18:15
    
The CSS is stored in external files (using link tag). –  Lucas Holt Dec 11 '12 at 18:30
    
So Suchit's comment should work. You just need first to parse out all links to CSS with Selenium, regepx or XPath, and then for each extracted link, fetch the referenced CSS file (e.g. with 'wget' in Perl). –  dzieciou Dec 11 '12 at 18:58
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.