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
   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');
      })
    });
  • 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 – Dmytro Lukashenko May 20 '18 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

  • 2
    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 May 20 '18 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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