0

I'm a beginner. Can any one guide me?

Tests.js

describe("Test the calculator",()=>{

    it("Addition functionality",function test(){
        driver.browser.get("https://juliemr.github.io/protractor-demo/");
        browser.manage().window().maximize();
        //browser.manage().timeouts().implicitlyWait(3000)

    })
})

Config.js

const driver= require("protractor")

exports.config= {
    browserName: 'chrome',
    framework: "mocha",
    directconnect: true,
    specs: ['./tests.js'],
    mochaOpts: {
        timeout: 0
    }
}

At run time it display a message as "driver is not defined"

Chrome version: 83.0.4103.61 (Official Build) (64-bit) Visual Studio code: 1.45.1

Nico Griffioen
  • 5,143
  • 2
  • 27
  • 36

1 Answers1

1

I see what's going on...

first of all, don't call protractor a driver. Don't confuse others and most importantly yourself. Protractor is protractor, period.

second, when you do const driver= require("protractor") your driver variable is available in conf.js, but when you call it from the spec, it's not there, because it's a local variable, not global. As simple as that, this is why you get this error

Third, you don't need to define protractor because it is a global variable, and is available anywhere in your project anyways. The same with browser, element, $, $$ they all are available globally in your project.

Fourth, lets assume for whatever GOOD reason you still want to define something that will be globally available just do global.driver = require('protractor') as described here https://stackoverflow.com/a/31208642/9150146, and then you can call by typing the variable name driver

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40