Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Quality Assurance Intermediate Selenium WebDriver Use Selenium with Testing Frameworks Selenium and Mocha

Amber Harlow
seal-mask
.a{fill-rule:evenodd;}techdegree
Amber Harlow
Java Web Development Techdegree Student 11,542 Points

TypeError: suite is not a function

I am getting the following error when trying to run my test. I even copied and pasted the snippet provided in the Teacher's Notes. Any ideas?

TypeError: suite is not a function
    at Object.<anonymous> (/Users/Amber/PROJECT/test/invitees.js:12:1)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at /usr/local/lib/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:576:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:637:18)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Jay McGavren
Jay McGavren
Treehouse Teacher

This is the snippet you saved to test/invitees.js, correct?

const {Browser, By, Key, until} = require("selenium-webdriver");
const {suite} = require("selenium-webdriver/testing");
const assert = require('assert');

suite(function(env) {
    describe('RSVP site', function() {
        it('has invitee list', function() {
            assert(1 === 2);
        });
    });
});

When I type node by itself in a terminal to launch the Node REPL, then type require("selenium-webdriver/testing");, I get this output:

$ node
> require("selenium-webdriver/testing");
{ Environment: [Function: Environment],
  TargetBrowser: [Function: TargetBrowser],
  SuiteOptions: [Function: SuiteOptions],
  init: [Function: init],
  ignore: [Function: ignore],
  suite: [Function: suite] }

...What do you get?

Steven Sullivan
Steven Sullivan
11,616 Points

Jay McGavren, I am facing a similar problem as well. My output from the Node REPL with require ("selenium-webdriver/testing"); results in the following:

> require("selenium-webdriver/testing");
{ controlFlow: [Function],
  describe: { [Function] only: [Function], skip: [Function] },
  xdescribe: [Function],
  after: [Function],
  afterEach: [Function],
  before: [Function],
  beforeEach: [Function],
  it: { [Function] only: [Function], skip: [Function] },
  xit: [Function],
  ignore: [Function: ignore] }

2 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Steve Sullivan My apologies for not replying earlier; I didn't get a notification that this forum thread had been updated.

I suspect that you (and also Amber Harlow ) have an older version of selenium-webdriver installed than that used in the videos, and that's why it's not working. To test this, you'll need to run two separate commands: npm list selenium-webdriver (to see which version is installed in your project directory) and npm list -g selenium-webdriver (to see which version, if any, is installed globally).

Here's the output I got.

$ npm list selenium-webdriver
/Users/jay/th/selenium/project
└── selenium-webdriver@4.0.0-alpha.1

$ npm list -g selenium-webdriver
/usr/local/lib
└── selenium-webdriver@3.6.0

It is okay if npm list -g selenium-webdriver doesn't return anything. But npm list selenium-webdriver needs to show selenium-webdriver@4.0.0-alpha.1 (or later). If it shows selenium-webdriver@3.6.0, then you'll need to do an npm install selenium-webdriver within your project directory to install the latest version, or the instructions in the videos for this course won't work correctly.

Ali Kholafaei
Ali Kholafaei
911 Points

Thanks Jay, I had the same issue and it got fixed after updating my selenium-webdriver version from 3.6 to 4.