Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Created April 17, 2011 13:52
Show Gist options
  • Save cburgmer/924043 to your computer and use it in GitHub Desktop.
Save cburgmer/924043 to your computer and use it in GitHub Desktop.
Using Selenium to validate XHTML markup using lettuce
# -*- coding: utf-8 -*-
import re
from lettuce import world, step, before
from lettuce_webdriver.util import find_field
from lettuce_webdriver import webdriver # We need this to register "I visit..."
from nose.tools import assert_true
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
@before.all
def setup_browser():
world.browser = webdriver.Firefox()
@before.all
def setup_slow_browser():
# Start the browser
profile = FirefoxProfile()
# When inserting many lines of text the Javascript process takes ages
profile.set_preference('dom.max_script_run_time', 10*60)
profile.set_preference('dom.max_chrome_script_run_time', 10*60)
world.slow_browser = webdriver.Firefox(firefox_profile=profile)
@step(u'The page validates correctly')
def the_page_validates_correctly(step):
page_source = world.browser.page_source
# Fix doctype which Firefox & validator disagree upon
page_source = re.sub(u"^<!DOCTYPE HTML ", u"<!DOCTYPE html ", page_source)
# Post to validator
world.slow_browser.get("http://validator.w3.org/#validate_by_input")
field = find_field(world.slow_browser, 'textarea', 'fragment')
field.clear()
field.send_keys(page_source)
field.submit()
assert_true("Congratulations"
in world.slow_browser.page_source)
Feature: W3C Markup Validator validates
Scenario: The validator gives thumbs up
Given I visit "http://www.google.com/"
Then the page validates correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment