01-Selenium环境搭建
一、关于selenium
selenium是开源的自动化测试工具,分为selenium1,selenium2,本文主要介绍selenium2-即selenium webdriver的环境搭建步骤
Selenium WebDriver支持多种语言:C、java、ruby、python等,本文使用的是java语言,其他语言的环境搭建方式略有差异,可以查阅相应的教程。
以下是搭建环境需要用到的所有资源的百度云链接:http://pan.baidu.com/s/1kVLuSdD 密码:uek3
二、开始搭建 (总的来说-就是在Eclipse添加Selenium JAR包)
1.下载jdk&eclipse
jdk和eclipse都是可以直接在网上下载到的,这里就不再赘述
2.下载Selenium环境包并(selenium2.4.0)导入环境需要的jar包
下载完毕之后,打开eclipse,新建一个javaproject,新建好之后,选中刚刚新建的项目,右击选择buildpath-configureBuildPath,添加Selenium
JAR 包
导入这三个部分的包(以selenium2.4.0为例):1.selenium-2.40.0\libs下面所有jar包
2.selenium-java-2.40.0.jar
3.selenium-server-standalone-2.40.0.jar
全部导入完成后,则环境搭建完毕!!!
验证环境:安装此selenium版本支持的firefox
新建一个class,代码如下:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class demo{
public void beforeClass() throws InterruptedException {
System.setProperty("webdriver.firefox.bin","D:/coding/51testingreal/Mozilla Firefox/firefox.exe");
WebDriver driver=new FirefoxDriver();
driver.navigate().to("http://www.baidu.com");
}
}
其中加粗部分为firefox.exe所在的路径,不要写错。
代码的作用是打开火狐浏览器并且跳转到百度首页。
如果执行成功,说明WebDriver环境搭建完毕。