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

posted @ 2012-09-03 17:32  在学习的团子  阅读(5094)  评论(0编辑  收藏  举报