javascript - Can't Access Scenario Object in Hooks -
trying screenshot when of steps fails accessing scenario object , seeing if .issuccessful() true or false. doing in hooks.js file:
after(function (scenario) { var status = scenario.issuccessful(); if (!status) driver.sleep(3000); takescreenshot('./test_artifacts/img/failures/', scenario.getname(), driver); //prints browser console logs driver.manage().logs().get('browser').then(function (logs) { fs.writefile('./test_artifacts/logs/' + scenario.getname() + '.txt', stringify(logs), function (err) { if (err) return console.log(err); }); }) return driver.quit(); });
however, getting following error:
typeerror: cannot read property 'issuccessful' of undefined
any idea going on? step_definition files working fine, .feature files.
edit: here hooks.js file:
var selenium = require('selenium-webdriver'); var phantomjs = require('phantomjs'); var sleep = require('system-sleep'); var = selenium.by; var fs = require('fs'); var seleniumtimeout = 20 * 1000; var childprocess = require('child_process'); var stringify = require('node-stringify'); var key = require('../../node_modules/selenium-webdriver/lib/input'); var { definesupportcode } = require('cucumber'); require('chromedriver'); function takescreenshot(path, imgname, driver) { driver.takescreenshot().then( function (image, err) { fs.writefilesync(path + imgname + (new date).gettime().tostring() + '.png', image, 'base64'); }); }; definesupportcode(function ({ after, before, setdefaulttimeout }) { setdefaulttimeout(60 * 1000); after(function (scenario) { var status = scenario.issuccessful(); if (!status) driver.sleep(3000); takescreenshot('./test_artifacts/img/failures/', scenario.getname(), driver); //prints browser console logs driver.manage().logs().get('browser').then(function (logs) { fs.writefile('./test_artifacts/logs/' + scenario.getname() + '.txt', stringify(logs), function (err) { if (err) return console.log(err); }); }) return driver.quit(); }); before(function () { //set driver instance driver = {}; driver = new selenium.builder() .withcapabilities({ 'phantomjs.cli.args': ['--ignore-ssl-errors=true'] }) .forbrowser('phantomjs') .build(); driver.manage().timeouts().implicitlywait(10000); driver.manage().window().setsize(1674, 1407); //clear local storage before tests var localstoragepath = process.env[(process.platform == 'win32') ? 'userprofile' : 'home'] + '\\appdata\\local\\ofi labs\\phantomjs\\'; fs.readdir(localstoragepath, function (err, items) { if (items) { (var = 0; < items.length; i++) { var file = localstoragepath + '/' + items[i]; try { fs.writefilesync(file, ''); console.log('truncated file: ' + file); } catch (err) { console.log('failed truncate file: ' + file); } } } }); //log in site retrieve access token before feature driver.get("https://localhost:8000/portal/login"); sleep(4000); driver.findelement(by.css('#app > div > div > div.col-xs-6.textcolumn > button')).click(); sleep(4000); takescreenshot('./test_artifacts/img/', 'load success', driver); driver.findelement(by.css('#auth0-lock-container-1 > div > div.auth0-lock-center > form > div > div > div:nth-child(3) > span > div > div > div > div > div > div > div > div > div > div.auth0-lock-social-buttons-container > button > div.auth0-lock-social-button-text')).click(); takescreenshot('./test_artifacts/img/', 'load success', driver); sleep(3000); var input1 = driver.findelement(by.css('#userid')); var input2 = driver.findelement(by.css('#password')); input1.sendkeys('utenza_reseller'); input2.sendkeys('reseller2015'); takescreenshot('./test_artifacts/img/', 'load success', driver); driver.findelement(by.css('#dologinoauth')).click(); takescreenshot('./test_artifacts/img/', 'load success', driver); }); });
thanks user chuan qin on cucumber-js gitter following answer:
reverted v 3.0.0 v 2.0.0 of cucumber. issuccessful still doesn't work isfailed work. seem have access scenario object now, while undefined in 3.0.0
Comments
Post a Comment