【问题标题】:How to pass multi line string as input parameter for a jbehave story?如何将多行字符串作为 jbehave 故事的输入参数传递?
【发布时间】:2016-11-25 01:33:09
【问题描述】:

我有一个 jbehave 故事,我将字符串作为数据传递给参数。

例子:

|line|
|hi.how ade you|

它给出了错误

expected hi.how are you

But is : 
hi
how are you

那么我该如何处理数据中的这种输入...因为如果我给\n 它会将其视为数据的一部分

【问题讨论】:

  • 你能提供一些代码吗,到目前为止你测试了什么?
  • 如果您要获取参数并在定义中添加一行,用实际的新行替换“\n”的所有匹配项,这不会解决您的问题吗?您正在尝试在表格中执行多行文本,这不适用于大多数基于 Gherkin 的测试。

标签: bdd jbehave


【解决方案1】:

一个故事:

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)

【讨论】:

  • 你知道如何阻止 JBehave 修剪多行参数的行吗?
  • @Alissa 请将此作为单独的问题发布,而不是评论。
  • 对不起,我以为这里没问题。单独发布:stackoverflow.com/questions/47269885/…
猜你喜欢
  • 2020-02-17
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
相关资源
最近更新 更多