LAB02:Selenium的安装与使用

1.安装

首先点击火狐浏览器右上角选择添加附件:

搜索

选择安装:

完成并启动:

2.使用录制与导出功能:

 

点击文件进行测试用例的输出:

3.测试网站内容是否与所给的git地址相一致:

首先,将三个java包导入到已经建立好的程序中;

接下来编写代码使自动化测试能够完成:

 public void testUsecase() throws Exception {
	  File csv = new File("inputgit.csv");  // CSV文件路径
	    BufferedReader br = null;
	    try
	    {
	        br = new BufferedReader(new FileReader(csv));
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    }
	    String line = "";
	    String everyLine[];
	    int i=1;
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	            	if(i==1){
	            	i++;
	            	continue;
	            	}
	            	else{
	                everyLine = line.split(",");
	                driver.get(baseUrl);
	                driver.findElement(By.id("name")).clear();
	                driver.findElement(By.id("name")).sendKeys(everyLine[0]);
	                driver.findElement(By.id("pwd")).clear();
	                driver.findElement(By.id("pwd")).sendKeys(everyLine[0].substring(4,10));
	                driver.findElement(By.id("submit")).click();
	  
	               assertEquals(everyLine[2], driver.findElement(By.xpath("//tbody[@id='table-main']/tr[3]/td[2]")).getText());
	               
	                System.out.println(everyLine[1]+" is OK!");
	            	}
	            }  
	    } catch (IOException e)
	    {
	        e.printStackTrace();
	    }
  }

 首先从inputgit.csv文件中提取出同学的身份信息进行系统的登录。接下来将本地文件中的git地址链接与网页中的地址链接做对比判断是否一致。测试结果由于时间关系简单截取:

原文地址:https://www.cnblogs.com/xuyuwei123/p/6610790.html