简体   繁体   English

在其他Fitnesse灯具中使用let创建的变量

[英]Using let created variables in other fitnesse fixtures

I have a problem with using let created variables. 我在使用let创建的变量时遇到问题。 I'm using RestFixture to get/post from http location and I do want to use this answer in another fixture: 我正在使用RestFixture从http位置获取/发布,但我确实想在另一个灯具中使用此答案:

  1. I'm getting data via post 我正在通过帖子获取数据
  2. saving body as variable using let 使用let将正文保存为变量
  3. printing my variable in comment line to see that is really working 在注释行中打印我的变量以查看是否确实有效

|!-CustomRestFixture-!| |!-CustomRestFixture-!| http://addres |CONFIG| http:// addres | CONFIG |
|setHeader |Content-Type : application/json | | setHeader | Content-Type:应用程序/ json |
|setBody | | setBody | {some JSON body} | {some JSON body} |
|POST | | POST | |200 |Content-Type: text/plain | | 200 |内容类型:文本/纯文字| | |
|let |myvariable |body|//* | |让| myvariable | body | // * | | |
|comment | |评论| This is my variable : %myvariable% | 这是我的变量:%myvariable%|

  1. Then I would like to use it in another (custom made) fixture that compares two strings (second fixture is inside same test page) : 然后,我想在另一个比较两个字符串的(定制)夹具中使用它(第二个夹具在同一测试页内):

!|DecTable| !| DecTable |
|my first value|my second value|is this equal?| |我的第一个值|我的第二个值|等于吗?|
|aaa |aaa |true | | aaa | aaa | true |
|%myvariable% |anything |ture | |%myvariable%|任何| ture |

  1. What I can noticed is my variable is not working anywhere else that in RestFixture. 我可以注意到,我的变量在RestFixture中的其他地方均无效。 I can not pass is any further, but it suppose to be global 我无法超越,但它应该是全球性的

Is there any solution for that ? 有什么解决办法吗? Thanks in advance 提前致谢

I don't know the specifics of the let keyword of RestFixture. 我不知道RestFixture的let关键字的细节。 But you can use variables using the standard Slim approach to define 'symbols' from decision/script tables. 但是您可以使用标准Slim方法使用变量来从决策/脚本表定义“符号” These symbols can then be used in any fixture. 这些符号然后可以在任何灯具中使用。

Using my fixture library you could combine a (Json) Http Test and Compare Fixture to achieve what you describe. 使用我的装置库,您可以结合使用(Json)Http测试比较装置来实现您所描述的内容。

Labels are global and can be shared across rest fixture instances. 标签是全局标签,可以在其余灯具实例之间共享。

However, if you want to use labels in your own custom fixture, you can save the data in to a variable like below and use it in any other custom fixtures 但是,如果您想在自己的自定义装置中使用标签,则可以将数据保存到如下所示的变量中,并在其他任何自定义装置中使用

|let|card_number1|js |response.jsonbody.card.number|$card=|

This would save card number in to a variable that is globally available to use in other tables 这会将卡号保存到一个全局变量中,供其他表使用

one point I would like to remind you though is that you don't have to write a separate fixture to compare the response from rest fixture. 我想提醒您的一点是,您不必编写单独的灯具来比较其余灯具的响应。 You can access the content of your response using response.jsonbody.element1 if you have json response and /root/element1/text() if you have an xml response. 如果您有json响应,则可以使用response.jsonbody.element1访问响应的内容;如果有xml响应,则可以使用/ root / element1 / text()。 So both posting a request at an end-point and validation can be done all in 1 go. 因此,既可以在端点上发布请求,又可以一次完成验证。 An example is below 下面是一个例子

|Table: RestFixture|${protocol}://${baseuri}:${port}/${resource_path}|longtimeoutconfig                                                                     |    
|setBody                                          |$req0                                                                                                                                   |
|setHeader                                        |Content-Type: application/json                                                                                                          |
|POST                                             |                                                 |200|                                                   |                    |
|let                                              |amount1                                          |js |response.jsonbody.amount                           |${amount}                     |

some very good examples can be found at https://cloud.github.com/downloads/smartrics/RestFixture/RestFixture-3.0.pdf 可以在https://cloud.github.com/downloads/smartrics/RestFixture/RestFixture-3.0.pdf中找到一些非常好的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM