Giter Club home page Giter Club logo

Comments (13)

k2tzumi avatar k2tzumi commented on June 12, 2024 1

In order to be recognized json in loop, do I declare json list vars in importing yaml?

You can manage the path of the json file in the runbook from which you are importing

  • root.yaml
desc: xxxx xxxxx xxxx
vars:
  xxxxx_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  xxxxx_res:
    - "do some magic"
    - "do some magic"
 headers:
   accept: 'application/json'
   Content-Type: 'application/json'
   Host: 'xxxx'
   X-API-KEY: 'xxxxxx'

steps:
  normal:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.xxxxx_req)
    include:
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        headers: '{{ vars.headers }}'
        request: 'json://{{ vars.xxxxx_req[i]}}'
        response: '{{ vars. xxxxx_res[i] }}'
  • xx/xx/xxx/yamls/200/normal.yaml
vars:
  request: null
  response: null
  headers: null

steps:
  normal:
    desc:  xxxx xxxx xxxx xxxx
    req:
      /xxx/xxx/xx/xxxxx:
        post:
          headers: "{{ vars.headers }}"
          body:
            application/json: "{{ vars.request }}"
    test: steps.normal.res.status == 200
      && steps.normal.res.body contains vars.response

from runn.

k1LoW avatar k1LoW commented on June 12, 2024 1

What is include.vars ?

vars: section of include runner.

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

The json:// and yaml:// schemes are only allowed in the root of the vars: section.

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

I think it will be recognized as JSON if set as follows

loopVars:
- "../vars.json"
- "../vars_array.json"
- "../template.json.template"

jsonRequestBody: 'json://{{ vars.loopVars[i] }}'

from runn.

t-kitamura-axel avatar t-kitamura-axel commented on June 12, 2024

Thank you for advice.
But., still recognized json as string.

  • runn book yaml
desc: xxxx xxxxx xxxx
vars:
  xxxxx_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  xxxxx_res:
    - "do some magic"
    - "do some magic"
steps:
  normal:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.xxxxx_req)
    req:
      /xxx/xxx/xx/xxxxx:
        post:
          headers:
            accept: "{{ vars.header.accept }}"
            Content-Type: "{{ vars.header.content_type }}"
            Host: "{{ vars.header.host }}"
            X-API-KEY: "{{ vars.header.x_api_key }}"
          body:
            application/json: "json://{{ vars.xxxxx_req[i] }}"
    test: steps.normal.res.status == 200
      && steps.normal.res.body contains vars.xxxxx_res[i]

Avobe yaml is imported one.
Bellow yaml is importing yaml.
In order to be recognized json in loop, do I declare json list vars in importing yaml?
If so, it might be hard a little in my usecase.
Because test case is many, vars will be fat. Also it is hard to find certain test case vars in importing one.
Than that, I want to summarize vars to imported yaml.
I think that way is view better for seeing the details individually.

importing runn book yaml (root)

  xxx xxx xx:
    desc: xxx xxxx xxxx
    include:I 
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        header:
          accept: "{{ vars.header.accept }}"
          content_type: "{{ vars.header.content_type }}"
          host: "{{ vars.header.host }}"
          x_api_key: "{{ vars.header.x_api_key }}" 

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

fmm...

I do not know what you want to achieve.
If possible I would be glad to get the smallest example I can try.
You shouldn't need to have a test server by using the API on httpbin.org or github.com.

from runn.

t-kitamura-axel avatar t-kitamura-axel commented on June 12, 2024

I want to recognize json as json in impoted yaml.
In runn, Is it impossible to make bellow yaml ?

desc: xxxx xxxxx xxxx
vars:
  xxxxx_req: <- json list
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  xxxxx_res:
    - "do some magic"
    - "do some magic"
steps:
  normal:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.xxxxx_req)
    req:
      /xxx/xxx/xx/xxxxx:
        post:
          headers:
            accept: "{{ vars.header.accept }}"
            Content-Type: "{{ vars.header.content_type }}"
            Host: "{{ vars.header.host }}"
            X-API-KEY: "{{ vars.header.x_api_key }}"  
          body:
            application/json: "json://{{ vars.xxxxx_req[i] }}" <- json  as json
    test: steps.normal.res.status == 200
      && steps.normal.res.body contains vars.xxxxx_res[i]

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

In runn, Is it impossible to make bellow yaml ?

No, it cannot.
The json:// scheme only works for root in the vars: section ( or include.vars: ).

from runn.

k2tzumi avatar k2tzumi commented on June 12, 2024

I want to recognize json as json in impoted yaml.

Do you want the list of json file paths in the root runbook to be specified in the vars of the include and expanded as a json request?

I would be able to give you better advice if I could get a more concrete image of the test you want to achieve.

from runn.

t-kitamura-axel avatar t-kitamura-axel commented on June 12, 2024

What is include.vars ?

The json:// scheme only works for root in the vars: section ( or include.vars: ). 

With this, the root yaml vars will be fat, right?
If many test is written in root yaml. I think root yaml vars is fat.

bellow root yaml fat example

desc: xxxx xxxxx xxxx
vars:
  xxxxx_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  xxxxx_res:
    - "do some magic"
    - "do some magic"
  yyyyy_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  yyyy_res:
    - "do some magic"
    - "do some magic"
 zzzz_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  zzzz_res:
    - "do some magic"
    - "do some magic"
  wwww_req:
    - "../../json/req/200/normal1.json"
    - "../../json/req/200/normal2.json"
  wwww_res:
    - "do some magic"
    - "do some magic"
   .
   .
   .
   .
 headers:
   accept: 'application/json'
   Content-Type: 'application/json'
   Host: 'xxxx'
   X-API-KEY: 'xxxxxx'

steps:
  normal-x:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.xxxxx_req)
    include:
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        headers: '{{ vars.headers }}'
        request: 'json://{{ vars.xxxx_req[i]}}'
        response: '{{ vars. xxxx_res[i] }}'
  normal-y:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.yyyyy_req)
    include:
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        headers: '{{ vars.headers }}'
        request: 'json://{{ vars.yyyy_req[i]}}'
        response: '{{ vars. yyyy_res[i] }}'
  normal-z:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.zzzz_req)
    include:
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        headers: '{{ vars.headers }}'
        request: 'json://{{ vars.zzzz_req[i]}}'
        response: '{{ vars. zzzz_res[i] }}'

 normal-w:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.wwwww_req)
    include:
      path: xx/xx/xxx/yamls/200/normal.yaml
      vars:
        headers: '{{ vars.headers }}'
        request: 'json://{{ vars.wwww_req[i]}}'
        response: '{{ vars. wwww_res[i] }}'
 .
.
.
.

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

How about xxxxx_req and yyyyy_req and zzzz_req and wwww_req and all responses in one JSON?

desc: xxxx xxxxx xxxx
vars:
  reqres: "json://../../json/reqres.json"
   .
   .
   .
  headers:
    accept: 'application/json'
    Content-Type: 'application/json'
    Host: 'xxxx'
    X-API-KEY: 'xxxxxx'

steps:
  normal-x:
    desc:  xxxx xxxx xxxx xxxx
    loop:
      count: len(vars.reqres.xxxxx)
    req:
      /xxx/xxx/xx/xxxxx:
        post:
          headers:
            accept: "{{ vars.header.accept }}"
            Content-Type: "{{ vars.header.content_type }}"
            Host: "{{ vars.header.host }}"
            X-API-KEY: "{{ vars.header.x_api_key }}"  
          body:
            application/json: "{{ vars.reqres.xxxxx[i].req}}"
    test: steps.normal.res.status == 200
      && steps.normal.res.body contains vars.reqres.xxxxx[i].res
.
.
.

With this, the root yaml vars will be fat, right?

I don't know if this is what you want, but at least all requests and responses can be externalized to reqres.json.

from runn.

k2tzumi avatar k2tzumi commented on June 12, 2024

With this, the root yaml vars will be fat, right?

How to divide the scenario to solve the problem of large root yaml? It would be better to consider how to divide the scenario.

  • Define the steps of a repeating scenario as a single scenario itself.
  • Define several steps as a single scenario.
    For example, split the yaml as one scenario with normal-x and normal-y steps (Have normal-z and normal-w processed in a separate file)

from runn.

k1LoW avatar k1LoW commented on June 12, 2024

Hi @t-kitamura-axel
runn now support wildcards in json:// and yaml://.

I think this will be one way to solve your problem.

from runn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.