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:E Z*Fa"D

生成java/junit4/webdriver类型的脚本,直接在eclipse里运行
|&]$M+@+t*x*a B0完整脚本如下51Testing软件测试网^&vO+N:[

Z2K v T3m$uN7uD)]z0

51Testing软件测试网7eP+Aes[4C x:V$^

package com.example.tests;

a$oO#V7O;y+Gvg#wQ^0

F3N?$z&FeY0import java.util.regex.Pattern;51Testing软件测试网*G WyA1| f
import java.util.concurrent.TimeUnit;
_ Q%F E%uc0import org.junit.*;
Gfy| ?-h5{{B)k0import static org.junit.Assert.*;51Testing软件测试网3q S}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/?4Ve051Testing软件测试网$uf`1kX@s P%JW

public class Untitled {51Testing软件测试网;fiyV6K%D&F
 private WebDriver driver;
+\^vn?,B~0 private String baseUrl;
AhL hS0 private StringBuffer verificationErrors = new StringBuffer();51Testing软件测试网+|$]&`K'm-k
 @Before
Y N+sCn,A K1|0 public void setUp() throws Exception {51Testing软件测试网6[xpx_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|(~rjJ b

 @Test51Testing软件测试网*NGL} {`#o m
 public void testUntitled() throws Exception {
g6M sy(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软件测试网 zc#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 {_Q2j b

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$`qY0D4Y0  }51Testing软件测试网GEMh#N|*Z4zA
 }
*X*Bp3FR7d0}51Testing软件测试网5f.yO+{5qfa
51Testing软件测试网N*uN*j1x9@#c

51Testing软件测试网,fHp0yD]Z(T9V


TAG:

 

评分:0

我来说两句

Open Toolbar