How to run successfully Protractor e2e test in Cloud Builders? - selenium

I'm setting up CI for our project that is in Angular. We are using Google Cloud Platform's Cloud Builder for CI. Everything is going smoothly, we can setup the environment, install packages via npm, build the project using angular-cli and deploy. But the problem is that our test cases (e2e) in Protractor keeps getting an error. What are we missing here?
This is for the Continuous Integration using Google Cloud Builders, we are running the protractor in headless mode, and using the puppeteer's chromium as the chrome's binary path
This is my protractor.conf.js
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath()
exports.config = {
allScriptsTimeout: 1000000,
specs: [
'./e2e/*.e2e-spec.ts',
'../e2e/*.e2e-spec.ts'
],
capabilities: {
// browserName: 'chrome',
browserName: 'chrome',
chromeOptions: {
binary: process.env.CHROME_BIN,
args: ['--headless', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage', '--disable-setuid-sandbox']
}
},
// seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
// ignoreUncaughtExceptions: true,
directConnect: true,
},
};
This is the error we are getting in cloud builders
[11:24:12] E/launcher - unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /workspace/node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-1033-gcp x86_64)
[11:24:12] E/launcher - WebDriverError: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /workspace/node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Related

Selenium Chrome Driver Nightmare (nodejs)

I'm trying to setup tests with NodeJS, Selenium & Jest. They work fine on my Mac but both a Windows and Linux install are failing with similar errors:
WITHOUT THE PATH EXPLICITLY SET
WebDriverError: unknown error: cannot find Chrome binary
at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:522:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:548:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:474:28)
WITH THE PATH EXPLICITLY SET
WebDriverError: unknown error: Chrome failed to start: exited
abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/local/bin/chromedriver is no longer running, so ChromeDriver is
assuming that Chrome has crashed.)
FWIW on a linux machine running chromedriver directly I get this:
Starting ChromeDriver 98.0.4758.80
(7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758#{#972})
on port 9515 Only local connections are allowed. Please see
https://chromedriver.chromium.org/security-considerations for
suggestions on keeping ChromeDriver safe. ChromeDriver was started
successfully.
Setting the path directly has not worked, using a globally installed (/usr/local/bin/chromedriver) binary and a local one node_modules/chromedriver/bin/chromedriver). None of the following options has made any difference:
.addArguments([
"--ignore-certificate-errors",
"--disable-extensions",
"--disable-popup-blocking",
"--enable-automation",
"--disable-dev-shm-usage",
"--no-sandbox",
"--headless",
"--log-path=/home/jsp/projects/proj/selenium/chrome.log",
"--append-log",
"--verbose",
"--enable-chrome-logs",
"--port=9222"
])
Enabling logging generated an empty chrome.log file. I tried simplifying and this is what I ended up with that again works on my Mac but not on the Linux test box.
const { Builder } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
let chromeTest = async () => {
let options = new chrome.Options()
.setChromeBinaryPath('/usr/local/bin/chromedriver')
.addArguments(["headless", "ignore-certificate-errors", "disable-dev-shm-usage", "no-sandbox"]);
let driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(options)
.build();
await driver.quit();
};
chromeTest();
Selenium: 4.1.1
ChromeDriver: 98.0.4758.80
Ubuntu 20.04.3
Any help would be greatly appreciated.

How to launch protractor tests from remote jenkins?

I am unable to launch my protractor test from remote jenkins.
I am able to launch the test if the jenkins is installed in my local.
I am not sure if it is because of the direct connect. i also tried to launch the protractor test through selenium webdriver but couldnt make it. please help on this.
The error i am getting is
*[16:06:14] I/launcher - Running 1 instances of WebDriver
[16:06:14] I/direct - Using ChromeDriver directly...
[16:16:15] E/launcher - session not created
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=88.0.4324.104)
(Driver info: chromedriver=88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324#{#1784}),platform=Windows NT 10.0.17763 x86_64)
[16:16:15] E/launcher - SessionNotCreatedError: session not created
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=88.0.4324.104)
(Driver info: chromedriver=88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324#{#1784}),platform=Windows NT 10.0.17763 x86_64)
at Object.checkLegacyResponse (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\http.js:509:13)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:93:5)
From: Task: WebDriver.createSession()
at Function.createSession (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\chrome.js:761:15)
at Direct.getNewDriver (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\driverProviders\direct.js:77:33)
at Runner.createBrowser (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\runner.js:195:43)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\runner.js:339:29
at _fulfilled (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:834:54)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:863:30
at Promise.promise.promiseDispatch (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:796:13)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:556:49
at runSingle (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:137:13)
[16:16:15] E/launcher - Process exited with error code 199
npm ERR! Test failed. See above for more details.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE*
my config.ts file is
*export let config: Config = {
// The address of a running selenium server.
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect:true,
framework:'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
//allScriptsTimeout: 30000,
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['../features/MasterEdit.feature'],
cucumberOpts: {
// require step definitions
//tags:"#SmokeTesting",
format:'json:./cucumberreport.json',
require: [
'./stepDefinitions/*.js', // accepts a glob,
]
},
onComplete: () =>{
var options = {
theme: 'bootstrap',
jsonFile: './cucumberreport.json',
output: './cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: true,
metadata: {
"App Version":"0.3.2",
"Test Environment": "STAGING",
"Browser": "Chrome 54.0.2840.98",
"Platform": "Windows 10",
"Parallel": "Scenarios",
"Executed": "Remote"
}
};
reporter.generate(options);
}*

Appium/Protractor - Cordova app - When I try to run simple test I get following error - Failed to get sockets matching: #webview_devtools_remote_

I'm trying to run a simple test on my hybrid app with Appium + Protractor and I am unable to since I am getting following error:
Failed to get sockets matching: #webview_devtools_remote_.*15239
I am using Ubuntu, and on it I have set up Appium and Protractor, tried literally every solution I have found on the internet, could not resolve the issue.
Only thing that would "remove" the error is adding following code into capabilities:
chromeOptions: {
androidPackage: "com.android.chrome"
},
But then I only get in the app, and Appium server just gets stuck at:
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8001/wd/hub/session] with body: {"desiredCapabilities":{"chromeOption {"androidPackage":"com.android.chrome","androidUseRunningApp":true,"androidDeviceSerial":"1cdc4ed10c027ece"}}}
It won't start the spec file at all.
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
seleniumAddress: 'http://localhost:4723/wd/hub',
allScriptsTimeout: 50976,
specs: [
'test.js'
],
capabilities: {
platformName: 'Android',
platformVersion: '8.0.0',
deviceName: 'Galaxy S9',
app: 'path_to_app',
autoWebview: true,
browserName: '',
appPackage: 'app_package_name',
newCommandTimeout: '140',
chromeOptions: {
androidPackage: "com.android.chrome"
}
},
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
framework: 'jasmine',
jasmineNodeOpts: {
print: function () {}, //remove protractor dot reporter
defaultTimeoutInterval: 100000
}
}
It seems to be a common appium problem.
Issue from github: https://github.com/appium/python-client/issues/255
Fix:
See here: https://github.com/blutter/appium-crosswalk-fix
This also happens if you want to switch to a web browser on the mobile phone, while you have already instanciated an appium on a mobile app.
To avoid having this exception, such as described in
https://github.com/appium/appium/issues/11189, [Chromedriver] Error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. (Original error: unknown error: Failed to get sockets matching: #webview_devtools_remote_.*24811 ,
before trying to switch to your web browser on the mobile phone just, reinstantiate the appium forcefully to web like below. Appium will pilot the appp then be forced and
switch cleanly to the web browser without complaining anymore :
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); // or other browsers
desiredCapabilities.setCapability("noReset", true );
try
{
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AppiumDriver driver = new AppiumDriver(url, desiredCapabilities);
}
catch (Exception e )
{
}
I got rid of a similar error after changing the default browser of the mobie device to Chrome from Samsung. Also updated the chromedriver version on laptop running appium server to match the version of Chrome version running on mobile. And appium was started with appium --chromedriver-executable=/usr/local/bin/chromedriver.
Also had setWebContentsDebuggingEnabled=true in desired_capabilities.

Protractor fails to find web-manager

I have protractor installed in project folder + web-manager (installed the same way).
The web-manager is started:
$npm-run webdriver-manager status
webdriver-manager: using global installed version 12.0.6
- selenium standalone version available: 3.8.1 [last]
- chromedriver version available: 2.35 [last]
- geckodriver version available: v0.19.1 [last]
- IEDriverServer is not present
However, when I run protractor
$ npm-run protractor conf.js
[15:22:12] I/launcher - Running 1 instances of WebDriver
[15:22:12] E/local - Error code: 135
[15:22:12] E/local - Error message: No update-config.json found. Run 'webdriver-manager update' to download binaries.
[15:22:12] E/local - Error: No update-config.json found. Run 'webdriver-manager update' to download binaries.
Here is my conf.js for protractor
exports.config = {
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['tests/common/*.js'],
};
How do I fix the config/run protrator?
you need to run npm-run webdriver-manager update to install webdriver binary and selenium-standalon-server.jar if you never execute it, otherwise the command will update existed stuff.
After that, find update-config.json in node_modules\protractor\node_modules\webdriver-manager\selenium.
Its content should be like this:
{
"chrome": {
"last": "xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\chromedriver_2.35.exe",
"all": ["xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\chromedriver_2.35.exe"]
},
"standalone": {
"last": "xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\selenium-server-standalone-3.9.0.jar",
"all": ["xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\selenium-server-standalone-3.9.0.jar"]
},
"gecko": {
"last": "xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\geckodriver-v0.19.1.exe",
"all": ["xxx\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\geckodriver-v0.19.1.exe"]
}
}
Then execute node_modules\.bin\webdriver-manager start to see will success or fail.
FYI, you need JDK 8 installed to start webdriver-manager.
Finally, found a solution using gulp.
The config below allows to run webmanager-update, webmanager-start and proptractor on by one.
gulp.js
var gulp = require('gulp'),
shell = require('gulp-shell'),
connect = require('gulp-connect'); // Webserver
protractor = require('gulp-protractor').protractor,
webdriver_standalone = require('gulp-protractor').webdriver_standalone,
webdriver_update = require('gulp-protractor').webdriver_update;
gulp.task('webdriver_update', webdriver_update);
gulp.task('webdriver_standalone', webdriver_standalone);
gulp.task('e2e', ['webdriver_update'], function() {
gulp.src(["tests/protractor/*.js"])
.pipe(protractor({
configFile: "protractor.conf.js",
args: [
//'--baseUrl', 'http://127.0.0.1:8000',
// '--suite', 'login',
// '--params.environment', 'test'
]
}))
.on('error', function(e) { throw e })
});
protractor.conf.js
exports.config = {
seleniumServerJar: './node_modules/webdriver-manager/selenium/selenium-server-standalone-3.9.0.jar',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
},
};
(using URL for selenium server is impotant)
Launch command:
gulp e2e

Protractor : ERROR - Unable to start a WebDriver session

I wrote test cases three months back at that time they worked fine now i want to run those test cases in another system so i did basic setup. When i try to run protractor test case now they are failing with 'Unable to start a WebDriver session'. I have tried so many solutions but they didn't work for me.
Here i am attaching my protractor.conf.js file and error details.
protractor.conf.js
'use strict';
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
baseUrl: 'http://localhost:' + (process.env.PORT || '3036'),
chromeOnly: true,
// To get the maximimum test screen size
onPrepare: function() {
browser.driver.manage().window().maximize();
},
// list of files / patterns to load in the browser
specs: [
'e2e/attributeSection/search_spec.js', 'e2e/attributeSection/create_spec.js',
'e2e/attributeSection/edit_spec.js', 'e2e/attribute/search_spec.js',
'e2e/attribute/create_spec.js', 'e2e/attribute/edit_spec.js',
'e2e/classification/search_spec.js', 'e2e/classification/create_spec.js',
'e2e/classification/edit_spec.js', 'e2e/classificationGroup/create_spec.js',
'e2e/classificationGroup/edit_spec.js'
],
exclude: [],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
binary: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
args: [],
extensions: [],
}
},
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 60000
}
};
Error in console
Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver
ERROR - Unable to start a WebDriver session.
C:\Users\Cronj- 4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145:16)
at ClientRequest.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1552:9)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:155:22)
at Function.webdriver.WebDriver.createSession (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:129:30)
at [object Object].Builder.build (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\builder.js:416:22)
at [object Object].DriverProvider.getNewDriver (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\driverProvider.js:38:7)
at [object Object].Runner.createBrowser (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:180:37)
at C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:257:21
at _fulfilled (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
Could anyone help me out? Thanks in advance
I believe the "chromeOnly" option got deprecated in v2.0.0.
chromeOnly: true,
This used to mean use "direct" mode without a selenium server. But since both firefox and chrome support direct mode, the property was renamed to "directConnect". So change that line to:
directConnect: true,
In this mode you don't need a selenium server, so you can drop the seleniumAddress property which is just confusing folks.
See https://github.com/angular/protractor/pull/1933/files
I ran webdriver-manager start in one command prompt and protractor in another command prompt then only test cases started running