Sep 23, 2010

selenium with python

Selenium is a good testing tool which can be controled by many programing languages. So here is some sample coding in python.

from selenium import selenium
import unittest

class TestGoogle(unittest.TestCase):
def setUp(self):
self.selenium = selenium("localhost", \
4444, "*firefox", "http://www.google.com/webhp")
self.selenium.start()

def test_google(self):
sel = self.selenium
sel.open("http://www.google.com/webhp")
sel.type("q", "hello world")
sel.click("btnG")
sel.wait_for_page_to_load(5000)
self.assertEqual("hello world - Google Search", sel.get_title())

def tearDown(self):
self.selenium.stop()

if __name__ == "__main__":
unittest.main()

This will test the google.com website.

No comments:

Post a Comment

Your comments are always welcome ...