Skip to content

Instantly share code, notes, and snippets.

@hugs
Created November 21, 2009 23:00
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hugs/240324 to your computer and use it in GitHub Desktop.
Screentest Demo
Copyright (c) 2009 Jason R. Huggins
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
# To run the test:
# (requires nose):
# $ nosetests screentest-demo.py
#
# expected output:
# .
# ----------------------------------------------------------------------
# Ran 1 test in 34.520s
#
# OK
import os
from string import Template
import time
from castro import Castro
from webdriver.firefox.webdriver import WebDriver
class HollywoodWebDriver(WebDriver):
def dramatic_pause(self, seconds=3):
time.sleep(seconds)
def resize_window(self, x, y, width, height):
js = "self.resizeTo(%s, %s);" % (width, height)
self.execute_script(js)
js = "self.moveTo(%s,%s);" % (x,y)
self.execute_script(js)
def show_text(self, text, pause=3):
js = Template(''' document.body.innerHTML = '<div style="' +
'text-align: center;' +
'position: absolute; top: 25%; left: 25%; ' +
'height: 50%; width: 50%;">' +
'${text}' +
'</div>' ''')
self.execute_script(js.substitute(text=text))
self.dramatic_pause(seconds=pause)
class TestSimpleGoogleSearch:
def setup(self):
# Prepare screen recorder
self.recorder = Castro(filename="screentest-demo.flv",
clipping="854x480+0+150")
# Prepare browser
self.driver = HollywoodWebDriver()
self.driver.resize_window(0,28,854,602)
# Roll camera
self.recorder.start()
self.driver.dramatic_pause()
def test_simple_google_search(self):
# Introduction
self.driver.show_text("<h1>How-to: Google Search</h1>")
self.driver.show_text("<h2>Step 1: Go to http://google.com</h2>", pause=2)
self.driver.show_text("<h2>Step 2: Enter some text</h2>", pause=2)
self.driver.show_text('<h2>Step 3: Click "Google Search"</h2>', pause=2)
# Perform the actual search
self.driver.dramatic_pause()
self.driver.get("http://www.google.com")
self.driver.find_element_by_name("q").send_keys("Hello World")
self.driver.dramatic_pause()
self.driver.find_element_by_name("btnG").click()
self.driver.dramatic_pause()
# Perform a test assertion:
assert "en.wikipedia.org/wiki/Hello_world_program" in self.driver.get_page_source()
# Reset the page, and show last slide
self.driver.get("about:blank")
self.driver.show_text("<h1>That was easy!</h1>")
self.driver.dramatic_pause()
def teardown(self):
self.driver.quit()
self.recorder.stop()
self.recorder.process()
@lonfee88
Copy link

lonfee88 commented Aug 4, 2015

cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment