当前位置: 代码迷 >> Web前端 >> Selenium-感受之旅
  详细解决方案

Selenium-感受之旅

热度:9637   发布时间:2013-02-26 00:00:00.0
Selenium-----体验之旅

今天我们来看一下如何在Eclipse下使用Java来编写webdriver的case。需要准备的东西:jdk1.6、eclipse、selenium-server-standalone-2.21.0.jar包。我使用的浏览器是Firefox的,要注意一下你的Firefox的版本是否和你的selenium sever的版本匹配。

selenium server可以到selenium的官网下载:http://seleniumhq.org/

首先在eclipse里新建一个java project--Test,然后在Test项目下新建一个文件夹lib,lib原来放selenium的server包。如下图所示:

然后将selenium加入到build path里:选中项目右键-->Build Path-->Configure Build path,然后点击add jars-->选我们项目下的selenium server就可以了。


到这里我们的准备就做好了。


下面新建一个java的类,来体验一下selenium webdriver。

package com.beyondtest;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class testbaidu {	/**	 * @param args	 */	public static void main(String[] args) {		// TODO Auto-generated method stub		//设置浏览器driver		WebDriver driver;		driver=new FirefoxDriver();				//打开百度的首页		driver.get("http://www.baidu.com");				//找到输入框,输入hello,并单击百度一下按钮		driver.findElement(By.id("kw")).clear();		driver.findElement(By.id("kw")).sendKeys("hello");				driver.findElement(By.id("su")).click();				//关闭浏览器		driver.close();					}}

OK,强大吧。接下来我们将一点一点深入的去学习这个强大的工具。

更多关于selenium培训的信息请关注:http://www.beyondtest.com


  相关解决方案