* Initializes this module by determining which browsers a * plain ./index.suite test suite should run against. The default * behavior is to run tests against every browser with a WebDriver executables * (chromedriver, firefoxdriver, etc.) are installed on the system by `PATH`. * * Specif
(force = false)
| 204 | * against. |
| 205 | */ |
| 206 | function init(force = false) { |
| 207 | if (wasInit && !force) { |
| 208 | return |
| 209 | } |
| 210 | wasInit = true |
| 211 | |
| 212 | // If force re-init, kill the current server if there is one. |
| 213 | if (seleniumServer) { |
| 214 | seleniumServer.kill() |
| 215 | seleniumServer = null |
| 216 | } |
| 217 | |
| 218 | seleniumJar = process.env['SELENIUM_SERVER_JAR'] |
| 219 | seleniumUrl = process.env['SELENIUM_REMOTE_URL'] |
| 220 | if (seleniumJar) { |
| 221 | info(`Using Selenium server jar: ${seleniumJar}`) |
| 222 | } |
| 223 | |
| 224 | if (seleniumUrl) { |
| 225 | info(`Using Selenium remote end: ${seleniumUrl}`) |
| 226 | } |
| 227 | |
| 228 | if (seleniumJar && seleniumUrl) { |
| 229 | throw Error( |
| 230 | 'Ambiguous test configuration: both SELENIUM_REMOTE_URL' + |
| 231 | ' && SELENIUM_SERVER_JAR environment variables are set', |
| 232 | ) |
| 233 | } |
| 234 | |
| 235 | const envBrowsers = getBrowsersToTestFromEnv() |
| 236 | if ((seleniumJar || seleniumUrl) && envBrowsers.length === 0) { |
| 237 | throw Error( |
| 238 | 'Ambiguous test configuration: when either the SELENIUM_REMOTE_URL or' + |
| 239 | ' SELENIUM_SERVER_JAR environment variable is set, the' + |
| 240 | ' SELENIUM_BROWSER variable must also be set.', |
| 241 | ) |
| 242 | } |
| 243 | |
| 244 | targetBrowsers = envBrowsers.length > 0 ? envBrowsers : getAvailableBrowsers() |
| 245 | info(`Running tests against [${targetBrowsers.map((b) => b.name).join(', ')}]`) |
| 246 | |
| 247 | after(function () { |
| 248 | if (seleniumServer) { |
| 249 | return seleniumServer.kill() |
| 250 | } |
| 251 | }) |
| 252 | } |
| 253 | |
| 254 | const TARGET_MAP = /** !WeakMap<!Environment, !TargetBrowser> */ new WeakMap() |
| 255 | const URL_MAP = /** !WeakMap<!Environment, ?(string|remote.SeleniumServer)> */ new WeakMap() |
no test coverage detected