Over a million developers have joined DZone.

Automated W3C Validation with TeamCity

DZone 's Guide to

Automated W3C Validation with TeamCity

· Web Dev Zone ·
Free Resource

This past week, I started experimenting with letting TeamCity create reports of CSS and XHTML Validation from the W3C website. In order to do this validation I was able to use their web URL and pass a URL to the web address. In order to do this I used EasyHTTP as it took care of the web request in a very simple way.

public class Validator : IValidator
        private readonly IConfigManager _configManager;

        public string Url { get; set; }
        public ValidatorType ValidatorType { get; set; }

        public Validator(IConfigManager configManager)
            _configManager = configManager;

        public void Validate()
            if (string.IsNullOrWhiteSpace(Url))
                throw new ArgumentNullException("Url", "Url to validate must be specified");

            var appSettingName = string.Format("{0}Validator", ValidatorType);
            var urlToValidate = string.Format("{0}{1}", _configManager.GetAppSetting(appSettingName), Url);
            var http = new HttpClient
                Request = { Accept = HttpContentTypes.TextHtml }

            var response = http.Get(urlToValidate);
            var validationSummary = response.RawText;

            var reportName = string.Format("{0}Report.html", ValidatorType);
            FileSave.SaveTheResponse(validationSummary, reportName);

When the response is caught, I was able to take the raw text part of the response and save to a html file. This code is very early proof of concept and plans are a foot to be able to pass in validation types and recursive list of files etc.

In order to run this from TeamCity, there was 1 very easy build configuration


I had pre-configured TeamCity to add new report tabs when the artifacts were available – using this article. I was then able to tell TeamCity to show these report tabs by outputting the correct files as build artifacts:


The reports can be found in the build results screen:


The code will be available very soon but if you feel you want it sooner then please do let me know. There may be changes to the reports but they look similar to the following:



Source: http://paulstack.co.uk/blog/post/automated-w3c-validation-with-teamcity.aspx




Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}