Created
October 24, 2019 13:46
-
-
Save seleniumgists/61e0478cc68a50119e835c4857e2b33a to your computer and use it in GitHub Desktop.
generated automatically from #selenium on seleniumhq slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
world.js | |
require('chromedriver') | |
const { setWorldConstructor } = require('cucumber') | |
const webDriver = require('selenium-webdriver') | |
const chrome = require('selenium-webdriver/chrome') | |
const chromiumBinary = require('chromium-binary') | |
var { Before, BeforeAll, AfterAll, After } = require('cucumber') | |
let driver | |
// Letter size: '--window-size=1280, 1696' | |
// '--window-size=1920, 1080' | |
const screen = { | |
width: 1280, | |
height: 1024 | |
} | |
const defaultChromeFlags = [ | |
'--start-maximized', | |
'--disable-gpu', | |
'--no-sandbox', | |
'--no-zygote', | |
'--headless' | |
] | |
function CustomWorld(driver, attach) { | |
this.attach = attach | |
this.driver = driver | |
} | |
BeforeAll(async function() { | |
driver = new webDriver.Builder() | |
.forBrowser('chrome') | |
.setChromeOptions( | |
new chrome.Options() | |
.setChromeBinaryPath(chromiumBinary.path) | |
.windowSize(screen) | |
.addArguments(defaultChromeFlags) | |
) | |
.build() | |
setWorldConstructor(CustomWorld.bind(undefined, driver)) | |
}) | |
Before(function(driver) { | |
console.log('') | |
console.log('STARTING SCENARIO: ' + driver.pickle.name) | |
}) | |
After(function(scenario) { | |
if (scenario.result.status === 'failed') { | |
const world = this | |
return this.driver.takeScreenshot().then(async function(screenshot) { | |
await world.attach.attach(screenshot, 'image/png') | |
await driver.close() | |
await driver.quit() | |
driver = new webDriver.Builder() | |
.forBrowser('chrome') | |
.setChromeOptions( | |
new chrome.Options() | |
.setChromeBinaryPath(chromiumBinary.path) | |
.windowSize(screen) | |
.addArguments(defaultChromeFlags) | |
) | |
.build() | |
setWorldConstructor(CustomWorld.bind(undefined, driver)) | |
}) | |
} | |
}) | |
AfterAll(function() { | |
try { | |
driver.close() | |
driver.quit() | |
} catch (error) { | |
console.log('ERROR TRYING TO Quit' + error) | |
} | |
}) | |
Beginning of stepDefs.js | |
const { Given, When, Then, setDefaultTimeout } = require('cucumber') | |
const { until, By, Key } = require('selenium-webdriver') | |
const selector = require('../support/connex-selectors') | |
const { readFile, utils } = require('xlsx') | |
const stepsWebdriver = require('selenium-webdriver') | |
setDefaultTimeout(60 * 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment