Skip to content

isabella232/url-decorator

 
 

Repository files navigation

url-decorator

npm Build Status Coverage Status

Common plugin for:

which is intended to change test urls in runtime.

You can read more about gemini plugins here and hermione plugins here.

Installation

npm install url-decorator

Usage

Configuration

  • enabled (optional) Boolean – enable/disable the plugin; by default plugin is enabled
  • url (optional) Object - the list of url parameters, which will be added in each test url
    • query (optional) Array - the list of query parameters
      • queryParam (optional) Object - query parameter object with fields:
        • name (optional) String - name of query parameter
        • value (optional) String|Number|Array - value of query parameter
        • mode (optional) String - parameters joining strategy. Can be concat or override. By default is concat.
        • browsers (optional) String|RegExp|Array<String|RegExp> - browsers condition. Query parameter will be applied only for configured browsers.

Gemini usage

Add plugin to your gemini config file:

system:
  plugins:
    url-decorator/gemini: true

To pass additional url parameters you can use environment variables, which should start with GEMINI_URL_ or specify them in the gemini config file.

For example, you have the following test url: http://localhost/test/?name=bilbo and you want to add query parameter via environment variable:

GEMINI_URL_QUERY_TEXT=ololo gemini test

After that your test url will be changed to: http://localhost/test/?name=bilbo&text=ololo.

The same thing you can do using gemini config file:

url-decorator/gemini:
  url:
    query:
      - name: text
        value: ololo
    # or
        text: ololo

Note: environment variables have higher priority than config values.

Hermione usage

Add plugin to your hermione config file:

module.exports = {
    // ...

    plugins: {
        'url-decorator/hermione': true
    },

    // ...
};

To pass additional url parameters you can use environment variables, which should start with HERMIONE_URL_ or specify them in the hermione config file.

For example, you have the following test url: http://localhost/test/?name=hermione and you want to add query parameter via environment variable:

HERMIONE_URL_QUERY_TEXT=ololo hermione

After that your test url will be changed to: http://localhost/test/?name=hermione&text=ololo.

The same thing you can do using hermione config file:

'url-decorator/hermione': {
    url: {
        query: [
            {
                name: 'text'
                value: 'ololo'
            }
        ]
        // or
        query: {
            text: 'ololo'
        }
    }
}

Note: environment variables have higher priority than config values.

Concatenation of url parameters

In previous example you have seen how add url parameters. Now we look how to concat and override url parameters.

Suppose, you want to add query parameter name which is already presented in your test url: http://localhost/test/?name=bilbo and you don't want to override it:

url-decorator/gemini:
  url:
    query:
      - name: 'name'
        value: 'torin'
        mode: 'concat'
      # or
      - name: 'name'
        value: torin

The result url will look like: http://localhost/test/?name=bilbo&name=torin. How you understand, the result will be the same if concat would be any value except false.

Moreover for previous test url you can specify a set of values for one query parameter:

url-decorator/gemini:
  url:
    query:
      - name: 'name'
        value:
          - torin
          - gloin

The result url will look like: http://localhost/test/?name=bilbo&name=torin&name=gloin

If you want to override value of name query parameter:

url-decorator/gemini:
  url:
    query:
      - name: 'name'
        value: torin
        mode: 'override'

As a result url will look like: http://localhost/test/?name=torin.

You can do the same thing via environment variables. In this case concat value will be used from config to the same url parameter:

GEMINI_URL_QUERY_NAME=gloin gemini test

The result url will look like: http://localhost/test/?name=gloin

Browser conditions

url-decorator gives the opportunity to set each of query parameters only for specified browser(s).

Browsers can be:

  • single browser id string
  • array of multiple browser ids
  • browser mask (regular expression)
  • array of browser masks

Examples:

url-decorator/gemini:
  url:
    query:
      - name: 'name'
        value: torin
        browsers: firefox
url-decorator/gemini:
  url:
    query:
      - name: 'name'
        value: torin
        browsers:
         - firefox
         - chrome
url-decorator/gemini: {
    url: {
        query: [
            {
                name: 'name',
                value: 'torin',
                browsers: /ie-\d+/  //ie-8, ie-9, ie-10, ...
            }
        ]
    }
}
url-decorator/gemini: {
    url: {
        query: [
            {
                name: 'name',
                value: 'torin',
                browsers: [/ie-\d+/, 'firefox']
            }
        ]
    }
}

About

Common url decorator for gemini and hermione

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%