it.only is broken in mocha
Attempting to use it.only in mocha throws an exception, because it.only in mocha attempts to use the literal return value of 'it', which protractor has wrapped in a promise.
Just noticed, mocha expects that it.only will return an instance of a test, but it.only is exported from selenium-webdriver package and it actually returns nothing (it is a wrapped function).
It's a bit more complicated than that - the way that WebDriverJS wraps the commands doesn't work properly with it.only, because when Protractor copies adapter.it.only onto the global it ends up getting wrapped twice. Internally, mocha's context.it.only calls context.it. Mocha sets context to be the global.
I have a hacky solution to think but I want to think about it for a bit longer to make sure there's not a cleaner way to do it.
Fixed with 1137d12b95435438d2b84448796f9fe32d2f87b2
I'm still having trouble with this.
Here is my test:
chai = require('chai')
chaiAsPromised = require('chai-as-promised')
loginPage = require('./pages/login')
chai.use(chaiAsPromised)
expect = chai.expect
describe 'auth', ->
beforeEach ->
protractor.getInstance().manage().deleteAllCookies()
it.only 'should redirect unauthorized users to login page', ->
browser.get('/')
expect(browser.getCurrentUrl()).to.eventually.contain('/login')
I get the following error:
TypeError: Cannot call method 'fullTitle' of undefined
screenshot:

All of my tests run fine when I don't use 'only'. I just updated to protractor v0.22.0, and I've updated selenium using webdriver-manager update.
Hi @lynndylanhurley the fix is in master but hasn't gone out to a release yet. It'll be in 0.23.0.
Oh cool, thx @juliemr. I'll just use master for now.
Still seeing this issue both on master and 0.23.x... Output below:
Starting selenium standalone server... [launcher] Running 1 instances of WebDriverSelenium standalone server started at http://192.168.1.20:55480/wd/hub [launcher] chrome passed
Fatal error: protractor exited with code: 1
Hey @smdahlen are there any more logs? What makes you believe this is an issue with it.only? The ones you've posted don't really say much.
I agree, the logs are not much to go on. I know it occurs by simply attempting to use it.only. I have tried using it on numerous tests and they all fail with the log posted. I'm going to investigate more in the next day or two but I wanted to bring it to the projects attention to see if the contributors were aware of anything.
On May 23, 2014, at 6:36 PM, Julie Ralph [email protected] wrote:
Hey @smdahlen are there any more logs? What makes you believe this is an issue with it.only? The ones you've posted don't really say much.
— Reply to this email directly or view it on GitHub.
This is definitely still an issue, and should be reproducible just by trying it in its simplest form.
The bug appears to be in webdriver. Mocha is expecting context.it (context === global) to return a test object. However, the wrapper function in webdriver looks like this:
return function() {
switch (arguments.length) {
case 1:
globalFn(asyncTestFn(arguments[0]));
break;
case 2:
globalFn(arguments[0], asyncTestFn(arguments[1]));
break;
default:
throw Error('Invalid # arguments: ' + arguments.length);
}
};
Which does not return anything. Patching case 1 and case 2 to return the result of globalFn fixes the issue. However, I can't think of a very nice way of fixing this in protractor.
I have the issue still IF I try to use it.only.
excerpt from my package.json:
"protractor": "^1.0.0-rc1",
"grunt-protractor-runner": "^1.0.0",
"mocha": "~1.20.1",
Stack trace:
↪ grunt test:e2e
Running "protractor:e2e" (protractor) task
Using ChromeDriver directly...
/Users/onetom/some/project/node_modules/mocha/lib/interfaces/bdd.js:124
var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$';
^
TypeError: Cannot call method 'fullTitle' of undefined
at Function.context.it.only (/Users/onetom/some/project/node_modules/mocha/lib/interfaces/bdd.js:124:52)
at Suite.<anonymous> (/Users/onetom/some/project/client/scripts/notifications/notification-list.spec.coffee:16:8)
at context.describe.context.context (/Users/onetom/some/project/node_modules/mocha/lib/interfaces/bdd.js:74:10)
at Object.<anonymous> (/Users/onetom/some/project/client/scripts/notifications/notification-list.spec.coffee:12:3)
at Object.<anonymous> (/Users/onetom/some/project/client/scripts/notifications/notification-list.spec.coffee:34:4)
at Module._compile (module.js:456:26)
at Object.loadFile (/Users/onetom/some/project/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
at Module.load (/Users/onetom/some/project/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/onetom/some/project/node_modules/mocha/lib/mocha.js:172:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/onetom/some/project/node_modules/mocha/lib/mocha.js:169:14)
at Mocha.run (/Users/onetom/some/project/node_modules/mocha/lib/mocha.js:356:31)
at /Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/lib/frameworks/mocha.js:50:11
at /Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1243:15
at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1531:20)
at notify (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:354:12)
at notifyAll (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:323:7)
at resolve (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:301:7)
at fulfill (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:421:5)
at /Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1398:10
at Object.webdriver.promise.asap (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:663:5)
at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1542:25)
at webdriver.promise.ControlFlow.runEventLoop_ (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1396:8)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
run test preparers
at Object.exports.run (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/lib/frameworks/mocha.js:42:24)
at driverprovider_.setupEnv.then.then.then.testResult (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/lib/runner.js:233:28)
at _fulfilled (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:759:13)
at /Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:525:49
at flush (/Users/onetom/some/project/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3
>>
Fatal error: protractor exited with code: 1
Execution Time (2014-06-30 05:17:37 UTC)
protractor:e2e 1.8s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100%
Total 1.8s
@onetom This is actually an issue with the way webdriver wraps its functions. I've filed an issue/pull-request with them here: https://code.google.com/p/selenium/issues/detail?id=7519
In the meantime, if you apply the patch in that issue (or as explained in my previous post), it should work just fine.
I have the same problem. TypeError: Cannot call method 'fullTitle' of undefined protractor --version : Version 1.0.0-rc5
@Efimster don't forget to update protractor frequently. I've just noticed yesterday that v1.0.0 has been released recently. (might not solve the problem, but better to report against the latest stable code)
The same stuff with protractor --version : Version 1.0.0
Still an issue with version 1.1.1 but now I get no error or any output when I have it.only():
$ protractor protractor/chrome-native-config.js
Using ChromeDriver directly...
$
When I take out the it.only(), the tests run fine
Confirming same as @ryanzec issue in v 1.2.0 as well--no error or any output written when I use it.only(). Perhaps this issue can be reopened?