2016-11-21 82 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