Project

unused_css

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby gem, built from a need, to watch a suite of functional tests and gather all of the unused CSS styles.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Unused CSS

Build Status

A Ruby gem that will watch a suite of functional tests running and gather all of the unused CSS styles.

Install

gem install unused_css

How to use

Here's a typical 'features/support/env.rb' file using Unused CSS to watch the Watir webdriver as it runs your functional tests:

require "watir-webdriver"
require "unused_css/watir"

$browser = Watir::Browser.new

at_exit do
  $browser.close
  
  # A list of all stylehseets together with their unused styles
  puts "Unused CSS"
  $browser.stylesheets.each do |stylesheet|
    puts stylesheet.uri
    stylesheet.unused_styles.each { |style| puts style }
  end
  
end

How it works

Unused CSS will override the 'goto' method on Watir webdriver. After going to the specified web page, it will grab any new stylesheets it may have found and scan all stylesheets it knows about removing any used css found on the page.

Checking for unused css/styles on your terms (AJAX scenario)

I thought it would be nice to also put you in control of when you want to check for used styles on a page. A page that relies on AJAX to dynamically load content will likely benefit from being able to do so.

In one of your step definitions you can simply call:

When(/^I recheck the styles on the page$/) do

    # Where $browser is an instance of Watir webdriver
    $browser.check_for_unused_styles!
end

Limitations

Unused CSS currently only works with Watir webdriver, I will be adding more webdrivers soon.

Feedback

Please send me a message or an email and let me know what you think.

Chris Temple