2

My question is basically the same as this one. But I am writing my tests in JavaScript. I want to have several step definition files. I tried creating a file with exported driver like this

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();

module.exports = driver;

I am importing this file in my step definition files with const { driver } = require('test-driver') When I run the tests there are two browser windows opened insted of one.

What is the right way of sharing the same WebDriver between several step definition files?

sininen
  • 503
  • 1
  • 6
  • 20

1 Answers1

0

I would recommend using protractor(a wrapper for selenium) instead of webdriver directly as protractor has some neat built-in support for Javascript. Take a look here https://github.com/protractor-cucumber-framework/protractor-cucumber-framework

Then you can just import browser and use the driver across steps

Ray
  • 1,134
  • 10
  • 27