首页 > 代码库 > Java Selenium起步
Java Selenium起步
先将录制的脚本导出来,转成java的格式
在Eclipse中编辑并运行test
2.1 新建一个Java project: File-New-Java Project
2.2 在上一步建好的项目名称上点鼠标右键, 点击Build Path-Add External Archives...,将下载的selenium-java-2.21.0.jar(client)和selenium-server-standalone- 2.21.0.jar(server)加进来
2.3 启动selenium server.进入cmd,运行 "java -jar selenium-server-standalone-2.21.0.jar" --保证能找到改jar包。信息如下:
[java] view plaincopy
- 信息: Launching a standalone server
- 22:16:21.484 INFO - Java: Sun Microsystems Inc. 17.1-b03
- 22:16:21.500 INFO - OS: Windows XP 5.1 x86
- 22:16:21.515 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
- 22:16:21.859 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
- 1:4444/wd/hub
- 22:16:21.875 INFO - Version Jetty/5.1.x
- 22:16:21.875 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
- /driver]
- 22:16:21.875 INFO - Started HttpContext[/selenium-server,/selenium-server]
- 22:16:21.875 INFO - Started HttpContext[/,/]
- 22:16:22.062 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@5d173
- 22:16:22.062 INFO - Started HttpContext[/wd,/wd]
- 22:16:22.093 INFO - Started SocketListener on 0.0.0.0:4444
- 22:16:22.093 INFO - Started org.openqa.jetty.jetty.Server@32fb4f
2.4 代码测试
[java] view plaincopy
- import com.thoughtworks.selenium.DefaultSelenium;
- public class SeleniumDemo01
- {
- public static void main(String[] args)
- {
- String host = "localhost";
- int port = 4444;
- String url = "http://www.baidu.com/";
- String browserType = "*firefox";
- String keyWordsLocator = "document.getElementById(‘kw‘)";
- String search = "document.getElementById(‘su‘)";
- DefaultSelenium selenium = new DefaultSelenium(host,port,browserType,url);
- selenium.start();
- selenium.open(url);
- selenium.type(keyWordsLocator,"java selenium");
- selenium.click(search);
- selenium.waitForPageToLoad("50000");
- selenium.stop();
- }
- }
- 运行结果:
- 1.firefox浏览器期待
- 2.打开百度主页
- 3.在搜索框中键入了"java selenium"
- 4.点击"百度一下"按钮
- 5.等等页面加载50s
- 6.关闭浏览器
- 摘自http://blog.csdn.net/test_me/article/details/7471364
Java Selenium起步
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。