wget http://selenium.googlecode.com/files/selenium-server-standalone-2.19.0.jar java -jar selenium-server-standalone-2.19.0.jar
預設連接埠是4444,可以使用-port 改變連接埠
java -jar selenium-server.jar -Dfile.encoding="Unicode" 指定編碼
from selenium import selenium
# This is the driver's import. You'll use this class for instantiating a
# browser and making it do what you need.
import unittest, time, re
# This are the basic imports added by Selenium-IDE by default.
# You can remove the modules if they are not used in your script.
class NewTest(unittest.TestCase):
# We create our unittest test case
def setUp(self):
self.verificationErrors = []
# This is an empty array where we will store any verification errors
# we find in our tests
self.selenium = selenium("192.168.1.3", 5555, "*firefox",
"http://www.google.com/")
self.selenium.start()
# We instantiate and start the browser
def test_new(self):
# This is the test code. Here you should put the actions you need
# the browser to do during your test.
sel = self.selenium
# We assign the browser to the variable "sel" (just to save us from
# typing "self.selenium" each time we want to call the browser).
sel.open("/")
sel.type("q", "selenium rc")
sel.click("btnG")
sel.wait_for_page_to_load("30000")
self.failUnless(sel.is_text_present("Results * for selenium rc"))
# These are the real test steps
def tearDown(self):
self.selenium.stop()
# we close the browser (I'd recommend you to comment this line while
# you are creating and debugging your tests)
self.assertEqual([], self.verificationErrors)
# And make the test fail if we found that any verification errors
# were found
if __name__ == "__main__":
unittest.main()
firefox
self.selenium = selenium("localhost", 4444, "*firefox", "http://www.google.com/")
iexplore
self.selenium = selenium("localhost", 4444, "*iexplore", "http://www.google.com/")
chrome
self.selenium = selenium("localhost", 4444, "*chrome", "http://google.com/")
通過絶對路徑指定瀏覽器
self.selenium = selenium( "localhost", 4444, "c:\\program files\\internet explorer\\iexplore.exe", "http://google.com/" )