Selenium standalone only works with chrome - selenium

I'm using my protractor tests run with a selenium standalone server.
Now i want to support all browsers.
I created a folder with the standalone (3.0.1) and a subfolder driver with IEDriver, geckodriver, chromedriver.
I added the path to the driver folder to the system PATH.
The standalone is running with no args (i do not know what to add).
My Config is:
var TIMEOUT = 20000;
exports.config = {
seleniumAddress: 'http://localhost:4448/wd/hub',
baseUrl: 'https://intmachine.project.com/',
/*
list the Suites to run locally here
*/
specs: [
'./UseCases/protractorTestcaseNightly.js',
],
capabilities: [
{
'browserName': 'firefox',
'firefox_binary':'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'
// shardTestFiles: false,
// maxInstances: 1,
// maxSessions: -1,
// restartBrowserBetweenTests: true,
},
],
getPageTimeout: TIMEOUT,
allScriptsTimeout: TIMEOUT,
jasmineNodeOpts: {
defaultTimeoutInterval: TIMEOUT,
isVerbose: true,
includeStackTrace: true
},
framework: "jasmine2",
//rootElement: 'html',
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.driver.manage().deleteAllCookies();
}
};
Update:
i changed "Capa..." to capabilities and now get:
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Target browser must be a string, but is <undefined>; did you forget to call forBrowser()?
at TypeError (native)
at Builder.build (C:\dev\dcps-angular\node_modules\selenium-webdriver\builder.js:417:13)
at DriverProvider.getNewDriver (C:\dev\dcps-angular\node_modules\protractor\built\driverProviders\driverProvider.js:42:27)
at Runner.createBrowser (C:\dev\dcps-angular\node_modules\protractor\built\runner.js:203:37)
at C:\dev\dcps-angular\node_modules\protractor\built\runner.js:293:21
at _fulfilled (C:\dev\dcps-angular\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\dev\dcps-angular\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\dev\dcps-angular\node_modules\q\q.js:796:13)
at C:\dev\dcps-angular\node_modules\q\q.js:556:49
at runSingle (C:\dev\dcps-angular\node_modules\q\q.js:137:13)
[launcher] Process exited with error code 100

Related

Bypass docker to run selenium scripts locally

I have selenium scripts to run on docker container selenium grid that were written before I join this project. due to the docker I don't have access to view the browser while running the scripts. And when scripts fail its very hard to debug. Can someone help me how to modify the below conf.js file to run my scripts locally for debugging.
Conf.js
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
const log = require('loglevel');
const util = require('#raven/common-protractor-test-utils');
const { ExpectedConditions } = require('protractor');
require('dotenv').config({ path: '.local.env' })
var testOutputDir = './test_output/';
let peregrineUrl = util.functionalTestBaseUrl(
'https://ea-webapp-int-raven.ocp-nonprod/'
);
let domainName = util.domainName;
exports.config = {
directConnect: true, // Set to true for local testing, or provide a link to a running selenium grid.
specs: ['e2e/**/mailbox-test.js', 'e2e/**/email-dumps-test.js'],
capabilities: {
browserName: 'chrome',
acceptInsecureCerts: true,
'goog:chromeOptions': {
w3c: false,
args: [
'--no-sandbox',
// '--headless',
'--disable-gpu',
'--window-size=1200,1200',
'--allow-insecure-localhost',
'--allow-running-insecure-content',
'--ignore_ssl',
'--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
],
},
},
allScriptsTimeout: 600000,
baseUrl: peregrineUrl,
framework: 'jasmine',
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 600000,
stackTrace: true
},
onPrepare: async () => {
/* Set Log Level */
log.setLevel('INFO');
log.info('Base URL: ' + peregrineUrl);
log.info('Domain Name: ' + domainName);
browser.ignoreSynchronization = true;
const ec = protractor.ExpectedConditions;
/* Set up the test directory. */
util.mkdirs(testOutputDir);
console.time('Peregrine Load Time');
await browser.get(peregrineUrl);
browser.driver.sleep(3000);
await username_area.sendKeys('rv-peregrine-test-user');
await password_area.sendKeys(process.env.SELENIUM_SERVICE_PASSWORD);
await agree_button.click();
await login_button.click();
},
};
When I try to change directConnect: ture and disable --headless to run locally I am able to see the chrome browser launched but the application opened. This is the trace from my console
[21:28:19] I/launcher - Running 1 instances of WebDriver
[21:28:19] I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:51650/devtools/browser/bf44c6c7-72a6-49e5-ab80-b13139ce9005
[15808:15796:0115/212822.298:ERROR:url_util.cc(414)] Invalid pattern javascript://
[15808:4128:0115/212826.609:ERROR:chrome_browser_main_extra_parts_metrics.cc(227)] START: ReportBluetoothAvailability(). If you don't see the END: message, this is crbug.com/1216328.
[15808:4128:0115/212826.610:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] END: ReportBluetoothAvailability()
[15808:4128:0115/212826.611:ERROR:chrome_browser_main_extra_parts_metrics.cc(235)] START: GetDefaultBrowser(). If you don't see the END: message, this is crbug.com/1216328.
[15808:15796:0115/212826.611:ERROR:device_event_log_impl.cc(214)] [21:28:26.611] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[15808:15796:0115/212826.613:ERROR:device_event_log_impl.cc(214)] [21:28:26.613] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[15808:4128:0115/212826.672:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
[15808:15796:0115/212826.687:ERROR:device_event_log_impl.cc(214)] [21:28:26.688] Bluetooth: bluetooth_adapter_winrt.cc:1206 Getting Radio failed. Chrome will be unable to change the power state by itself.
[15808:15796:0115/212826.730:ERROR:device_event_log_impl.cc(214)] [21:28:26.730] Bluetooth: bluetooth_adapter_winrt.cc:1284 OnPoweredRadioAdded(), Number of Powered Radios: 1
[15808:15796:0115/212826.732:ERROR:device_event_log_impl.cc(214)] [21:28:26.732] Bluetooth: bluetooth_adapter_winrt.cc:1299 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1
Thanks in advance

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);
}*

How to run successfully Protractor e2e test in Cloud Builders?

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.)

Protractor test with headless Selenium Webdriver randomly times out

I am having intermittent failures when running Selenium headless in my
server using xvfb. It works most of the times, but ~10% of runs it fails with this message:
[06:35:05] I/direct - Using FirefoxDriver directly...
[06:35:05] I/launcher - Running 1 instances of WebDriver
/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:54389/hub
at Error (native)
at onError (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83:11)
at Promise.invokeCallback_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (node.js:368:9)
From: Task: WebDriver.createSession()
at acquireSession (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
at Function.createSession (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
at Driver (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/firefox/index.js:271:38)
at Direct.getNewDriver (/opt/e2e/node_modules/protractor/built/driverProviders/direct.js:71:26)
at Runner.createBrowser (/opt/e2e/node_modules/protractor/built/runner.js:182:43)
at /opt/e2e/node_modules/protractor/built/runner.js:255:30
at _fulfilled (/opt/e2e/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/opt/e2e/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/opt/e2e/node_modules/protractor/node_modules/q/q.js:796:13)
at /opt/e2e/node_modules/protractor/node_modules/q/q.js:556:49
[06:35:51] E/launcher - Process exited with error code 1
I am running Selenium Webdriver 2.53.0
My config (using Mozilla Firefox 46.0.1):
exports.config = {
framework: 'jasmine2',
directConnect: true,
specs: ['specs/*.js'],
capabilities: {
browserName: 'firefox'
},
jasmineNodeOpts: {
defaultTimeoutInterval: 40000,
showColors: false
}
};
Test is just opening a browser:
describe('Home page flow test', function() {
it('should load home page', function() {
browser.get('https://www.google.com');
});
});
I am running Protractor with this command:
xvfb-run --server-args="-screen 0 1024x768x24" protractor --verbose
Thanks!

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