2017-11-13 3 views
1

Ich habe einen Schritt, wo ich bestimmte Nachricht überprüfen muss. Ich verwenden einen mehrzeilige Parameter:Wie kann ich verhindern, dass JBehave mehrzeilige Parameter trimmt?

Then I see welcome message: 'Welcome to our site! 
Some more text 
Even more text' 

Problem ist, dass Nachrichten Leerzeichen am Ende der ersten und zweiten Leitungen aufweisen sollten (IDK warum, aber es soll). Und JHehave schneidet Leerzeichen aus jeder Zeile. Der Test schlägt fehl.

Wie kann ich einstellen, dass dieser Parameter nicht beschnitten wird?

Ich habe versucht \n anstelle der tatsächlichen Zeilenumbrüche zu schreiben, aber es wurde nicht mit Zeilenumbrüche ersetzt

Auch das Hinzufügen versucht {trim = false} am Anfang des Parameters, aber es liest es als Teil des Parameters.

einige Experimente mit Anführungszeichen gemacht (verwendet“,‘ none), es helfen, entweder nicht ...

Antwort

2

ich habe getestet und es scheint, dass JBehave kürzt tatsächlich Leerzeichen am Ende des Tests :

When some step with multitline parameter:first line has 10 spaces at the end   
Second line has 6 spaces at the end  
Third line has no spaces at the end, but fourth line has 8 spaces 

Fifth line has 3 spaces, and Sixth line has only 7 spaces 

@When("some step with multitline parameter:$lines") 
    public void stepWithMultilneString(String s) { 

     String lines [] = s.split("\\r?\\n"); 

     for(int i = 0; i < lines.length; i++) { 
      System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]); 
     } 
    } 

Line 1 is: >>first line has 10 spaces at the end   << 
Line 2 is: >>Second line has 6 spaces at the end  << 
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<< 
Line 4 is: >>  << 
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces<< 
When some step with multitline parameter:first line has 10 spaces at the end   
Second line has 6 spaces at the end  
Third line has no spaces at the end, but fourth line has 8 spaces 

Fifth line has 3 spaces, and Sixth line has only 7 spaces 

schlage ich einen Bypass - ein Schritt mit Begrenzungszeichen ! am Anfang und Ende o f der Text:

When step with multitline parameter surrounded by !:!first line has 10 spaces at the end   
Second line has 6 spaces at the end  
Third line has no spaces at the end, but fourth line has 8 spaces 

Fifth line has 3 spaces, and Sixth line has only 7 spaces 

! 

@When("step with multitline parameter surrounded by !:$string") 
    public void stepWithMultilneStringVersion2(String s) { 

     if(s.startsWith("!")) { 
      s = s.substring(1); 
     } 
     if(s.endsWith("!")) { 
      s = s.substring(0, s.length()-1); 
     } 

     String lines [] = s.split("\\r?\\n"); 

     for(int i = 0; i < lines.length; i++) { 
      System.out.format("Line %d is: >>%s<<\n", i+1, lines[i]); 
     } 
    } 

Line 1 is: >>first line has 10 spaces at the end   << 
Line 2 is: >>Second line has 6 spaces at the end  << 
Line 3 is: >>Third line has no spaces at the end, but fourth line has 8 spaces<< 
Line 4 is: >>  << 
Line 5 is: >>Fifth line has 3 spaces, and Sixth line has only 7 spaces << 
Line 6 is: >>  << 
When step with multitline parameter surrounded by !:!first line has 10 spaces at the end   
Second line has 6 spaces at the end  
Third line has no spaces at the end, but fourth line has 8 spaces 

Fifth line has 3 spaces, and Sixth line has only 7 spaces 

! 
+0

Dank, zum Glück letzte Zeilen haben keine Leerzeichen in meinem Fall. Es sieht so aus, als ob Zeilen von IntelliJ abgeschnitten wurden. Ich habe am Ende jeder Zeile Schutzsymbole hinzugefügt ('irgendein Text ~ \ n') '~' und dann in Schritttext durch nichts ersetzt. – Alissa

Verwandte Themen