2

Following are my steps:

Then(/^I clear default folder name$/, function () { 
            var d = new Date();
            var n = d.getTime();      
           // var folderName= "Drawings"+Math.random()+'\n';
           var folderName= "Drawings"+n+'\n';
            var row = element.all(by.repeater('node in nodes.selectedNode.children  track by node._id')).last();
            var cells = row.all(by.tagName('input'));
            return cells.map(function (elm) {
                    return elm.clear().then(function(){
                            return elm.sendKeys(folderName);
                    });
              });
        });
Then(/^I see folder updated notification$/, function () {   
            return element(by.xpath("//div[contains(@class,'notification-bottom-bar show')]")).getText().then(function(itemss) {
                    console.log(itemss);
                    return expect(itemss).to.have.string(folderName+ 'has been updated'); 
                 })
});

In this case how we need to pass folderName value from first step to next step. Similarly how we can pass variable values between scenarios.

Saagar
  • 794
  • 3
  • 20
  • 41

1 Answers1

0

Your protractor tests reside in a normal javascript file only. So, you can just pass your data through normal global variables. Like so:

let folderName;
Then(/^I clear default folder name$/, function () { 
            var d = new Date();
            var n = d.getTime();      
            folderName= "Drawings"+Math.random()+'\n';
           var folderName= "Drawings"+n+'\n';
            var row = element.all(by.repeater('node in nodes.selectedNode.children  track by node._id')).last();
            var cells = row.all(by.tagName('input'));
            return cells.map(function (elm) {
                    return elm.clear().then(function(){
                            return elm.sendKeys(folderName);
                    });
              });
        });
Then(/^I see folder updated notification$/, function () {   
            return element(by.xpath("//div[contains(@class,'notification-bottom-bar show')]")).getText().then(function(itemss) {
                    console.log(itemss);
                    return expect(itemss).to.have.string(folderName+ 'has been updated'); 
                 })
});

Remember to declare folderName variable right at the top to make it accessible in all your step functions.

And to pass data between scenarios, you can use cucumber hooks. see more info at https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md

Dilip Agheda
  • 2,447
  • 1
  • 11
  • 15