Feature Requests & Ideas

For bug reports and questions, please use the in-app chat or support@mabl.com.

Parametrized snippets

As a test author, I want the option of variables used in a snippet to be passed to it as parameters, so that I can use the same snippet with different input multiple times without having to declare/mutate the input variables in previous steps (and pollute the global namespace for no apparent reason in the process).

  • Lukas Linhart
  • Aug 8 2019
  • For Consideration
  • Attach files
  • Admin
    Anton Hristov commented
    21 Aug 13:52

    Lukas, I assume you are aware of the ability to access previously defined variables inside a JavaScript step (e.g. mablInputs.variables.user.myVariable ). Can you please elaborate a bit more how you would like this to be improved to help us better understand the request?

  • Lukas Linhart commented
    22 Aug 10:53

    Yes, I am aware of that.

    I would like to pass data to the snippet step, and not create a global variable in some previous step. I don't imagine the solution to be difficult (that of course depends to some extent on how well the existing thing is designed), all the necessary mechanisms are already in place.

    1) add the 'snippet' key under the variables object:

    const mablInputs = {
    variables: {
            user: {}, // variables defined in preceding steps
            snippet: {}, // variables passed to the snippet instance via UI
        },
    };

     

    2) pass an object to specific snippet step/instance through a single text input, possibly with some special syntax for passing global variables:

    {
        foo: 'foo',
        bar: {{whatever-syntax-for-global-vars}},
    }

     

    3) use the parameters in a snippet:

    function mablJavaScriptStep(mablInputs, callback) {
        const foo = mablInputs.varuables.snippet.foo;
        console.log(foo);
        callback(true);
    }

     

    No need to create a global variable in advance.

Copyright © 2019 mabl Inc. All rights reserved.