Question

In our angular application we have started using protractor tool but its still in early phase and for one test we have stuck at a point, we are not finding any way to transfer data from one test to another, with in the scope of function it is giving me fetched value and I can print it on command prompt as well. But when I want this value to be used for other tests then it is returning undefined for that variable.

Guys, you all must have faced this scenario please mention different possible ways of achieving this use case.

Waiting for your reply !!

Thanks !!

No correct solution

OTHER TIPS

You should do all things that want to be shared in the beforeEach function. This runs everytime before each test.

Do something like this:

describe('My tests', function() {
  var sharedState;

  it('should test something', function() {
    sharedState = {
      someValue: 1
    };
  });

  it('should use shared state', function() {
    expect(sharedState).toBeDefined();
  });
});

If you want to share state across different test files you can use the global scope.

Test file 1

describe('File 1', function() {
  it('should test something', function() {
    global.sharedState = {
      someValue: 1
    };
  });    
});

Test file 2

describe('File 2', function() {
  it('should use shared state', function() {
    expect(global.sharedState).toBeDefined();
  });
});

I accomplished this by creating global variables that can be used like normal variables throughout the files. For example, if you needed a count to be used across multiple tests, set it like this:

browser.params.count = 5;

(You can use anything for the name instead of count).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top