Lab 2 Selenium

 

1、安装SeleniumIDE插件

  首先下载火狐浏览器(40.0.3版本),安装seleniumIDE插件,成功安装后,工具栏会出现“selenium IDE”选项

           

 

2、学会使用SeleniumIDE录制脚本和导出脚本

  单击该选项会出现下图插件,单击右上角红色按钮即可录制脚本。

   

     随后,点击“文件—>Export Test Case As—>JUnit4/WebDriver”即可进行下载脚本

   

 

3、访问http://121.193.130.195:8080/使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该同学的git地址。编写Selenium Java WebDriver程序,测试inputgit.csv表格中的学号和git地址的对应关系是否正确。

  思路:首先将csv文件进行数据驱动,将文件中数据提取到一个数组中,在提取网页中github地址与其进行比较,相关测试代码如下:

   

 1  @Test
 2   public void test() throws Exception {  
 3       
 4           String row = "";
 5           int i= 0;
 6         try {
 7             BufferedReader br = new BufferedReader(new FileReader        ("C:/Users/fy/Desktop/新建文件夹/软件测试/lab2/inputgit.csv"));
 8             while ((row = br.readLine())!=null) {
 9                 String fields[] = row.split(",");
10                 i++;
11                 if(i != 1){
12                     driver.get(baseUrl);
13                     WebElement t1 = driver.findElement(By.id("name"));
14                     t1.sendKeys(fields[0]);
15                     WebElement t2 = driver.findElement(By.id("pwd"));
16                     t2.sendKeys(fields[0].substring(4,10));
17                     WebElement btn = driver.findElement(By.id("submit"));
18                     btn.click();
19                     WebElement text = driver.findElement(By.xpath("//tbody[@id='table-main']/tr[3]/td[2]"));
20                     String address2 = text.getText();
21                     assertEquals(fields[2],address2);            
22                 }            
23             }
24             System.out.println("The numble of users is "+ i--);
25             
26         }catch (Exception e){
27             e.printStackTrace();
28         }      
29   }            

 

  测试结果如下:

  

   

 

posted on 2017-03-26 19:52  fy2014  阅读(113)  评论(0编辑  收藏  举报