Selenium是thoughtworks公司的一個整合測試的強大工具,關於它的好處網路隨處可以搜到,我就不一一介紹,在之前見到一個系列是Selenium Remote Control For Java,在這裡模仿一下,主要以Python來實現。一是我比較喜歡用Python,二是剛好可以練手,熟悉熟悉Python開發Selenium RC指令碼。
What is Selenium?
Selenium is a testing tool for web applications that uses JavaScript and Iframes to run tests directly in a browser. There are several test tools based on this technology: Selenium Core, Selenium IDE, Selenium Remote Control, and Selenium on Rails.
下面的是第一個例子:
在http://www.bitmotif.com/上點擊link=Test Page For Selenium Remote Control,檢查新頁面的標題
代碼from selenium import selenium
import unittest
class ExampleTest(unittest.TestCase):
MAX_WAIT_TIME_IN_MS = 60000
BASE_URL = "http://www.bitmotif.com"
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox3 E:/Program Files/Mozilla Firefox/firefox.exe", self.BASE_URL)
self.selenium.start()
def tearDown(self):
self.selenium.stop()
def testClinckinglink(self):
sel = self.selenium
sel.open(self.BASE_URL)
sel.click("link=Test Page For Selenium Remote Control")
sel.wait_for_page_to_load(self.MAX_WAIT_TIME_IN_MS)
expectedTitle = u"Test Page For Selenium Remote Control « Bit Motif"
#sel.get_title()
self.assertEquals(expectedTitle, sel.get_title())
if __name__ == '__main__':
unittest.main()