Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

6.2. Selenium RC

http://seleniumhq.org/download/
		
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/"
			)