码迷,mamicode.com
首页 > 其他好文 > 详细

软件测试lab2

时间:2017-03-26 16:15:26      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:use   result   recording   tac   which   rac   split   log   equal   

  1. Install the selenium plugin on Firefox

   First,entre the official website http://www.seleniumhq.org/download/

      技术分享

       Click this link.

技术分享

      技术分享

     And click the installation button.

      技术分享

      Finally, in the add-on, add selenium ide to the menu bar.

技术分享技术分享

  2. Learn to use SeleniumIDE to record scripts and export scripts

  Click on the little label to open selenium ide.

技术分享

Base url Fill in with the URL to test. When we use it, we should click the red button to recording firstly.

技术分享

It can export scripts in various formats . We usually choose the Junit 4/WebDrive。

  3. Write Selenium Java WebDriver program

  The code in github URL is https://github.com/zjwjerome/lab2

  The first method does not store data. Each cycle tests a use case. But the results can be seen at the end, and it is not easy to see which case is wrong.

  The operation results shown in Figure:

技术分享

@Parameters

public static Collection<Object[]> getData(){
Object[][] test = new Object[117][3];
File fi = new File("E:/inputgit.csv");
String csvSplitBy = ","; 
int add = 0;
try{
BufferedReader br = new BufferedReader(new FileReader(fi));
String line = br.readLine(); 
while ((line = br.readLine()) != null) { 
String [] temp = line.split(csvSplitBy);
test[add][0] = temp[0];
test[add][1] = temp[0].substring(4,10);
test[add][2] = temp[2];
add++;

br.close();
} catch(FileNotFoundException e){ 
e.printStackTrace(); 
} catch(IOException e){
e.printStackTrace();
}

return Arrays.asList(test);

}

@Test
public void testSelenium() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys(name);
driver.findElement(By.id("pwd")).clear();
driver.findElement(By.id("pwd")).sendKeys(pwd);
driver.findElement(By.id("submit")).click();
String infoAll = driver.findElement(By.xpath("//tbody[@id=‘table-main‘]")).getText();
String infoAddr = infoAll.substring(infoAll.indexOf("http"));
assertEquals(url, infoAddr);
}

We can only see a result in the end.

  The second method first stores the data and then uses a parametric test.

Parametric test preparation process is as follows:

A. Specifying a special runtime for the parameterized test class with @RunWith annotation: Parameterized.class;

B. Declare several variables in the test class, which are used to store the expected values and test data and create a constructor for several parameters of the user;

C. Create a static test data feed (feed) method, the return type is Collection, and use @Parameter annotation to modify;

D. Write the test method (with @Test annotation).

The operation results shown in Figure:

技术分享

It can test each pair of data. The wrong will prompt, and it will not stop running.

软件测试lab2

标签:use   result   recording   tac   which   rac   split   log   equal   

原文地址:http://www.cnblogs.com/joker001/p/6623015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!