1

I'd like to configure / initialize the driver in a JS function but I'm not sure how to create the driver instance. I'm thinking it might be something like this but I haven't been able to find the right syntax:

karate-config.js:

fn() {
  return {
    setupDriver: function (browserName, isEmulated, url) {
      karate.configure('driver', {
        type:       'chrome',
        executable: 'chrome'
      })

      driver = new Driver(url)

      if (isEmulated) {
        const browser = browsers[browserName]
        driver.emulateDevice(browser.width, browser.height, browser.useragent)
      }
    },
  }
}

example.feature

Given setupDriver('iPhone', true, 'https://www.google.com/')
Then screenshot()
jckdnk111
  • 2,280
  • 5
  • 33
  • 43
  • 1
    karate is opinionated about when the driver is initiated, it is always within a feature file - and there is a life-cycle to close it as well. the linked answer is the best reference on how to structure your tests if you want re-use and some conditional logic, it is all possible without actually "starting" the driver from JS. if this still doesn't suffice, maybe you should just stick to Java code: https://twitter.com/getkarate/status/1353969718730788865 – Peter Thomas Feb 26 '22 at 06:01

0 Answers0