Hello,
I see that Dredd executes my tests using User-Agent: Dredd/5.1.7 (Darwin 17.6.0; x64) and because of this my tests fail.
Is it possible to set my own User-Agent in dredd.yml ?
$ dredd
dredd.yml?reporter: [xunit, apiary]
custom:
apiaryApiKey: my-key
apiaryApiName: my-api
dry-run: null
hookfiles: null
language: nodejs
sandbox: false
server: null
server-wait: 3
init: false
names: false
only: []
output: [./report.xml]
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: 127.0.0.1
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: public.apib
endpoint: 'https://my.endpoint'
dredd --version output?dredd v5.1.7
Is it possible to set my own
User-Agentindredd.yml?
That's not possible. But I believe you could use the beforeEach hook to modify the request in this regard before Dredd sends it. Would that work for you?
@honzajavorek, can you explain more detailed, please, what should I do?
Thanks in advance!
You'd need to use hooks. See docs for an intro to hooks. They're available in multiple languages.
Given your hooks are in JavaScript, following hooks.js could solve your problem:
var hooks = require('hooks');
hooks.beforeEach(function (transaction) {
transaction.request.headers['User-Agent'] = 'FooBar/1.2.3';
});
Writing it from the top of my head though.
@honzajavorek thanks a lot!
@honzajavorek sorry, one more thing to clarify:
In case if I want to add the User-Agent only to some specific requests, I can use hooks.before, something like this:
hooks.before("Group Users > User [/users] > POST [POST /users]", function (transaction) {
transaction.request.headers['User-Agent'] = 'FooBar/1.2.3';
});
The structure of my .apib is:
## Group Users
## User [/users]
### POST [POST /users]
...
I'm not sure how I should define the request that have to be hooked, I've tried "Group Users > User [/users] > POST [POST /users]", but it seems to be not working.
Can you help please?
Thanks in advance!
I've already figured out how to do that here: https://github.com/apiaryio/dredd/issues/1074
Thanks.