博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lab2_selenium测试
阅读量:5969 次
发布时间:2019-06-19

本文共 3403 字,大约阅读时间需要 11 分钟。

1、install seleniumIDE

get to selenium official page.

 

 

2、use selenium to videotype and export the code

 at first, the selenium can not be used completely right. then the teacher told us it's the version problem.

so i use selenium2.53. firefox 40. problem solved.

 

 

 

click 文件->export test case as -> JAVA/JUnit4/WebDriver     to get the code

 

 

3、build a new project, copy the code into the new .java file. add the external jars.

 

then add some new code.

4、write Selenium Java WebDriver code

package lab1;import java.nio.charset.Charset;import java.util.regex.Pattern;import java.util.concurrent.TimeUnit;import org.junit.*;import static org.junit.Assert.*;import static org.hamcrest.CoreMatchers.*;import org.openqa.selenium.*;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.support.ui.Select;import com.csvreader.CsvReader;public class TestGit {  private WebDriver driver;  private String baseUrl;  private boolean acceptNextAlert = true;  private StringBuffer verificationErrors = new StringBuffer();  private String id = null;  private String pwd = null;  private String gitUrl = null;  @Before  public void setUp() throws Exception {        driver = new FirefoxDriver();    baseUrl = "http://121.193.130.195:8080";    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  }  @Test  public void testGit() throws Exception {      CsvReader cin =  new CsvReader("F:/inputgit.csv", ',',Charset.forName("GBK"));      cin.readHeaders();      while(cin.readRecord()){        id = cin.get(0);        pwd = id.substring(4, 10);        gitUrl = cin.get(2);        driver.get(baseUrl + "/");        driver.findElement(By.id("name")).clear();        driver.findElement(By.id("name")).sendKeys(id);        driver.findElement(By.id("pwd")).clear();        driver.findElement(By.id("pwd")).sendKeys(pwd);        driver.findElement(By.id("submit")).click();        String gitUrls = driver.findElement(By.xpath("//tbody[@id = 'table-main']/tr[3]/td[2]")).getText();        if (!gitUrl.equals(gitUrls)){            System.out.println(id);            System.out.println(gitUrl);            System.out.println(gitUrls);            continue;                    }        assertEquals(gitUrl,gitUrls);    }  }  @After  public void tearDown() throws Exception {    driver.quit();    String verificationErrorString = verificationErrors.toString();    if (!"".equals(verificationErrorString)) {      fail(verificationErrorString);    }  }  private boolean isElementPresent(By by) {    try {      driver.findElement(by);      return true;    } catch (NoSuchElementException e) {      return false;    }  }  private boolean isAlertPresent() {    try {      driver.switchTo().alert();      return true;    } catch (NoAlertPresentException e) {      return false;    }  }  private String closeAlertAndGetItsText() {    try {      Alert alert = driver.switchTo().alert();      String alertText = alert.getText();      if (acceptNextAlert) {        alert.accept();      } else {        alert.dismiss();      }      return alertText;    } finally {      acceptNextAlert = true;    }  }}

it took 218s to execute this test.

then I modified the csv file, I changed one record. and I use

 this to print out the wrong git url.

 

this is the result

 this is an exciting experience, i learnt not only test automation, but also the vital thinking method of testing.

转载于:https://www.cnblogs.com/duanyihai/p/6612383.html

你可能感兴趣的文章
ASP.NET 运行机制详解
查看>>
在 ML2 中配置 OVS vlan network - 每天5分钟玩转 OpenStack(136)
查看>>
Selenium2+python自动化34-获取百度输入联想词
查看>>
【★★★★★】提高PHP代码质量的36个技巧
查看>>
如何解决/home/oracle: is a directory报警
查看>>
BaaS API 设计规范
查看>>
bootloader功能介绍/时钟初始化设置/串口工作原理/内存工作原理/NandFlash工作原理...
查看>>
iOS开发UI篇—Quartz2D使用(矩阵操作)
查看>>
C++ 构造函数与析构函数
查看>>
Python快速教程
查看>>
ssh免密码登录
查看>>
Linux下Django环境安装
查看>>
如何在指定的内容中找出指定字符串的个数
查看>>
我的友情链接
查看>>
浅谈如何用We7站群平台打造垂直性政务网站
查看>>
我的友情链接
查看>>
Go bytes包
查看>>
Spring MVC请求处理流程分析
查看>>
生产环境MySQL 5.5.x单机多实例配置实践
查看>>
Web应用工作原理、动态网页技术
查看>>