0

I started creating a base test case using Mocha and Selenium Webriver. I get the following error when I try and run

> mocha test

TypeError: describe is not a function
at Object.<anonymous> (/Users/<username>/projects/selenium-testing/test/website_test.js:6:5)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /usr/local/lib/node_modules/mocha/lib/mocha.js:253:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:250:14)

My code sample:

var webdriver = require('selenium-webdriver'),
{describe, before, after, it} = require('selenium-webdriver/testing');
By = webdriver.by,
until = webdriver.until;

describe('scenarios', function(){
  beforeEach(function(){
    var driver = new webdriver.Builder().forBrowser('chrome').build();
    driver.get('http://google.com');
  });

  afterEach(function(){
    driver.quit();
  });

  it('find google', function(){

  });

});

I am not sure how to take care of this error since I tried all 1) globally and locally installing selenium-webdriver

1
  • 1
    Have you installed mocha? Commented May 20, 2018 at 9:46

3 Answers 3

2
   var Page = require ('../lib/home_page.js');
   var webdriver = require('selenium-webdriver');
  { describe , before , after , it }  require('selenium-webdriver/testing');

    var page;
   describe('library app scenarious', function() {
      beforeEach(function(){
          page = new Page();
          page.CheckOut();
      });

      afterEach(function(){
          page.quit();
      });

      it('Test1',function(){
        console.log('1testpass');
      });

      it('Test2',function(){
        console.log('2testpass');
      })
    });
1
  • Yep!!!! I finaly fix this . Just try to init comands (dscribe,before,after,it) in this way(without euqals). I missunderstood how does it work, but it helps me Commented May 20, 2018 at 14:11
0

I suppose it is not an issue with Selenium webdriver, it is a part of mocha that might be causing error. please look at it and that should solve

1
  • 3
    More explanation on why you think this might be the issue might make this a useful answer. This would fit better as a comment, TBH. Have a look here: how to answer
    – Ray Oei
    Commented May 20, 2018 at 11:15
0

You need to install mocha globally.

$ npm install --global mocha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.