Selenium in Jenkins failure test - selenium

I'm trying to run selenium in Jenkins. When I run it locally the test always passed. But in Jenkins I always get error:
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#ee7d9f1
Starting ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e) on port 10010
Only local connections are allowed.
Dec 18, 2017 2:35:43 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
File cannot be found
Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 6.807 sec <<< FAILURE!
no such element: Unable to locate element:
Im using Jenkins, Selenium and Testing

This issue is related to your mac, and is a connection issue to other server on which you are running your script. for resolving this issue please read this: https://discussions.apple.com/thread/1789752

Related

Timed out connecting to Chrome, giving up error - EC2 instance jenkins running selenium tests

I'm receiving the following error when trying to run my selenium tests through an ec2 instance using Jenkins.
Running the tests locally works fine.
The output of the logs:
[[1;34mINFO[m] -------------------------------------------------------
[[1;34mINFO[m] T E S T S
[[1;34mINFO[m] -------------------------------------------------------
[[1;34mINFO[m] Running [1mTestSuite[m
[main] INFO com.DefaultTest - BeforeClass start
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 106.0.5249.61 (resolved driver for Chrome 106)
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as /var/lib/jenkins/.cache/selenium/chromedriver/linux64/106.0.5249.61/chromedriver
Starting ChromeDriver 106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249#{#569}) on port 42525
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Oct 11, 2022 11:13:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Oct 11, 2022 11:13:55 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 106, so returning the closest version found: a no-op implementation
Oct 11, 2022 11:13:55 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 106.
Oct 11, 2022 11:13:55 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.3` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
[main] INFO com.page.MainApp - URL: data:,
[main] INFO com.DefaultTest - AfterClass start
[main] INFO com.DefaultTest - BeforeClass start
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 106.0.5249.61 (resolved driver for Chrome 106)
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as /var/lib/jenkins/.cache/selenium/chromedriver/linux64/106.0.5249.61/chromedriver
Starting ChromeDriver 106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249#{#569}) on port 50463
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1665530123.403][WARNING]: Timed out connecting to Chrome, retrying...
[1665530132.591][WARNING]: Timed out connecting to Chrome, retrying...
[1665530149.634][WARNING]: Timed out connecting to Chrome, giving up.
[1665530156.893][WARNING]: Timed out connecting to Chrome, retrying...
[1665530166.364][WARNING]: Timed out connecting to Chrome, retrying...
[1665530186.944][WARNING]: Timed out connecting to Chrome, giving up.
Build timed out (after 3 minutes). Marking the build as failed.
[[1;34mINFO[m]
[[1;34mINFO[m] Results:
[[1;34mINFO[m]
[[1;34mINFO[m] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[[1;34mINFO[m]
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1;31mBUILD FAILURE[m
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] Total time: 03:07 min
[[1;34mINFO[m] Finished at: 2022-10-11T23:16:40Z
I'm not sure how to resolve this.
I have google chrome and chromedriver on the same version (v106).
I've attempted adding countless arguments that people have suggested, but still can't get it to run successfully

The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I get the following error when I run this command on headless ubuntu 20.04
selenium-side-runner -c "browserName=chrome chromeOptions.args=[disable-infobars, headless]" myproject.side
info: Running Mynew.side
FAIL MySuiteOne/MytestOne.test.js
● Test suite failed to run
WebDriverError: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
at Object.throwDecodedError (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:560:13)
at Executor.execute (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:486:26)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.255s
Ran all test suites.
My Chrome version:91.0.4472.77 installed in /usr/bin/google-chrome
Chrome driver version: chromedriver#90.0.1
I also tried commands
selenium-side-runner /path/to/your-project.side
selenium-side-runner -c "browserName=chrome chromeOptions.args=[headless, no-sandbox, disable-dev-shm-usage, disable-infobars] chromeOptions.binary='/usr/bin/google-chrome'" Mynew.side
But still, I am facing the same error. Is there any way to fix this. I am trying to configure selenium in Ubuntu 20.04 Amazon EC2 instance.
Per the Chromedriver Download page,
If you are using Chrome version 91, please download ChromeDriver 91.0.4472.19

Jenkins run causes Selenium tests to fail with org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally?

I'm running Selenium tests for Chrome through Jenkins pipeline on CentOs machine. When ran, it gives following error -
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
[testng] (unknown error: DevToolsActivePort file doesn't exist)
[testng] (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
However if I run same tests with same command(which is used through Jenkins pipeline) from that machine locally, it succeeds.
For the same, I went through link1, link2, link3 and other answers. From those answers, only following helped -
chrome_options.add_argument('--headless')
But this run tests with chrome in headless mode which is not my intention.
In my case, having matching Chrome browser and chromedriver version did not help, also Chrome has executable permission for all.
Note: I've my CentOs machine display enabled
Could you please help to understand what is causing this failure? Also please help with what code and/or machine level changes I've to make for its success.
EDIT:
In case, this helps to get more info.
ls | grep 'chrome' under /usr/bin gave following result -
lrwxrwxrwx 1 root root 31 Jan 20 12:29 google-chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 32 Jan 20 12:29 google-chrome-stable -> /opt/google/chrome/google-chrome
Do you run chromedriver locally on a linux machine? What version of CentOS are you using? If you haven't already you need to install the correct chromedriver for linux. As far as I know if you want to run via Jenkins you have to run in headless mode. But I may be wrong. Below is another post that can help:
Steps to Install and run headless chrome browser on centos 6.5 using chrome driver
Below are my own settings for chrome options:
options.addArguments("--headless");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--window-size=1920,1080");
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--disable-infobars");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--force-device-scale-factor=1");

Quarkus quickstart example test - Connection refused

Beginning with Quarkus, I build the getting-started-example and it works fine. But if I run the tests with mvn test it doesn't work, I'm getting a connection refused error. The port 8081 is ok, so what's wrong with it?
[INFO] Running org.acme.quickstart.GreetingResourceTest
2020-02-20 07:55:20,150 INFO [io.quarkus] (main) Quarkus 1.1.0.Final started in 0.080s.
2020-02-20 07:55:20,154 INFO [io.quarkus] (main) Profile test activated.
2020-02-20 07:55:20,154 INFO [io.quarkus] (main) Installed features: []
[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 6.345 s <<< FAILURE! - in org.acme.quickstart.GreetingResourceTest
[ERROR] testHelloEndpoint Time elapsed: 3.192 s <<< ERROR!
java.net.ConnectException: Connection refused: connect
at org.acme.quickstart.GreetingResourceTest.testHelloEndpoint(GreetingResourceTest.java:17)
[ERROR] testGreetingEndpoint Time elapsed: 2.029 s <<< ERROR!
java.net.ConnectException: Connection refused: connect
at org.acme.quickstart.GreetingResourceTest.testGreetingEndpoint(GreetingResourceTest.java:23)
Updating Quarkus to 1.2.1.Final solved the problem, tests are working now.

Protractor redirects and times out immediately after loading page

I'm trying to write some e2e specs for an AngularJS application. I have one Jasmine spec in test/e2e/test_spec.js:
describe('basic functionality', function() {
it('loads the home page', function() {
browser.get('/');
expect(browser.getCurrentUrl()).toMatch(/localhost/);
});
});
Terminal output when the spec is run:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
Stacktrace:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
at Array.forEach (native)
From: Task: waiting for page to load for 10000ms
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:3:13)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 10.955 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
While the console is sitting on [launcher] Running 1 instances of WebDriver, Chrome opens and displays the index page for a fraction of a second, then changes to a blank page with data:text/html,<html></html> in the address bar.
Here is my protractor.config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: 'test/e2e/**/*_spec.js',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true
},
allScriptsTimeout: 20000,
onPrepare: function() {
return browser.driver.get("http://localhost:8100");
}
};
My webdriver-manager stuff seems to be up to date, although the tool doesn't seem to have a way to output version numbers.
> webdriver-manager status
selenium standalone is up to date
chromedriver is up to date
IEDriver is not present
Why is the spec failing?
Edit: This is what is printed to the terminal when onPrepare is commented out:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
unknown
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
timeout: timed out after 30000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 34.27 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Edit 2: When I do browser.get("http://google.com"), Chrome briefly shows the data: and data:text/html,<html></html> pages, redirects to Google, then times out looking for Angular.
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
Stacktrace:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
at Array.forEach (native)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 12.186 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Set baseUrl: 'http://localhost:8100' in your protractor.config.js file. From the Protractor Reference Config:
A base URL for your application under test. Calls to protractor.get() with relative paths will be prepended with this.
It is a sporadic open bug in protractor https://github.com/angular/protractor/issues/5103
Instead of this
browser.get('http://juliemr.github.io/protractor-demo/');
Using this has solved my issue.
browser.driver.get('http://juliemr.github.io/protractor-demo/');
I had that problem in chrome. I read somewhere that protractor starts on that data:text/html,<html></html> page. Calling browser.get(...) navigates away from that page. My idea was to open chrome already on my base url. I accomplished that by adding it to the capabilities like this:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--app=www.yourBaseUrl.com']
}
},
It's a bit of a hack, but it seems to have done the trick.