Comments (55)
I tried to use the callback onConsoleMessage
on the browser instance but it does not seem to work, see admc/wd#296 (comment)
Any ideas why?
from grunt-mocha-webdriver.
Looks like that callback is only available for WebPage
instances. But we have only a browser
instance here. Hmmm ...
from grunt-mocha-webdriver.
Did you try wd .log()
as I suggested in #46 ?
This is what I get:
describe('test log', function () {
it.only('test', function(done) {
var browser = this.browser;
browser.get('http://saadtazi.com/')
.eval('console.log("yeah yeah");')
.eval('console.error("no no");')
.log('browser')
.then(function(logs) { console.log(logs);})
.nodeify(done);
});
});
ouput:
[ { level: 'INFO',
message: 'yeah yeah (undefined:undefined)',
timestamp: 1398077004967 },
{ level: 'INFO',
message: 'no no (undefined:undefined)',
timestamp: 1398077004980 } ]
You can put the .log()
in a top-level afterEach(function(done) {})
if needed.
I am not sure how onConsoleMessage() works though.
from grunt-mocha-webdriver.
Hmmm, that would work. But I want a callback. Anytime the browser writes a line to the console, it should be seen asap in my console. I do not want to wait until .log(...)
is called and only then it's shown.
Also, I have my mocha scripts configured so that they bail asap on the first error. I have lots of reasons why I am after a callback instead.
from grunt-mocha-webdriver.
FYI: I just tried --webdriver-logfile=phantom.log
as recommended by @sebv here (admc/wd#296 (comment)) but this only bumps webdriver logs into the file, not the browser log.
But if your goal is to capture js errors, then webdriver logfile contains js errors:
[ERROR - 2014-04-21T13:20:16.332Z] Session [ad8fff80-c957-11e3-9478-d781ecd29fcc] - page.onError - msg: TypeError: 'undefined' is not a function (evaluating 'document.writee('you should NOT see this<br/>')')
[ERROR - 2014-04-21T13:20:16.332Z] Session [ad8fff80-c957-11e3-9478-d781ecd29fcc] - page.onError - stack:
So one option would be to allow phantomjs flags to be passed at startup through grunt config.
What I mean is:
// in Gruntfile.js
...
webdriver:
phantom: {
src: ['test/sanity.js'],
options: {
testName: 'phantom test',
usePhantom: true,
usePromises: true,
phantomPort: 5555,
phantomStartFlags: [--webdriver-logfile', 'phantom.log'] // note that ignoreSslErrors could also be set here
}
},
...
Then you could set a file stream
(using fs.createReadStream()
) that detects ERROR
in your top-level before()
...
@jmreidy, what do you think of the proposed solution? any thoughts/concerns? Not really KISS but could allow other options like --load-images=false
, --debug=true
, proxy settings with --proxy=
...
from grunt-mocha-webdriver.
@saadtazi did you try --webdriver-loglevel=DEBUG
, I know in pure phantomjs you can get those logs.
from grunt-mocha-webdriver.
@sebv I just tried it, and it works:
DEBUG - 2014-04-21T13:53:16.529Z] Session [49dde560-c95c-11e3-8b27-317586dbde40] - page.onConsoleMessage - i am a console.log() message
from grunt-mocha-webdriver.
Hmm, I tried but failed. Where can I find the phantom.log
file?
In the grunt file I have this:
phantomStartFlags: [
'--webdriver-logfile', 'phantom.log',
'--webdriver-loglevel', 'DEBUG'
],
and in the e2e setup hook (top-level before) this:
this.browser.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
then on the client side code I added console.warn('blabah');
but am not seeing anything :(
from grunt-mocha-webdriver.
Sorry, i was not clear: phantomStartOptions is not implemented yet. I was proposing to @jmreidy a new feature.
from grunt-mocha-webdriver.
Also, i think onConsoleMessage is not a method of wd browser object (because it is not part of selenium jsonwire protocol like sebv feom wd mentionned in the wd issue you opened). So this.browser.onConsoleMessage should be undefined
from grunt-mocha-webdriver.
Okay, I get it now. Hope this will be implemented soon!
from grunt-mocha-webdriver.
@binarykitchen , version 1.0.2 has a new phantomFlags option (check here for an example).
You still have to setup a readStream in your top-level before() or something similar...
from grunt-mocha-webdriver.
@saadtazi Wonderful! Can you also add a small example on how to setup a readStream? I think this would be a very nice addition to the README.md?
from grunt-mocha-webdriver.
here is an example:
before(function() {
fs.createReadStream('phantom.log').on('data', function(chunk) {
console.log('data', chunk.toString());
});
});
I think your use case is too specific to be described in README.md.
from grunt-mocha-webdriver.
That's sweet. Thanks. Yeah, it seems to be too specific but I wasn't sure before what path and event to pick.
from grunt-mocha-webdriver.
Just checked this out. Works well but --webdriver-loglevel
won't work. Is loglevel implemented yet?
from grunt-mocha-webdriver.
And will this work with saucelabs too??
from grunt-mocha-webdriver.
What do you have in phantomFlags?
I don't think saucelabs have phantomjs.
from grunt-mocha-webdriver.
I tried
phantomStartFlags: [
'--webdriver-logfile', 'phantom.log',
'--webdriver-loglevel', 'DEBUG'
],
but wont work.
Regarding saucelabs, I mean, how can I use --webdriver-logfile
for them? When it's not phantom, what parameter should I use in grunt?
from grunt-mocha-webdriver.
On saucelabs, you will have to use the wd function log()
but you will have to explicitly call it in the after or afterEach.
from grunt-mocha-webdriver.
Ok, and what about the loglevel?
from grunt-mocha-webdriver.
what do you mean by webdriver-loglevel does not work? I just tried it with and without the --webdriver-loglevel
, and I have way more lines when loglevel is debug.
from grunt-mocha-webdriver.
It is just weird that all my tests fail when I set the loglevel to debug. When I remove the loglevel, then all my tests pass. Weird.
from grunt-mocha-webdriver.
Do you have a track trace? why do they fail?
Did you comment out the before() that contains the createReadStream() (and keep the loglevel)?
from grunt-mocha-webdriver.
There is no stack trace, no indication why they fail.
And when I keep the log level but comment out the code that contains createReadStream()
, all the tests still fail.
from grunt-mocha-webdriver.
does it fail with one test (if you add a it.only()
to one test)?
from grunt-mocha-webdriver.
it.only()? I am using TDD, not BDD here ... i.E. suite()
from grunt-mocha-webdriver.
add only
to one of the test('...')
so it becomes test.only('...')
from grunt-mocha-webdriver.
Also, the option is called phantomFlags
, not phantomStartFlags
so removing the loglevel option form phantomStartFlags
should have no impact at all.
from grunt-mocha-webdriver.
Yeah, I already fixed phantomFlags
... still do not understand test.only()
from grunt-mocha-webdriver.
Ah, when I wait long enough for the timeout to expire, then I see the error:
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object
afterConnect [as oncomplete] (net.js:895:19)
from grunt-mocha-webdriver.
http://visionmedia.github.io/mocha/#exclusive-tests
My understanding is that suite()
is describe()
and test()
is it()
.
from grunt-mocha-webdriver.
Yeah I know that. Just never seen only
before.
from grunt-mocha-webdriver.
So the mocha link I sent you will explain what only
is. which version of phantom do you have?
from grunt-mocha-webdriver.
./node_modules/.bin/phantomjs -v
from grunt-mocha-webdriver.
$ ./node_modules/.bin/phantomjs -v
1.9.7
from grunt-mocha-webdriver.
Not sure, but I think phantom webdriver does not start on your computer because of some flags... can you try the following command:
./node_modules/phantomjs/lib/phantom/bin/phantomjs --webdriver-logfile phantom.log --webdriver-loglevel DEBUG --webdriver 5555 --ignore-ssl-errors yes
On my mac, it shows a debug log message, then waits for command. I have to CTL-C to kill the process (which is ok). Do you get something else?
from grunt-mocha-webdriver.
I get the same on Linux:
$ ./node_modules/phantomjs/lib/phantom/bin/phantomjs --webdriver-logfile phantom.log --webdriver-loglevel DEBUG --webdriver 5555 --ignore-ssl-errors yes
PhantomJS is launching GhostDriver...
[DEBUG - 2014-05-06T03:00:23.023Z] Config - config.init - {"ip":"127.0.0.1","port":"5555","hub":null,"logFile":"phantom.log","logLevel":"DEBUG","logColor":false}
[INFO - 2014-05-06T03:00:23.033Z] GhostDriver - Main - running on port 5555
from grunt-mocha-webdriver.
Ok, then let's try to see what your test is executing. Can you edit ./node_modules/grunt-mocha-webdriver/tasks/grunt-mocha-wd.js
, line 106, and add a console.log there:
console.log(phantom.path, phantomOpts.join(' ')); // <--- add this line
var process = childProcess.execFile(phantom.path, phantomOpts);
and execute the ouput of the console.log
.
Remember to remove it after.
from grunt-mocha-webdriver.
Okay, here it is when isolated and executed:
$ /home/michael.heuberger/binarykitchen/code/signdna/node_modules/phantomjs/lib/phantom/bin/phantomjs --webdriver-logfile phantom.log --webdriver-loglevel DEBUG --webdriver 4444 --ignore-ssl-errors yes
PhantomJS is launching GhostDriver...
[DEBUG - 2014-05-06T03:12:03.298Z] Config - config.init - {"ip":"127.0.0.1","port":"4444","hub":null,"logFile":"phantom.log","logLevel":"DEBUG","logColor":false}
[INFO - 2014-05-06T03:12:03.308Z] GhostDriver - Main - running on port 4444
from grunt-mocha-webdriver.
It does not help... I will try to give it a try on a linux box tomorrow.
Not sure how you got your ECONNREFUSED error, but it is not a good sign...
from grunt-mocha-webdriver.
Yeah... here is more information. When I add more debugging info like this:
this.browser.on('status', function(info) {
console.log('STATUS >', info.cyan);
});
this.browser.on('command', function(meth, path, data) {
console.log('COMMAND >', meth.cyan, path.yellow, (data || '').grey);
});
this.browser.on('http', function(meth, path, data) {
console.log('HTTP >', meth.cyan, path.yellow, (data || '').grey);
});
and run through my e2e tests, I get this at the end:
...
20) Redirects to login when not authorized yet /admin/subtitle/anything:
Error: connect ECONNREFUSED
at errnoException (ne
.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
21) Home create one video and it is listed:
Error: timeout of 10000ms exceeded
at null.<anonymous> (/home/michael.heuberger/binarykitchen/code/signdna/node_modules/mocha/lib/runnable.js:139:19)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
COMMAND > CALL quit()
HTTP > DELETE /session/:sessionID
STATUS >
Ending your web drivage..
[WAITING FOREVER]
^C
The tests never exit. It waits forever and I have to abort with CTRL-C.
The timeout should exit the tests!
Yeah, please investigate ECONNREFUSED as well. Thanks heaps!
from grunt-mocha-webdriver.
Maybe in the mean time you can try to limit to one test (using .only) or even better, create one super simple test and run only that test (note that you can only have one only
in your test suite):
test.only('supersimple test', function(done) {
this.browser.get('http://www.google.com')
.nodeify(done);
})
and see if it still fails with debuglevel option.
from grunt-mocha-webdriver.
Interesting. This supersimple test works! Tell me, what is nodeify()
for? I do not call it in my tests ...
from grunt-mocha-webdriver.
https://github.com/kriskowal/q/wiki/API-Reference#promisenodeifycallback
from grunt-mocha-webdriver.
Ok, thanks @sebv, have changed to nodeify everywhere in my test code. Still have the above issues.
@saadtazi Hope you can find out more about ECONNREFUSED tomorrow with a linux box ...
from grunt-mocha-webdriver.
Ok, some updates: I have a test suite of 68 tests: it fails the same way (ECONNREFUSED) after the first test (1 passing, one failing) on my linux box.
So I tried the following:
I started phantomjs webdriver manually like this:
./node_modules/phantomjs/lib/phantom/bin/phantomjs --webdriver-logfile phantom.log --webdriver-loglevel DEBUG --webdriver 5555 --ignore-ssl-errors yes
and I changed my grunt config:
mochaWebdriver: {
dev: {
require: [ 'test/e2e/globals.js' ],
timeout: 1000 * 10,
src: test.e2e.files,
options: {
usePhantom: false,
hostname: '127.0.0.1',
port: 5555,
browsers: [{browserName: 'any'}],
phantomFlags: [
'--webdriver-logfile', 'phantom.log',
'--webdriver-loglevel', 'DEBUG'
],
reporter: 'spec',
// testName: 'Dev on phantom'
}
Then I started my tests using grunt mochaWebdriver:dev
and it works!
So ghostdriver takes some time to fully starts and accepts commands from a client when loglevel = TRUE.
Here is a workaround (I tried it it works for me):
In your toplevel before(): make sure you have a done
param, like this before(function(done) {...})
, then use a setTimeout and call done() in the setTimeout. For example I added the following:
.then(function() {setTimeout(function() { done(); }, 10000)})
You can instead a custom wd promise method sleep
or wait
.
from grunt-mocha-webdriver.
Hmmm, I see. But isn't this a bug @saadtazi? Instead of applying this workaround, I think we should patch the code. What do you reckon?
from grunt-mocha-webdriver.
Yes, this is why I called it a workaround. But I don't see any easy and good way of fixing it on grunt-mocha-webdriver side. I am actually not sure the problem is on grunt-mocha-webdriver side:
grunt-mocha-webdriver is waiting for running
in the output before starting phantom tests, which correspond to that line in the output:
[INFO - 2014-05-07T02:25:55.022Z] GhostDriver - Main - running on port 4444
This is the last log message in non-debug mode.
But when loglevel is DEBUG, ghostdriver seems to output this line before it is fully ready to accept selenium commands.
from grunt-mocha-webdriver.
So, it might be a ghostdriver bug?
from grunt-mocha-webdriver.
it might.
from grunt-mocha-webdriver.
Shall we raise this on their issue tracker?
from grunt-mocha-webdriver.
I think we need to make sure it is on their end first, and try to repro without grunt-mocha-webdriver.
from grunt-mocha-webdriver.
Okay, but since I do not have the needed expertise for this, I will leave this for now. But if you could look into this, that would be great!
from grunt-mocha-webdriver.
Some updates on this issue:
when loglevel
is set to DEBUG
, when using grunt-mocha-webdriver, it seems to crash when the visited webpage contains a lot of assets (js, images, css...). It was the case for my project (tested before minification). So I chose http://www.angelfire.com/super/badwebs/
for my tests.
Then I did the following:
In a folder that have wd (0.2.21), phantomjs (1.9.7-8) and grunt-mocha-webdriver (1.0.6) installed , I created the following grunt task:
// Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
mochaWebdriver: {
options: {
// we exclude some e2e tests by default
usePromises: true,
usePhantom: true,
phantomPort: 5555,
phantomFlags: ['--webdriver-logfile', 'phantom.log','--webdriver-loglevel', 'DEBUG','--webdriver', '5555'],
timeout: 1000 * 10,
reporter: 'mocha-teamcity-reporter'
},
dev: {
src: ['grunt-test.js'],
options: {
reporter: 'spec'
}
}
}
});
grunt.loadNpmTasks('grunt-mocha-webdriver');
};
The associated mocha test:
describe('suite', function() {
it('test', function(done) {
this.timeout(60000);
this.browser
.get('http://www.angelfire.com/super/badwebs/')
.nodeify(done);
});
});
I get a ECONNREFUSED
.
Then I created a plain nodejs file that executes a similar test, but without grunt-mocha-webdriver:
// test.js
var wd = require('wd'),
childProcess = require('child_process'),
request = require('request'),
phantomArgs = [
'--webdriver-logfile', 'phantom.log',
'--webdriver-loglevel', 'DEBUG',
'--webdriver', '4444'
];
var phantomProcess = childProcess.spawn('./node_modules/.bin/phantomjs', phantomArgs)
function runTest() {
var browser = wd.promiseChainRemote(); // default to localhost:4444
browser
.init({browserName:'phantomjs'})
.get('http://www.angelfire.com/super/badwebs/')
.then(function() {
console.log('no error');
}, function(err) { console.log('error', error); })
.fin(function() {
browser.quit();
phantomProcess.kill('SIGTERM');
})
.done();
}
// when phantom process outputs something...
phantomProcess.stdout.on('data', function(data) {
// we check if we get the log info 'GhostDriver - Main - running on port 4444'
// console.log('data', data.toString());
if (/GhostDriver - Main - running on port/.test(data)) {
// we assume we are ready to start testing
runTest();
}
});
And I don't get any error. So I am confused... and changed my mind: I don't think the problem is on ghostdriver side. But what is causing the ECONNREFUSED error? If someone has an idea or see a problem in my tests and my interpretation, please feel free to share.
from grunt-mocha-webdriver.
Related Issues (20)
- upload
- ECONNREFUSED on file upload HOT 11
- Grunt task hangs on ECONNREFUSED HOT 1
- Release patch version to npm HOT 2
- [feature] See a progress bar HOT 2
- kill() does not fire close event HOT 3
- Move Release History from README.md to History.md HOT 5
- Automatically restart Sauce Connect
- Switch out wd.js for leadfoot HOT 4
- Spawn mocha as a child process HOT 3
- How can I configure the retryDelay parameter? HOT 3
- .setWindowSize no effect on latest PhantomJS HOT 1
- selenium launcher dependency causes failures when behind a firewall that blocks git protocol HOT 1
- Use SauceLabs without Sauce Connect tunnel? HOT 4
- Mocha failures do not cause grunt build to fail
- Use mocha 2
- Custom host server Question
- Implement concept of Adapters HOT 1
- Docs - code example required
- [Question] selenium-webdriver instance instead of wd.js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-mocha-webdriver.