How to use saveViewportIndexes method in backstopjs

Best JavaScript code snippet using backstopjs

createBitmaps.js

Source:createBitmaps.js Github

copy

Full Screen

1var cloneDeep = require('lodash/cloneDeep');2var fs = require('./fs');3var each = require('./each');4var pMap = require('p-map');5var runPuppet = require('./runPuppet');6const ensureDirectoryPath = require('./ensureDirectoryPath');7var logger = require('./logger')('createBitmaps');8var CONCURRENCY_DEFAULT = 10;9function regexTest (string, search) {10 var re = new RegExp(search);11 return re.test(string);12}13function ensureViewportLabel (config) {14 if (typeof config.viewports === 'object') {15 config.viewports.forEach(function (viewport) {16 if (!viewport.label) {17 viewport.label = viewport.name;18 }19 });20 }21}22function decorateConfigForCapture (config, isReference) {23 var configJSON;24 if (typeof config.args.config === 'object') {25 configJSON = config.args.config;26 } else {27 configJSON = Object.assign({}, require(config.backstopConfigFileName));28 }29 configJSON.scenarios = configJSON.scenarios || [];30 ensureViewportLabel(configJSON);31 var totalScenarioCount = configJSON.scenarios.length;32 function pad (number) {33 var r = String(number);34 if (r.length === 1) {35 r = '0' + r;36 }37 return r;38 }39 var screenshotNow = new Date();40 var screenshotDateTime = screenshotNow.getFullYear() + pad(screenshotNow.getMonth() + 1) + pad(screenshotNow.getDate()) + '-' + pad(screenshotNow.getHours()) + pad(screenshotNow.getMinutes()) + pad(screenshotNow.getSeconds());41 screenshotDateTime = configJSON.dynamicTestId ? configJSON.dynamicTestId : screenshotDateTime;42 configJSON.screenshotDateTime = screenshotDateTime;43 config.screenshotDateTime = screenshotDateTime;44 if (configJSON.dynamicTestId) {45 console.log(`dynamicTestId '${configJSON.dynamicTestId}' found. BackstopJS will run in dynamic-test mode.`);46 }47 configJSON.env = cloneDeep(config);48 configJSON.isReference = isReference;49 configJSON.paths.tempCompareConfigFileName = config.tempCompareConfigFileName;50 configJSON.defaultMisMatchThreshold = config.defaultMisMatchThreshold;51 configJSON.backstopConfigFileName = config.backstopConfigFileName;52 configJSON.defaultRequireSameDimensions = config.defaultRequireSameDimensions;53 if (config.args.filter) {54 var scenarios = [];55 config.args.filter.split(',').forEach(function (filteredTest) {56 each(configJSON.scenarios, function (scenario) {57 if (regexTest(scenario.label, filteredTest)) {58 scenarios.push(scenario);59 }60 });61 });62 configJSON.scenarios = scenarios;63 }64 logger.log('Selected ' + configJSON.scenarios.length + ' of ' + totalScenarioCount + ' scenarios.');65 return configJSON;66}67function saveViewportIndexes (viewport, index) {68 return Object.assign({}, viewport, { vIndex: index });69}70function delegateScenarios (config) {71 var scenarios = [];72 var scenarioViews = [];73 config.viewports = config.viewports.map(saveViewportIndexes);74 // casper.each(scenarios, function (casper, scenario, i) {75 config.scenarios.forEach(function (scenario, i) {76 // var scenarioLabelSafe = makeSafe(scenario.label);77 scenario.sIndex = i;78 scenario.selectors = scenario.selectors || [];79 if (scenario.viewports) {80 scenario.viewports = scenario.viewports.map(saveViewportIndexes);81 }82 scenarios.push(scenario);83 if (!config.isReference && scenario.hasOwnProperty('variants')) {84 scenario.variants.forEach(function (variant) {85 // var variantLabelSafe = makeSafe(variant.label);86 variant._parent = scenario;87 scenarios.push(scenario);88 });89 }90 });91 var scenarioViewId = 0;92 scenarios.forEach(function (scenario) {93 var desiredViewportsForScenario = config.viewports;94 if (scenario.viewports && scenario.viewports.length > 0) {95 desiredViewportsForScenario = scenario.viewports;96 }97 desiredViewportsForScenario.forEach(function (viewport) {98 scenarioViews.push({99 scenario: scenario,100 viewport: viewport,101 config: config,102 id: scenarioViewId++103 });104 });105 });106 const asyncCaptureLimit = config.asyncCaptureLimit === 0 ? 1 : config.asyncCaptureLimit || CONCURRENCY_DEFAULT;107 if (config.engine.startsWith('puppet')) {108 return pMap(scenarioViews, runPuppet, { concurrency: asyncCaptureLimit });109 } else if (/chrom./i.test(config.engine)) {110 logger.error(`Chromy is no longer supported in version 5+. Please use version 4.x.x for chromy support.`);111 } else {112 logger.error(`Engine "${(typeof config.engine === 'string' && config.engine) || 'undefined'}" not recognized! If you require PhantomJS or Slimer support please use backstopjs@3.8.8 or earlier.`);113 }114}115function writeCompareConfigFile (comparePairsFileName, compareConfig) {116 var compareConfigJSON = JSON.stringify(compareConfig, null, 2);117 ensureDirectoryPath(comparePairsFileName);118 return fs.writeFile(comparePairsFileName, compareConfigJSON);119}120function flatMapTestPairs (rawTestPairs) {121 return rawTestPairs.reduce((acc, result) => {122 var testPairs = result.testPairs;123 if (!testPairs) {124 testPairs = {125 diff: {126 isSameDimensions: '',127 dimensionDifference: {128 width: '',129 height: ''130 },131 misMatchPercentage: ''132 },133 reference: '',134 test: '',135 selector: '',136 fileName: '',137 label: '',138 scenario: result.scenario,139 viewport: result.viewport,140 msg: result.msg,141 error: result.originalError && result.originalError.name142 };143 }144 return acc.concat(testPairs);145 }, []);146}147module.exports = function (config, isReference) {148 const promise = delegateScenarios(decorateConfigForCapture(config, isReference))149 .then(rawTestPairs => {150 const result = {151 compareConfig: {152 testPairs: flatMapTestPairs(rawTestPairs)153 }154 };155 return writeCompareConfigFile(config.tempCompareConfigFileName, result);156 });157 return promise;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = async function (page, scenario, vp) {2 console.log('SCENARIO > ' + scenario.label);3 await require('./loadCookies')(page, scenario);4 await page.evaluate(_ => {5 window.saveViewportIndexes();6 });7 await page.waitFor(500);8};

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstop = require('backstopjs');2backstop('saveViewportIndexes', {config: './backstop.json'}).then(function (data) {3 console.log('data', data);4}).catch(function (err) {5 console.log(err);6});7{8 {9 },10 {11 },12 {13 }14 {15 }16 "paths": {17 },18 "engineOptions": {19 },20}21data { scenarios: [], viewports: [] }22{ [Error: ENOENT: no such file or directory, open 'backstop_data/bitmaps_test/20160317-153754/failed_diff_backstop_default_BackstopJS_Homepage_0_phone.png']

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2var fs = require('fs');3var path = require('path');4var config = require('./backstop.json');5var viewport = require('./config/viewport.json');6var scenario = require('./config/scenario.json');7var scenarios = [];8var viewports = [];9var viewports = viewport.viewports;10var scenarios = scenario.scenarios;11var timestamp = new Date().getTime();12var reportPath = path.resolve(__dirname, 'reports');13var reportConfigPath = path.resolve(reportPath, timestamp.toString());14var reportConfigPath = path.resolve(reportPath, timestamp.toString());15var reportConfigFile = path.resolve(reportConfigPath, 'config.json');16var reportConfig = {17};18var mkdirSync = function (path) {19 try {20 fs.mkdirSync(path);21 } catch (e) {22 if (e.code !== 'EEXIST') throw e;23 }24}25mkdirSync(reportPath);26mkdirSync(reportConfigPath);27fs.writeFileSync(reportConfigFile, JSON.stringify(reportConfig, null, 2));28var report = backstopjs('reference', {29});30report.then(function (result) {31 if (result.failures.length > 0) {32 console.log('Test Failed');33 } else {34 console.log('Test Passed');35 }36});37{38 {39 },40 {41 },42 {43 },44 {45 }46}47{48 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var viewportIndexes = require('./viewportIndexes.json');3var viewportIndexes = {4 "test1": {5 },6 "test2": {7 }8};9var viewportIndexes = JSON.stringify(viewportIndexes, null, 4);10fs.writeFile('viewportIndexes.json', viewportIndexes, function(err) {11 if (err) {12 return console.log(err);13 }14 console.log("The file was saved!");15});16{17 "test1": {18 },19 "test2": {20 }21}22{23 {24 },25 {26 },27 {28 },29 {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run backstopjs automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful