Huyin Dong
Huyin Dong

Reputation: 31

E2E test Protractor issue: redirect to another page in the same window

The website I need to test requires login. However, you have to stay in the same window to keep your login information, which means if you close the window of this page, you need to login again. This gives me the problem: when I am using protractor to test the websites, it seems like each time I use browser.get(url). It will turn off the browser and open another one for the test, then I lost my login information. So I can't test the pages I want to test. Can anybody give me some suggestions, I have not figured it out for one days. Crazy!

describe('Sample List page test', function(){
	beforeEach(function(){
	browser.driver.get('http://localhost:8600/#/login');
        browser.driver.sleep(2000);
        browser.driver.findElement(by.id('google-login')).click();
	});
	it('should list all the items in samples',function(){
  	browser.get("#/osctr/sample");
    expect(browser.getTitle()).toBe("Sample");
	}
});
});

In the above codes, I can't get information in the sample page because I used brower.get(url), it will open a new page which I will lose my login information.

Upvotes: 1

Views: 1754

Answers (1)

nilesh
nilesh

Reputation: 14287

When you do browser.driver.get(), it would open a new windown. That's how selenium-webdriver works. There was an issue opened longtime back to attach webdriver instance to an existing browser window which is now marked as NotFeasible.

If you want to keep the browser session intact, you can do browser.driver.get() in before() method instead of beforeEach() and have multiple tests that work on the same browser instance and quit the browser in after method.

Upvotes: 1

Related Questions