How do I store a value in a global variable and then use it in subsequent steps of a scenario in protractor



  • 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.



  • 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() {
                browser.driver.manage().window().maximize();
                //create a global variable like below
    global.variableName = "hello";
            }
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2