selenium-webdriver
上一篇 /
下一篇 2012-12-02 01:37:33
/ 个人分类:selenium
+R#so.}#^.~7Nh'T0eclipse工程里添加外部jar包,selenium-server-standalone-*.jar和selenium-java-*.jar之后,就可以运行webdriver类型的脚
4Fp2p5[y051Testing软件测试网"m9IQF:EZ*Fa"D生成java/junit4/webdriver类型的脚本,直接在eclipse里运行
|&]$M+@+t*x*a B0完整脚本如下51Testing软件测试网^&vO+N:[
Z2Kv
T3m$uN7uD)]z0
51Testing软件测试网7eP+A es[4C
x:V$^ package com.example.tests; a$oO#V7O;y+Gv g#wQ^0F3N ?$z&FeY0import java.util.regex.Pattern;51Testing软件测试网*G
WyA1| f import java.util.concurrent.TimeUnit; _Q%FE%uc0import org.junit.*; Gfy| ?-h5{{B)k0import static org.junit.Assert.*;51Testing软件测试网3qS}i'B{ import static org.hamcrest.CoreMatchers.*; 0S
r;z*P.f"Lq0import org.openqa.selenium.*; Ne9v
E%X4P"l4G(ou0import org.openqa.selenium.firefox.FirefoxDriver; K!_&E S^\0import org.openqa.selenium.support.ui.Select; ]1S"x/?4V e051Testing软件测试网$uf`1kX@s
P%JWpublic class Untitled {51Testing软件测试网;fiyV6K%D&F private WebDriver driver; +\^vn?,B~0 private String baseUrl; AhLhS0 private StringBuffer verificationErrors = new StringBuffer();51Testing软件测试网+|$]&`K'm-k @Before Y N+sCn,A K1|0 public void setUp() throws Exception {51Testing软件测试网6[x px_pt driver = new FirefoxDriver();51Testing软件测试网$l [y]1| EIk baseUrl = "http://www.baidu.com/"; Pv
f,Nb-z+Ff0 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
tW"@ {_
X4Kg0 }51Testing软件测试网Bp\5Fg7yd{2{ 51Testing软件测试网1K8|(~rjJb @Test51Testing软件测试网*NGL} {`#o m public void testUntitled() throws Exception { g6Msy(q/{,vc0 driver.get("http://www.baidu.com/");51Testing软件测试网 DbC\"K0SAn driver.findElement(By.id("kw")).clear(); y#s4]'gA}cr6V0 driver.findElement(By.id("kw")).sendKeys("111");51Testing软件测试网 h#a/@z%n:Z3nT driver.findElement(By.id("su")).click();51Testing软件测试网D'[m+rWK(gb-G0rw } %yrs~2t'VFd'mm1L051Testing软件测试网z c#j6X0g @After [#O+olt~0 public void tearDown() throws Exception {51Testing软件测试网
[$b9d sf driver.quit(); 2TH C0^
T"O0 String verificationErrorString = verificationErrors.toString();51Testing软件测试网Ju+S2jT)@c if (!"".equals(verificationErrorString)) { gS%bZ2H \0 fail(verificationErrorString); +q1Asi)Z0 } apb2bI0x4`C0 }51Testing软件测试网RM {_Q2jb
x5s Jf;TRO0 private boolean isElementPresent(By by) {51Testing软件测试网tK{C/aAyM~ try { TIK1D._ [2x0 driver.findElement(by); 7Jr,qQ+f!h+|3A]3g0 return true;51Testing软件测试网Y v tQ+gb_!@ } catch (NoSuchElementException e) {51Testing软件测试网
U,k"w%p2Xn return false; i)x3b%m$`q Y0D4Y0 }51Testing软件测试网GE Mh#N|*Z4zA } *X*Bp3FR7d0}51Testing软件测试网5f.yO+{5qfa 51Testing软件测试网N*uN*j1x9@#c |
51Testing软件测试网,fHp0yD]Z(T9V
收藏
举报
TAG: