Why do multiple GET requests fail?

I am trying to run a protractor test in an Amazon EC2 environment using the PhantomJS browser. I know that it is not recommended to the PhantomJS user using Protractor, but this is the only choice that I have now. Tests always run in a Win7 environment.

When a test looks like this, it always works great

describe('Portal Login End 2 End test', function() { it('should automatically redirect to login /form', function() { browser.get(''); expect(browser.getLocationAbsUrl()).toMatch("/login"); }); it('should automatically redirect to dashboard page after successful login', function() { element(by.model('user.username')).sendKeys('admin'); element(by.model('user.password')).sendKeys('admin'); element(by.buttonText('Sign in')).click(); expect(browser.getLocationAbsUrl()).toMatch("dashboard/home"); }); }); 

but when a GET request is executed in a beforeEach function like this

  describe('Portal Login End 2 End test', function() { beforeEach(function() { browser.get(''); } it('should automatically redirect to login', function() { expect(browser.getLocationAbsUrl()).toMatch("/login"); }); it('should automatically redirect to dashboard page after successful login', function() { element(by.model('user.username')).sendKeys('admin'); element(by.model('user.password')).sendKeys('admin'); element(by.buttonText('Sign in')).click(); expect(browser.getLocationAbsUrl()).toMatch("dashboard/home"); }); }); 

tests are not executed most of the time, but not always, with the following error

UnknownError: communication error with remote browser. He may have died. Assembly Information: version: '2.43.1', version: '5163bce', time: '2014-09-10 16:27:33' System information: host: 'ip-10-249-98-182', ip : '10 .249.98.182 ', os.name:' Linux ', os.arch:' amd64 ', os.version:' 2.6.32- 504.el6.x86_64 ', java.version:' 1.6.0_45 'Information about driver: driver.version: EventFiringWebDriver

Therefore, when two GET requests are executed in the same test, it most often fails, but when only one request is executed, it always works. And, as I wrote above, two GET requests work fine in Win7, but not in Linux.

I saw several posts with this error, but not how to fix it. Anyone out there with a solution?

+6
source share
2 answers

I'm not sure beforeEach waiting for the browser to complete, but the it function is waiting. Try wrapping the get call in the it function.

 describe('Portal Login End 2 End test', function() { beforeEach(function() { it('redirects',function(){browser.get('');}); }); // ..... }); 
0
source

If you have problems, as you said, this is because the browser is not waiting for input in beforeEach, add browser.waitForAngular ();

 describe('Portal Login End 2 End test', function() { beforeEach(function() { browser.get(''); } it('should automatically redirect to login', function() { browser.waitForAngular(); expect(browser.getLocationAbsUrl()).toMatch("/login"); }); it('should automatically redirect to dashboard page after successful login', function() { element(by.model('user.username')).sendKeys('admin'); element(by.model('user.password')).sendKeys('admin'); element(by.buttonText('Sign in')).click(); expect(browser.getLocationAbsUrl()).toMatch("dashboard/home"); }); }); 

because it checks execution in order, you do not need to call it in every block.

you can also try calling the browser.waitForAngular () function in the beforeEach function, although I prefer to make a call in this function.

0
source

Source: https://habr.com/ru/post/978284/


All Articles