Karate UI: How to initialize a new driver in JS

Viewed 10

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()
0 Answers
Related