Experimental-work2

软件测试第二次实验报告

3015207191       软件工程3班        林家乐

一、安装SeleniumIDE插件:

        

 

    如上图所示,SeleniumIDE安装成功。

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

访问https://psych.liebes.top/st,将自己的学号和密码输入后。在seleniumIDE选择“文件” --- Export Test Case As” --- Java Junit4 Webdriver”。完成上述操作后,会在左面上产生一个文件,如下图所示,即成功使用SeleniumIDE录制脚本和导出脚本。

 

 

三、访问https://psych.liebes.top/st使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该同学的git地址:

 

四、编写Selenium Java WebDriver程序,测试input.xlsx表格中的学号和git地址的对应关系是否正确。

程序代码:

package TestHomework;

import java.io.*;

import java.text.DecimalFormat;

import java.util.concurrent.TimeUnit;

import org.apache.http.auth.UsernamePasswordCredentials;

import org.apache.poi.ss.usermodel.CellStyle;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.*;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.support.ui.Select;

public class TestHomework {

 private WebDriver driver;

  private String baseUrl;

  private boolean end = false;

  public int count = 0;

  public void isSame() throws IOException

  {

  driver = new FirefoxDriver();

  baseUrl = "https://psych.liebes.top/";

  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

  String[] username = new String[200];

  String[] password = new String[200];

  String[] webSite = new String[200];

  FileInputStream in = new FileInputStream("F://input.xlsx");

  XSSFWorkbook xssfWorkbook = new XSSFWorkbook(in); 

  for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {  

             XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);  

             if (xssfSheet == null) {  

                 continue;  

             }  

             for (int rowNum = 0,i = 0; rowNum <= xssfSheet.getLastRowNum(); i++,rowNum++) {  

                 XSSFRow xssfRow = xssfSheet.getRow(rowNum);  

                 if (xssfRow != null) {  

                     XSSFCell one = xssfRow.getCell(0);  

                     username[i] = getValue(one);

                     password[i] = username[i].substring(4, 10);

                     XSSFCell two = xssfRow.getCell(1);  

                     webSite[i]= getValue(two); 

                 }  

             }  

             break;  

         }

  for(int i=0;i<97;i++)

    {    

     driver.get(baseUrl + "/st");

     if(username[i].equals("3015218150"))

     {

     count += 1;

     continue;

     }

     driver.findElement(By.id("username")).clear();

     driver.findElement(By.id("username")).sendKeys(username[i]);

     driver.findElement(By.id("password")).clear();

     driver.findElement(By.id("password")).sendKeys(password[i]);

     driver.findElement(By.id("submitButton")).click();

     WebElement element1 = driver.findElement(By.xpath("/html/body/div/div[2]/a"));

     String s = element1.getAttribute("href");

     if(!(s.equals(webSite[i])))

     {

     count += 1;

     }

    }

  System.out.println(count);

  driver.close();

  }

  private static String getValue(XSSFCell xssfRow) {  

        if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {  

            return String.valueOf(xssfRow.getBooleanCellValue());  

        } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) { 

         double value = xssfRow.getNumericCellValue();

         CellStyle style = xssfRow.getCellStyle();

         DecimalFormat format = new DecimalFormat();

         String temp = style.getDataFormatString();

         if(temp.equals("general"))

         {

         format.applyPattern("#");

         }

         String cellinfo = format.format(value);

            return cellinfo;  

        } else {  

            return String.valueOf(xssfRow.getStringCellValue());  

        }  

    } 

  public static void main(String args[]) throws IOException

  {

  TestHomework a = new TestHomework();

  a.isSame();

  }

}

结果截图:

 

 

 

结果显示,共有11位同学的在input.xlsx表格中的学号和git地址的对应关不正确。

五、将测试代码提交到github上(41523:59:59前)。

githubhttps://github.com/3015207191

 

转载于:https://www.cnblogs.com/3015207191A/p/8836374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值