I want to retrieve a value in 'Given' function and then store it in a global variable so that the value is accessible in subsequent steps of a scenario in protractor cucumber typescript based automation project.

1 Answer 1


Go to your conf.js file and create an onPrepare function, there you can define and initialize a global variable. Below is a sample:

exports.config = {
        directConnect: true,
        capabilities: {
            'browserName': 'chrome'
        framework: 'jasmine',
        baseUrl: "http://url.com",
        specs: ['./*_specs.js'],

        onPrepare: function() {
            //create a global variable like below
global.variableName = "hello";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.