Error on protractor: "Timed out waiting for the WebDriver server at http://127.0.0.1:50636/hub" executing on firefox - protractor

I was executing my scripts on firefox and got one notification for Firefox upgrade which I closed. Started execution again but I'm getting error as below,
Rohits-MacBook-Pro:FFAutomation rohitgathibandhe$ /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/bin/protractor conf.js
Report destination: target/screenshots/Report.html
Using FirefoxDriver directly...
[launcher] Running 1 instances of WebDriver
/Users/rohitgathibandhe/npm-global/lib/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:50636/hub
at Error (native)
at onError (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83:11)
at Promise.invokeCallback_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (node.js:406:9)
From: Task: WebDriver.createSession()
at acquireSession (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
at Function.createSession (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
at Driver (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/firefox/index.js:271:38)
at [object Object].DirectDriverProvider.getNewDriver (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/driverProviders/direct.js:76:16)
at [object Object].Runner.createBrowser (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/runner.js:203:37)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/runner.js:293:21
at _fulfilled (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:796:13)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:556:49
[launcher] Process exited with error code 1
My config file is as below,
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'Report.html',
reportTitle: 'Execution Report',
showSummary: true,
showQuickLinks: true,
pathBuilder: function(currentSpec, suites, browserCapabilities) {
// will return chrome/your-spec-name.png
return browserCapabilities.get('browserName') + '/' + currentSpec.fullName;
}
});
exports.config = {
directConnect: true,
//seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {'browserName': 'firefox'},
framework: 'jasmine',
specs: ['Login_spec2.js','Article_spec.js'],
allScriptsTimeout: 200000,
getPageTimeout: 200000,
jasmineNodeOpts: {
defaultTimeoutInterval: 200000
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
},
onPrepare: function() {
var width = 1300;
var height = 1200;
browser.driver.manage().window().setSize(width,height);
jasmine.getEnv().addReporter(reporter);
afterAll(function(done) {
process.nextTick(done);
})
}
};
Other details are:
Other details are as below: protractor#3.2.2, nodeVersion: 4.2.4, npmVersion: 2.14.12, jasmine: 2.4.1, selenium-webdriver: 2.52.0, firefox: 47
Kindly help me with solution to this issue.

You have to do the following to make it work:
upgrade protractor to the latest, currently 3.3.0, version which would also bring selenium-webdriver 2.53
downgrade firefox to version 46 and don't let it update for a while (there are compatibility issues)

In my case it was the local firewall (iptables on Linux) that was very restrictive such that WebDriver could not contact the Selenium server hub at whatever TCP port.
To make it work I turned off the firewall. The long term solution was to adjust the firewall rules such that this type of connection is allowed.
If you want your scripts communicate directly with the Firefox|Chrome Driver (bypassing the Selenium server entirely) then try adding the directConnect: true in your protractor.conf.js

I solved it by change the browser (use Chrome instead of Firefox).
In C:__projectWorkspace__\src\test\javascript\protractor.conf.js
modify the entry
capabilities: {
'browserName': 'firefox',
to
capabilities: {
'browserName': 'chrome',
That wasn't enough. I had to change also the webBrowserDriver 'cause after the JHipster installation the 2.22 version was written in protractor.conf.js file but in the path:
node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.25.exe
the chromedriver was 2.25 version so i edited the entry
webbrowserDriver = prefix + 'node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.25.exe';
and it worked!

I solved this by restarting the computer.
I don't know why, but I think that "suspending" the computer can cause some bad configuration with Selenium Server.
Ah, I run commands on the command prompt as an administrator.

I fixed this issue by changing directConnect to true in base.config.js from repository folder.
or
webdriver-manager clean and then webdriver-manager start

Related

WebdriverIO can not create session to test Android emulator with Appium

I am using Visual Studio Code and WDIO with Appium to test Android on emulator by Android Studio, but I can not run Appium for some reason. However Android home and Java home has been set and Appium Doctor confirms necessary dependencies are completed, no fix needed.
I have tried with Appium stand-alone and from Command too.
Wit Appium standalone the ERROR log is the below:
ERROR webdriver: Request failed with status 500 due to session not created: Unable to create session from {
"desiredCapabilities": {
"platformName": "android",
"appium:deviceName": "Pixel",
"appium:platformVersion": "10.0",
"appium:app": "\u002fUsers\u002fzsolt\u002fappium_js\u002fApiDemos-debug.apk"
If I add ['appium'] to services in wdio.config.js the ERROR log is the below, though Appium stand-alone is shut:
ERROR #wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: Appium exited before timeout (exit code: 2)
[HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
at ChildProcess.<anonymous> (C:\Users\zsolt\Documents\AppiumTestProject\node_modules\#wdio\appium-service\build\launcher.js:103:16)
at Object.onceWrapper (events.js:417:26)
at ChildProcess.emit (events.js:310:20)
at ChildProcess.EventEmitter.emit (domain.js:482:12)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
This is my wdio.config.js file with using Appium stand-alone:
exports.config = {
runner: 'local',
port: 4723,
specs: [
'./test/specs/**/*.js'
],
exclude: [
// 'path/to/excluded/files'
],
maxInstances: 10,
capabilities: [{
platformName: 'android',
'appium:deviceName': 'Pixel',
'appium:platformVersion': '10.0',
'appium:app': '/Users/zsolt/appium_js/ApiDemos-debug.apk'
}],
logLevel: 'error',
bail: 0,
baseUrl: 'http://localhost',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['selenium-standalone',
/*['appium', {
//command : 'appium'
}]*/],
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
These are my:
"devDependencies": {
"#wdio/local-runner": "^6.1.11",
"#wdio/mocha-framework": "^6.1.8",
"#wdio/selenium-standalone-service": "^6.0.16",
"#wdio/spec-reporter": "^6.1.9",
"#wdio/sync": "^6.1.8",
"appium": "^1.17.1"
Has anybody an idea what am I doing wrong?
Welcome to Stack-overflow!
Below is my configuration and I believe you are missing some important details.
{
platformName: 'Android',
maxInstances: 1,
'appium:deviceName': 'Device Name',
'appium:platformVersion': '8'
'appium:orientation': 'PORTRAIT',
'appium:app': 'Path to App',
'appium:automationName': 'UiAutomator2',
'appium:noReset': true,
'appium:newCommandTimeout': 240,
}
There are boilerplates from maintainers themselves here.
I have played with the boilerplates and was able to run the tests on android emulator through Appium finally.
I have then compared the differences in conf.js and figured out, the below is needed to execute the test.
services:[
[
'appium',
{
// For options see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
args: {
// For arguments see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
},
command: 'appium',
},
],
],
Interesting but actually the test runs with only the below capabilites too:
capabilities: [{
platformName: 'Android',
'appium:deviceName': 'Pixel 2',
'appium:app': join(process.cwd(), './ApiDemos/ApiDemos-debug.apk'),
}],
When I execute the test it logs almost the same error messages as before though at the end of the execution it runs the test on the emulator. I did not use the Appium Desktop app.
Not perfect but works...
I guess this issue has been sorted out.
Cheers
Also you need to install the Appium service:
$ npm i #wdio/appium-service --save-dev
Finally check in your wdio.conf.js:
port: 4723, // default appium port
services: [
[
'appium',
{
args: {
},
command: 'appium'
}
]
],
Check that the file you are running is inside the correct folder when you do the 'npx wdio'.
this file

How can I fail Karma tests if there are unhandled rejections?

A couple of places propose this solution:
window.addEventListener('unhandledrejection', function(err) {
window.__karma__.error(err); // yeah private API ¯\_(ツ)_/¯
});
But it throws:
Uncaught TypeError: Cannot read property 'error' of undefined
I'm able to get reports of unhandled rejections with the following setup:
karma.conf.js:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha'],
files: [
'setup.js',
'test.js',
],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
});
};
setup.js:
window.addEventListener('unhandledrejection', function(ev) {
window.__karma__.error("unhandled rejection: " + ev.reason.message);
});
test.js:
it("test 1", () => {
Promise.reject(new Error("Q"));
});
it("test 2", (done) => {
setTimeout(done, 1000);
});
Separating setup.js from test.js is not necessary. I just like to have such setup code separate from the tests proper.
When I run karma start --single-run I get:
25 01 2017 07:20:07.521:INFO [karma]: Karma v1.4.0 server started at http://0.0.0.0:9876/
25 01 2017 07:20:07.523:INFO [launcher]: Launching browser Chrome with unlimited concurrency
25 01 2017 07:20:07.528:INFO [launcher]: Starting browser Chrome
25 01 2017 07:20:08.071:INFO [Chrome 55.0.2883 (Linux 0.0.0)]: Connected on socket g-BGwMfQLsQM128IAAAA with id 22107710
Chrome 55.0.2883 (Linux 0.0.0) ERROR
unhandled rejection: Q
Chrome 55.0.2883 (Linux 0.0.0): Executed 1 of 2 ERROR (0.006 secs / 0.001 secs)
Caveat
Reports of unhandled rejections are asynchronous. This has a few consequences.
The example I gave has a 2nd test that takes 1 second to complete. This gives time to the browser to report the unhandled rejection in the 1st test. Without having this delay, Karma terminates without detecting the unhandled rejection.
Another issue is that an unhandled rejection caused by test X may be discovered while test X+1 is running. The runner's report may make it look like X+1 is the test the caused the issue.

'Globals' are not working as expected in protractor 4.0.0?

we have the following setting in our onPrepare function of config file-
exports.config = {
directConnect: true,
baseUrl: env.baseUrl,
capabilities: env.capabilities,
onPrepare: function () {
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect; // by removing this line error is not thrown
browser.manage().window().maximize();
},
setDefaultTimeout : 60 * 1000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'../Features/*.feature'
],
cucumberOpts: {
monochrome: true,
strict: true,
plugin: ["pretty"],
require: ['../StepDefinitions/*.js', '../Support/*.js'],
tags:'#AddActiveTip,#AddInActiveTip,~#AddActiveManufacturer,~#AddInActiveManufacturer'
//tags:'#TestSplitText'
}
};
since the upgrade to protractor 4.0, I am getting the following error and the browser hangs indefinitely and the error does not help to debug in anyway.
error:
> protractor Config/config.js --troubleshoot
[22:38:12] I/direct - Using FirefoxDriver directly...
[22:38:12] I/launcher - Running 1 instances of WebDriver
/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:87
if (e.message.indexOf(errMsg) !== -1) {
^
TypeError: Cannot read property 'indexOf' of undefined
at Function.ErrorHandler.isError (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:87:30)
at Function.ErrorHandler.parseError (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:98:26)
at process.<anonymous> (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/launcher.js:169:54)
at emitOne (events.js:82:20)
at process.emit (events.js:169:7)
at process.emit (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/node_modules/source-map-support/source-map-support.js:419:21)
at process._fatalException (node.js:224:26)
npm ERR! Test failed. See above for more details.
is anyone else facing this issue? are there any major changes that I am missing?
The error message shown has nothing to do with "globals", it is working as expected! my scripts were failing randomly due to network latency issues.But the error messages need to improved as the user has no idea what caused the error!
Marking it closed as I was able debug this issue!

I'm not able to run protractor test in firefox but in chrome it runs fine

When I am trying to run Protractor e2e test in firefox, it launches the browser but my test scripts do not get executed.
I am using windows Server 2012 R2 machine with firefox version 46.0.1 and Selenium 2.53.0.
It gives me the following error:
Using FirefoxDriver directly...
[launcher] Running 1 instances of WebDriver
code\ui\dgui\node_modules\protractor\node_modules\selenium-webdriver\http\util.js:89
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:58798/hub
I tried running Selenium standalone
code\ui\dgui\node_modules\protractor\selenium>java -jar selenium-server-standalone-2.53.0.jar
09:37:21.214 INFO - Launching a standalone Selenium Server
09:37:21.285 INFO - Java: Oracle Corporation 25.91-b14
09:37:21.285 INFO - OS: Windows Server 2012 R2 6.3 amd64
09:37:21.293 INFO - v2.53.0, with Core v2.53.0. Built from revision 35ae25b
09:37:21.332 INFO - Driver class not found: com.opera.core.systems.OperaDriver
09:37:21.332 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
09:37:21.336 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN8
09:37:21.336 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
09:37:21.336 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
09:37:21.434 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:37:21.434 INFO - Selenium Server is up and running
I am using npm run e2e command to execute my test
my Config file:
exports.config = {
allScriptsTimeout: 30000,
suites: {
test Suit: 'e2e/TestSuites/Tests/*.js',
},
multiCapabilities: [
// We will want to eventually include the following options to split out tests to multiple instances
{'browserName': 'firefox'}
],
// only for firefox and chrome - IE will require using a selenium server
directConnect : true,
// make sure that the baseURL reflects the configuration of the web server
baseUrl: 'http://10.26.5.13:8000/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'tests/test-results',
// this will produce distinct xml files for each capability
filePrefix: browserName + '-xmloutput',
modifySuiteName: function(generatedSuiteName, suite) {
// this will produce distinct suite names for each capability,
// e.g. 'firefox.login tests' and 'chrome.login tests'
return browserName + '.' + generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
},
resultJsonOutputFile: 'tests/test-results/output.json'
};
Found this link: https://github.com/angular/protractor/issues/3182,
I was also facing similar issue.
I tried installing Firefox v44.0.2 and then executed my scripts, it worked.
I was using Firefox v46 earlier, and my scripts were not executing with Firefox v46.
Had the same problem with firefox version 49.0.2 and Selenium 2.52.0
I installed Firefox portable 46 and everything worked for me.
And in my protractor.config-file i set:
...
capabilities: {
// FIREFOX portable in version 46.0.1
'browserName': 'firefox',
"firefox_binary": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe",
"binary_": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe"
},
// tells protractor to directly connect to the webdriver
directConnect: true
...
I downloaded Firefox Portable here: http://www.m64.info/index.php/firefox-64-bit-portable
That's also a good opportunity to have more than one version of firefox "installed" :-)
Hope somebody will help it!
Follow Protractor setup here:
http://www.protractortest.org/#/tutorial#setup
These versions are what worked for me:
Node: v6.9.4
NPM: v3.10.10
Protractor: v5.1.0
Selenium WebDriver: 3.0.1
Firefox: 51.0.1
conf.js:
exports.config = {
framework: 'jasmine',
// no need for seleniumAddress for firefox and chrome
specs: ['spec.js'],
capabilities: {
browserName: 'firefox',
firefoxPath: 'C:/Program Files/Mozilla Firefox/firefox.exe'
},
directConnect: true // for firefox and chrome
}
https://github.com/angular/protractor/blob/master/lib/config.ts
Add the binary (firefox.exe) location as moz:firefoxOptions capability
exports.config = {
capabilities: {
browserName: 'firefox',
shardTestFiles: false,
'moz:firefoxOptions': {
'binary': "<your_path>/Mozilla Firefox/firefox.exe"
}
},

selenium standalone terminates with unknown error

when i start my test the browser opens and an ip is displayed after few sec the ip is changed to "data;" in terminal the test is been looped and sends err ms
empresss-Mac-mini:myApp admin$ protractor test/e2e.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
Failures:
1) header Module should check title text
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Message:
Failed: header is not defined
Stack:
ReferenceError: header is not defined
at Object.<anonymous> (/Users/admin/myApp/www/head.spec.js:8:13)
From: Task: Run it("should check title text") in control flow
From asynchronous test:
Error
at Suite.<anonymous> (/Users/admin/myApp/www/head.spec.js:7:4)
at Object.<anonymous> (/Users/admin/myApp/www/head.spec.js:1:63)
1 spec, 1 failure
Finished in 30.019 seconds
[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
my config file is
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../www/head.spec.js'],
multiCapabilities: [
{
browserName: 'chrome'
}],
onPrepare: function(){
browser.driver.get('http://192.168.1.2:8100');
}
}
i named it as e2e.js
my test file is
describe('header Module', function(){
beforeEach(function() {
var header = element(by.css('title'));
});
it('should check title text',function(){
expect(header.getText()).toContain('Ionic Blank Starter');
});
});
i downloaded an blank ionic app and i want to test the header contains elements "Ionic Blank Starter"
You are not handling async code well in your project. header.getText() returns a promise which you need to resolve before asserting the text. You can do something like this:
describe('header Module', function(){
it('should check title text',function(callback){
var header = element(by.css('.title'));
header.getText()
.then(function (text) {
expect(text).toContain('Ionic Blank Starter');
callback();
});
});
});