2017-10-18 147 views
0

我试图将我在GUI中的文本与使用testNG声明的文本文件中的文本进行比较。该GUI源代码如下在测试ng中声明LineBreaks

<h2>What is EAC?</h2> 
 
         <br/> 
 
         The Effective Annual Cost (EAC) is a measure ....(text continues...) 
 
[enter image description here][1]

我的文本文件就像

什么是EAC?

实际年成本(EAC)是衡量....(文本继续...)

断言失败和比较示出的空白字符差(道歉图像不附接。我仍然没有权限这样做)

我试图添加\ n在我的文本文件中有一个换行符,因为我在论坛中看到,但没用。

我该如何正确断言?

回答

0
Issue solved. My mistake was in the Java code I was using to read the text file. 

public String readTextfile(String fileFullPath){ 
    BufferedReader reader= null; 
    StringBuilder stringBuilder = new StringBuilder(); 

     try { 
     reader = new BufferedReader(new FileReader (fileFullPath));  
      String   line = null; 
      //String   ls = System.getProperty("line.separator"); 
      // System.out.println("Line separator is "+ls); 

       while((line = reader.readLine()) != null) { 
        stringBuilder.append(line); 
        //stringBuilder.append(ls); 
        stringBuilder.append("\n"); 
       } 


     } catch (IOException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
     }finally { 
     try{ 
      reader.close(); 
     }catch(Exception e){ 
      e.printStackTrace(); 
     } 
    } 

我的代码是使用System.getProperty(“line.separator”)读取行分隔符并追加到行。如上面的代码所示,我不得不将其替换为追加新行(\ n)。