Protractor tests run instable ( ETIMEDOUT ) - protractor

We are working to make our Protractor E2E tests stable, so our development and deployment flow can depend on it.
However, until now we are not able to have a fully stable run of E2E tests.
Sometimes, inconsistent which, some test somewhere is failing due a ETIMEDOUT in ClientRequest in selenium-webdriver.
Failed: ETIMEDOUT connect ETIMEDOUT 5.255.93.10:80
Stack:
Error: ETIMEDOUT connect ETIMEDOUT 5.255.93.10:80
at ClientRequest.<anonymous> (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/http/index.js:365:15)
at emitOne (events.js:90:13)
at ClientRequest.emit (events.js:182:7)
at Socket.socketErrorListener (_http_client.js:306:9)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at emitErrorNT (net.js:1265:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From: Task: WebDriver.findElements(By(css selector, *[id="chart_doubleSlider_brush"]))
at WebDriver.schedule (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/webdriver.js:344:17)
at WebDriver.findElements (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/webdriver.js:897:22)
at /var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/protractor/built/element.js:141:44
at Promise.invokeCallback_ (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /var/lib/jenkins/workspace/HPS UI E2E Tests/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
We would like to have a way to stabilise this test, for example to have some kind of retry mechanism in the Protractor run or on low level a retry mechanism of the failed http request. Right now, we have not found any solution for it.
More information about our setup:
Our test-scripts are executed by a Jenkins machine.
We use grunt-protractor-runner to start our protractor tests.
The tests are executed on BrowserStack.
We set up a BrowserStack tunnel between BrowserStack and our Jenkins machine before the test start up. Since the application we test is on a private environment. ( we use https://www.npmjs.com/package/browserstacktunnel-wrapper )
We test on IE11, Chrome ( latest ), FireFox ( latest, 38, 31 ). However there is no relation between timeouts and the browser where testing on.
The execution time of our tests runs are 30 minutes for each browser.
We have set options.agent to http.Agent({keepAlive: true,keepAliveMsecs: 30 * 1000, timeout: 10 * 30 * 1000} of our http request, to keep the sockets open.
In the capabilities of Protactor we set 'browserstack.local': true and 'browserstack.debug': true.
We would like to hear your advice on how to stabilise our Protractor tests.

Related

Cypress tests passing locally but not passing in Azure DevOps pipeline

My Cypress tests are passing locally when running this command:
npx cypress run --browser chrome --env api_endpoint="https://myApp.com",page="TestAppsForCdnIntegrations/myApp.html"
However, when I run this in my Azure DevOps pipeline, I'm getting the below error:
2021-09-29T15:51:07.2749462Z *****************************************
2021-09-29T15:51:07.2762053Z Run Cypress
2021-09-29T15:51:07.2771057Z *****************************************
2021-09-29T15:51:20.4370810Z (Run Starting)
2021-09-29T15:51:20.4448402Z │ Cypress: 6.9.1
2021-09-29T15:51:20.4449343Z │ Browser: Chrome 94
2021-09-29T15:51:20.4468328Z Running: examples\get_js_config.spec.js (1 of 7)
2021-09-29T15:52:20.4675196Z
2021-09-29T15:52:20.4676105Z Timed out waiting for the browser to connect. Retrying...
2021-09-29T15:53:17.2314823Z EPERM: operation not permitted, unlink 'C:\Users\admin\AppData\Roaming\Cypress\cy\production\browsers\chrome-stable\run-5596\CypressCache\Default\Cache\data_1'
2021-09-29T15:53:17.2316098Z Error: EPERM: operation not permitted, unlink 'C:\Users\admin\AppData\Roaming\Cypress\cy\production\browsers\chrome-stable\run-5596\CypressCache\Default\Cache\data_1'
I'm not sure why it's working locally, but not in the pipeline.
Can someone please advise what is causing this & how to resolve?

Webdriver-manager update unable to download geckodriver

I am trying to setup protractor for my angular app automation. I am on Node version 12 , I installed protractor version 5.4.3. when I use webdriver-manger update --proxy=blahblahproxy.com , I see the below error.
[13:37:06] I/config_source - curl -oC:\Users\******\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\gecko-response.json '**corpproxy**/repos/mozilla/geckodriver/releases' -H 'host:api.github.com'
(node:15904) UnhandledPromiseRejectionWarning: Error: response status code is not 200. It was 407
at Request.<anonymous> (C:\Users\*****\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\binaries\config_source.js:181:28)
at Request.emit (events.js:311:20)
at Request.onRequestResponse (C:\Users\*****\AppData\Roaming\npm\node_modules\protractor\node_modules\request\request.js:1059:10)
at ClientRequest.emit (events.js:311:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at Socket.socketOnData (_http_client.js:476:22)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
(node:15904) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15904) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Chrome and selenium standlaone server are updated/downlaoded just fine
when i do webdriver-manager status
[13:39:39] I/status - selenium standalone version available: 3.141.59
[13:39:39] I/status - chromedriver version available: 80.0.3987.106
[13:39:39] I/status - geckodriver is not present
[13:39:39] I/status - IEDriverServer is not present
[13:39:39] I/status - android-sdk is not present
[13:39:39] I/status - appium is not present
Under corporate proxies we will face issues like this.
The 407 Proxy Authentication Required is an HTTP response status code indicating that the server is unable to complete the request because the client lacks proper authentication credentials for a proxy server that is intercepting the request between the client and server.
Option 1 : Try using selenium-standalone npm package. This is similar to webdriver-manager.
https://www.npmjs.com/package/selenium-standalone
Install this package globally
npm i -g selenium-standalone
Then to download/install the drivers
selenium-standalone install
Then to start the server
selenium-standalone start
(Or)
Option 2: https://stackoverflow.com/a/53358685/8903949

webdriver-manager start: Error: connect ETIMEDOUT

I am configurating protractor environment by the http://www.protractortest.org/#/ website.When execute
webdriver-manager start
webdriver-manager: using global installed version 12.0.6
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 192.30.255.116:443
at Object._errnoException (util.js:1024:11)
at _exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
But sometimes,it will execute success.
The environment is:
Protractor –version:5.2.0
Java –version:1.8.0_131
Node –v:v8.9.0
Npm –v:5.5.1
Can someone please telling me what is happening here. Your assistance is appreciated.
If you are behind a VPN, you may need to add a proxy.
> set HTTP_PROXY=http://proxy.host.blah:80
> set HTTPS_PROXY=http://proxy.host.blah:80
> webdriver-manager start
This worked for me anyway.

How to set proxy in config for protector

I am using protector with angular 4, when i run e2e test it failed to download some dependency from network as it blocked within my org proxy.
I tried to set proxy in protractor.conf.js, but it did not work for me.
capabilities: {
'browserName': 'chrome',
'proxy': {
'proxyType': 'manual',
'httpProxy': 'http://ptx.proxy.corp.sopra:8080'
}
below error I'm getting when run ng e2e
webpack: Compiled successfully.
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 216.58.204.144:443
at Object._errnoException (util.js:1024:11)
at _exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
Can someone please tell me how to use the proxy within in.
I did find a way around to set the proxy, I set up proxy in system environment variable with key http_proxy and ng e2e ran fine for me.

Protractor does not close browser when a server is unavailable

I do e2e testing with protractor. When my application is running on a server the tests pass fine and a browser is closed afterward, however when the server is down the browser remains (Firefox, Chrome). It is OK on my local machine but I am experimenting with running tests on remote CI machine and afraid that the tests can spawn multiple browser windows if the server fails to run. How to make sure protractor closes the browser window in such situation?
Here is my configuration:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'../test/e2e/*.js'
],
capabilities: {
'browserName': 'firefox'
},
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
and the test is:
'use strict';
describe('typicaClient', function() {
browser.get('index.html');
it('test', function() {
expect('str').toMatch('str');
});
});
Protractor leaves browser open on those errors which it doesn't recognize and cannot handle.
Check out the example below. This error thrown by spawn() process is unhandled by Protractor and it exits with an error code - 199
describe('sample test', function(){
it('Sample Check', function(){
browser.get("http://www.protractortest.org/#/");
browser.sleep(5000);
var terminal = require('child_process').spawn('34e3545')
});
});
Output:
[18:26:46] I/local - Starting selenium standalone server...
[18:26:46] I/launcher - Running 1 instances of WebDriver
[18:26:46] I/local - Selenium standalone server started at http://192.168.1.5:61146/wd/hub
Started
[18:26:49] E/launcher - spawn 34e3545 ENOENT
[18:26:49] E/launcher - Error: spawn 34e3545 ENOENT
at exports._errnoException (util.js:873:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
[18:26:49] E/launcher - Process exited with error code 199
To avoid these , handle gracefully the error at non-protractor commands
describe('sample test', function(){
it('Sample Check', function(){
browser.get("http://www.protractortest.org/#/");
browser.sleep(5000);
var terminal = require('child_process').spawn('34e3545').on('error', function(err) {
fail('Test is failing because we provided an invalid process')
});
});
});
Output in this case:
[18:57:22] I/local - Starting selenium standalone server...
[18:57:22] I/launcher - Running 1 instances of WebDriver
[18:57:22] I/local - Selenium standalone server started at http://192.168.1.5:49867/wd/hub
Started
F
Failures:
1) sample test Sample Check
Message:
Failed: Test is failing because we provided an invalid process
Stack:
Error: Failed: Test is failing because we provided an invalid process
at ChildProcess.<anonymous> (C:\Users\ayannam\WebstormProjects\demo\errorHandle.js:7:13)
at emitOne (events.js:77:13)
at ChildProcess.emit (events.js:169:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
1 spec, 1 failure
Finished in 6.582 seconds
See it this case Un-handled exception is handled and Protractor throws an error code - 1 which is gracefully handled