2016-11-21 83 views
0

我有一個jbehave的故事,我將一個字符串作爲數據傳遞給參數。如何將多行字符串作爲jbehave故事的輸入參數傳遞?

例子:

|line| 
|hi.how ade you| 

它給誤差

expected hi.how are you

But is : 
hi 
how are you 

那麼,如何處理這個輸入的數據...因爲如果我給\n這是考慮它作爲數據的一部分

+0

你能提供一些代碼,你有什麼測試這麼遠嗎? – Hida

+0

如果您要獲取參數並在定義內添加一行,用一個實際的新行替換「\ n」的所有匹配項,這難道不能解決您的問題嗎? 您正在嘗試在表格中執行多行文本,並且這對大多數基於小黃瓜的測試都無效。 –

回答

0

一個故事:

Narrative: 

As a tester 
I want to use a string that spans multiple lines as a parameter 
So that I can test scenarios using multiline strings 

Scenario: User enters a string that spans multiple lines 

When the user enters a string: This 
is 
a very 
long 
string 

that 
spans 
multiple 
lines 

and even 
has 

some empty 
lines 


Then I can see this string in the console 

的步驟的實現:

public class MySteps { 

    private String myString; 

    @When("the user enters a string: $string") 
    public void userEntersString(String string){ 
     myString = string; 
    } 

    @Then("I can see this string in the console") 
    public void printTheStringToTheConsole(){ 
     System.out.println("====== the string starts here ======="); 
     System.out.println(myString); 
     System.out.println("====== the string endss here ======="); 
    } 
} 

的結果:

Running story org/buba/jbsimple/stories/my.story 

(org/buba/jbsimple/stories/my.story) 
Narrative: 
As a tester 
I want to use a string that spans multiple lines as a parameter 
So that I can test scenarios using multiline strings 
Scenario: User enters a string that spans multiple lines 
When the user enters a string: This 
is 
a very 
long 
string 

that 
spans 
multiple 
lines 

and even 
has 

some empty 
lines 
====== the string starts here ======= 
This 
is 
a very 
long 
string 

that 
spans 
multiple 
lines 

and even 
has 

some empty 
lines 
====== the string endss here ======= 
Then I can see this string in the console 



(AfterStories) 
+0

你知道如何阻止JBehave修剪多行參數的行嗎? – Alissa

+0

@Alissa plase將此作爲單獨問題發佈,而不是評論。 – krokodilko

+0

對不起,我認爲在這裏可以。單獨發佈:https://stackoverflow.com/questions/47269885/how-to-stop-jbehave-from-trimming-multiline-parameters – Alissa