您的位置:首页 > 编程语言 > Java开发

SELENIUM中文教程之Selenium+ Webdriver+JAVA 自动化测试 环境搭建( SELENIUM自动化测试入门基础)

2015-07-13 22:23 1051 查看
WebDriver(JAVA)基本教程之环境的搭建 Qa不止是点点点,偶尔写点代码,让测试更加的轻松,解放更多的时间去学习交流。 一.Java环境的搭建JDK的安装1.访问oracle的官网下载最新版本的jdkhttp://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 进去后选择电脑配置对应版本的JDK版本。下载成功以后直接下一步,安装默认的路径。这里注意:安装的过程中会提示一个jre的安装路径,需要注意一下,一个是运行环境,一个是编译的环境。2.配置环境变量打开电脑中的系统属性中的高级系统配置中的环境变量。系统变量中新建一个变量名称为Java_Home,存放的路径式jdk的安装目录的路径:C:\Program Files\Java\jdk1.8.0_45。新建变量Path:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;新建变量Classpath:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(注意Classpath中的.;和中间分隔的; ps:别整成中文的了,根据自己的目录可以自行调整路径)验证是否安装成功,windows cmd:输入java and javac 如果看见大串出现,恭喜你安装成功了。 3.编译工具eclipse我的网盘工具版本比较低了:http://pan.baidu.com/s/1sjuUHPj jdk6和eclipse,直接打开就行。4.WebDriver的三个jar包 http://pan.baidu.com/s/1qWJtpjm 5.浏览器驱动,WebDriver支持多个浏览器,目前用的比较多的Chrome Ie FireFox。http://pan.baidu.com/s/1pJj3yZL Chrome和ie的驱动Firefox安装在默认的路径就可以直接调用。 二.新建第一个程序1.新建一个java的project,填写project和finish就好。 2.导入java包,右击你的工程,选择buildpath,add external Archives 导入Selenium的三个jar包。 3.新建一个类 class,输入名称,点击finish即可。4.上代码和selenium say hello和firefox say hellopackage com.cxy.controller; import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver; public class TestBaidu { public static void main(String[] args) {// TODO Auto-generated method stubWebDriver dr = new FirefoxDriver();dr.get("http://www.baidu.com");dr.findElement(By.id("kw")).sendKeys("hello Selenium");dr.findElement(By.id("su")).click();try {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} dr.quit();} } 和chrome say hello package com.cxy.controller; import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver; public class TestBaidu { public static void main(String[] args) {// TODO Auto-generated method stubSystem.setProperty("webdriver.chrome.driver", C:\\browser\\chromedriver.exe"); WebDriver driver3 = new ChromeDriver();dr.get("http://www.baidu.com");dr.findElement(By.id("kw")).sendKeys("hello Selenium");dr.findElement(By.id("su")).click();try {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}dr.quit();}}和 ie say hello package com.cxy.controller;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver; public class TestBaidu { public static void main(String[] args) {// TODO Auto-generated method stub System.setProperty("webdriver.ie.driver", "D:\\browser\\IEDriverServer.exe");//ie浏览器安全设置的问题 DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver2 =new InternetExplorerDriver(ieCapabilities);dr.get("http://www.baidu.com");dr.findElement(By.id("kw")).sendKeys("hello Selenium");dr.findElement(By.id("su")).click();try {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}dr.quit();}}欢迎关注我们的社区,Webdriver中文社区

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息