Selenium(webdriver)实战

版本firefox41.0.2

Selenium2.48.2

代码下载地址:http://pan.baidu.com/s/15JaFG

关键代码如下:

pom.xml


	4.0.0

	com.bj58.webdriver.demo
	webdriverdemo
	0.0.1-SNAPSHOT
	jar

	webdriverdemo
	http://maven.apache.org

	
		UTF-8
	

	
		
			junit
			junit
			4.12
			test
		


		
			org.seleniumhq.selenium
			selenium-java
			2.48.2
		

	


test.java

package com.bj58.webdriver.demo.webdriverdemo;

import java.util.concurrent.TimeUnit;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class WebDriverDemoTest  {
	WebDriver driver;

	@Before
	public void setUp() throws Exception {
	      System.out.println("init...");
	        //用 Chrome
//	      System.setProperty(
//	              "webdriver.chrome.driver",
//	              "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
//	      driver = new ChromeDriver();
		// 如果火狐浏览器没有默认安装在C盘,需要制定其路径
		System.setProperty("webdriver.firefox.bin",
				"E:\\tools\\迅雷\\Mozilla Firefox\\firefox.exe");
		driver = new FirefoxDriver();
        //用 IE
//      driver = new InternetExplorerDriver();
		
	}

	@Test
	public void testTest() throws Exception {

//		 driver.get("http://www.baidu.com/");
		driver.get("http://www.baidu.com/");
		// driver.manage().window()

		 WebElement txtbox = driver.findElement(By.name("wd"));
		 txtbox.sendKeys("Glen");
		
		 WebElement btn = driver.findElement(By.id("su"));
		 btn.click();
		 
		 for(int i=0;i<100;i++){
			 txtbox = driver.findElement(By.name("wd"));
			 
			 txtbox.clear();
			 txtbox.sendKeys(i+"");
			 btn.click();
			Thread.sleep(3000);
		 }

		// driver.close();
	}

}
//Browser 	Selenium IDE 	Selenium 1 (RC) 	Operating Systems
//Firefox 3.x 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//Firefox 3 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//Firefox 2 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//IE 8 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//IE 7 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//IE 6 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//Safari 4 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Safari 3 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Safari 2 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Opera 10 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Opera 9 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Opera 8 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Google Chrome 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Others 	Test execution only via Selenium RC 	Partial support possible** 	As a


你可能感兴趣的:(java基础,java,web开发)