selenium學習中遇到的問題


1. Selenium IDE, Options > Format 選擇Java / Junit 4 / Remote Control, 錄制的Source代碼仍舊不是Junit4的代碼。

解決:打開IDE Options > Options, 選上Enable experimental features, 再設置Options > Format, 就可以得到Junit代碼。

可通過文件 > Export Test Case As... > Java / Junit4 / Remote Control 保存得到代碼。

 

2. 引入架包seleniumserver.jar 和 selenium-java-client-driver.jar架包之后,selenium字仍顯示紅杠杠。

解決:代碼內加上定義selenium語句:

private static DefaultSelenium selenium;

 

3. java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4444' ?

Read more at http://seleniumhq.org/projects/remote-control/not-started.html

Connection refused: connect

解決:Selenium RC未啟動,啟動即可。

java -jar selenium-server-standalone-2.25.0.jar

 

4. 不啟動cmd運行selenium rc, 直接Java啟動的方法。

解決:使用java代碼如下

	SeleniumServer SELENIUM_SERVER;
	@Before
	public void setUp() throws Exception {
		RemoteControlConfiguration rcc = new RemoteControlConfiguration();
		rcc.setPort(4444); //指定selenium server 開放端口
		SELENIUM_SERVER = new SeleniumServer(rcc);
		SELENIUM_SERVER.start(); //測試前啟動server
	}	
	@After
	public void tearDown() throws Exception {
		SELENIUM_SERVER.stop(); //測試結束停止server
	}

 

5. 運行時出現錯誤WARNING: Failed to start: SocketListener0@0.0.0.0:4444

解決:出現這錯誤表示已經有另外一個Selenium server 啟動了,可以通過ps -efa | grep selenium查看是否有其他的selenium server正在運行, 如果有請將其關閉即可;否則就是有另外的服務器在使用4444端口,需要更換端口。

 

6. java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!

Please add the directory containing ''firefox.exe'' to your PATH environment

variable, or explicitly specify a path to Firefox 3 like this:

*firefox3 c:\blah\firefox.exe

解決:網上提供方法一是:我的電腦-屬性-高級-環境變量-系統變量-PATH

PATH=$PATH;D:\Program Files\Mozilla Firefox\

需要重新啟動一次eclipse

這個我試了無效,不知道怎么回事,懷疑是跟Selenium-server.jar包和Firefox版本不一致有關。

試驗成功的方法是:在代碼里面加上安裝路徑,可能是因為selenium server只能識別C盤, 不能識別其它盤,而Firefox我裝在D盤的,所以我就加上路徑,再啟動服務進行運行,成功。
selenium = new DefaultSelenium(“localhost”, 4444, “*firefox D:/Program Files/Mozilla Firefox/firefox.exe”, “http://www.baidu.com/“);

 

參考資料:

http://blog.csdn.net/guyue860103/article/details/7307038

http://blog.sina.com.cn/s/blog_66e7bc7201013eqd.html

http://blog.csdn.net/jepher/article/details/1615447


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM