westor
westor

Reputation: 1534

Change page url while Protractor test is running

In my protractor tests I want to do something in a page (page1). After that in the same testscript I want to go to another page (page2) to check the results.

describe('something', function() {
  describe('foo', function() {
    browser.get(url_1);
    it("should do something with elem1 on page1", function() {
      var elem1 = element(by.css("..."));
      ...
    });
  });
  describe('bar', function() {
    browser.get(url_2);
    it("should do something with elem1 on page2", function() {
      var elem1 = element(by.css("..."));
      ...
    });
  });
});

As long as I not try to navigate to url_2, the tests from page1 are working. But in the above example the browser navigates to page1 and immediately navigates to page2. And I get a "Failed: No element found using locator" error for page1. I thought commands like browser.get and browser.setLocation should also become part of the controlFlow ?

How can I solve this problem?

Upvotes: 0

Views: 657

Answers (1)

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

You need to wrap the browser.get(url_2); statement inside beforeAll() method like below.

describe('something', function() {
  describe('foo', function() {
    beforeAll(function(){
        browser.get(url_1);
    })

    it("should do something with elem1 on page1", function() {
      var elem1 = element(by.css("..."));
      ...
    });
  });
  describe('bar', function() {

    beforeAll(function(){
        browser.get(url_2);
    })

    it("should do something with elem1 on page2", function() {
      var elem1 = element(by.css("..."));
      ...
    });
  });
});

Upvotes: 1

Related Questions