admin管理员组文章数量:1387317
I try to update/export global variable (firstString) to use and validate it in 'Then' step. How do I export it correctly? When I'm doing it this way, the firstString is undefined. It works only when I export/import it inside steps. How can I update it globally and use it in 'Then' file?
helpers.js:
let firstString;
given.js:
let { firstString } = require('./helpers')
Given('I have first {string}', function (stringValue) {
return stringRequest(stringValue).then(response => {
firstString = response
});
});
module.exports = { firstString }
then.js:
firstString = require('./helpers').firstString
Then('blablabla {string}', function (stringType) {
console.log(firstString)
});
I try to update/export global variable (firstString) to use and validate it in 'Then' step. How do I export it correctly? When I'm doing it this way, the firstString is undefined. It works only when I export/import it inside steps. How can I update it globally and use it in 'Then' file?
helpers.js:
let firstString;
given.js:
let { firstString } = require('./helpers')
Given('I have first {string}', function (stringValue) {
return stringRequest(stringValue).then(response => {
firstString = response
});
});
module.exports = { firstString }
then.js:
firstString = require('./helpers').firstString
Then('blablabla {string}', function (stringType) {
console.log(firstString)
});
Share
Improve this question
asked Sep 24, 2019 at 7:30
TgralakTgralak
1473 silver badges11 bronze badges
1 Answer
Reset to default 8If I am correct in understanding what you want to do you are wanting to store data across steps. Todo that you will want to use the world instance that cucumber provides for you. You can access the world instance in steps via the this
keyword.
So what you would do is
Given('I have first {string}', function (stringValue) {
return stringRequest(stringValue).then(response => {
this.firstString = response
});
});
Then('blablabla {string}', function (stringType) {
console.log(this.firstString)
});
For more information on the world instance check out https://github./cucumber/cucumber-js/blob/master/docs/support_files/world.md
本文标签: javascriptCucumber JS How to exportupdate global variable outside GivenWhenThen stepStack Overflow
版权声明:本文标题:javascript - Cucumber JS: How to exportupdate global variable outside GivenWhenThen step? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744511399a2609906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论