Best JavaScript code snippet using backstopjs
gcjcv_keyword.js
Source:gcjcv_keyword.js
1/*2Javascript do projeto responsavel por atividades no Keyword3Julio Vitorino, 12/09/20184*/5function getserp(pid){6 var req1 = $.ajax({7 url: '../php/classes/gateway/listProjetoSERPController.php',8 method: "POST",9 data: {10 projetoid: pid11 },12 success: getSERPCallback13 });14 var req2 = $.ajax({15 url: '../php/classes/gateway/listProjetoSERPAnaliticoController.php',16 method: "POST",17 data: {18 projetoid: pid19 },20 success: popularSERPAnaliticoCallback21 });22}23var getSERPCallback = function(retorno, status){24 // Transforma em objeto javascript e obtem lista de projetos25 var lst = JSON.parse(retorno);26 if (lst.length > 0) { 27 // grafico ranking, DA e PA28 var barChartDataRanking = dadosGraficoBarra(lst);29 }30 // grafico ranking31 seostudioChartBar(barChartDataRanking, "chartjs_bar", "Tendência");32}33function dadosGraficoBarra(lst) {34 var labelMesesX = [];35 var dadosBarRanking = [];36 var dadosBarPA = [];37 var dadosBarDA = [];38 for (var i = 0; i < lst.length; i++) {39 var serp = lst[i]; // GraficoProjetoSERPDTO40 labelMesesX.push(serp.mesano);41 dadosBarDA.push(parseInt(serp.sumDA,10));42 dadosBarPA.push(parseInt(serp.sumPA,10));43 dadosBarRanking.push(parseInt(serp.sumranking,10));44 }45 var color = Chart.helpers.color;46 var datasetRanking = {47 label: 'Ranking',48 backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),49 borderColor: window.chartColors.blue,50 borderWidth: 1,51 data: dadosBarRanking52 }53 var datasetPA = {54 label: 'Page Authority',55 backgroundColor: color(window.chartColors.green).alpha(0.5).rgbString(),56 borderColor: window.chartColors.green,57 borderWidth: 1,58 data: dadosBarPA59 }60 var datasetDA = {61 label: 'Domain Authority',62 backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),63 borderColor: window.chartColors.red,64 borderWidth: 1,65 data: dadosBarDA66 }67 var retorno = {68 labels: labelMesesX,69 datasets: [datasetRanking, datasetPA, datasetDA]70 };71 return retorno;72}73function seostudioChartBar(dados, canvasid, titulo){74 var color = Chart.helpers.color;75 var barChartData = dados;76 // simula um reset no canvas77 $('#' + canvasid).remove();78 $('#graph-container').append('<canvas id="'+canvasid+'"><canvas>');79 var ctx = document.getElementById(canvasid).getContext("2d");80 window.myBar = new Chart(ctx, {81 type: 'bar',82 data: barChartData,83 options: {84 responsive: true,85 legend: {86 position: 'top',87 },88 title: {89 display: true,90 text: titulo91 }92 }93 });94}95function popularProjetosSERP(){96 var request = $.ajax({97 url: '../php/classes/gateway/loadtableController.php',98 success: popularProjetosSERPCallback99 });100}101var popularProjetosSERPCallback = function(retorno, status){102 //alert(retorno);103 // Transforma em objeto javascript e obtem lista de projetos104 var dto = JSON.parse(retorno);105 var lst = dto.lst_projetos;106 var t = $('#support_table_serp_projetos').DataTable( {107 "scrollX": true108 } );109 if (lst.length > 0) { 110 for (var i = 0; i < lst.length; i++) {111 // string html dos botões112 var pid = lst[i].id;113 var acoes = '<td class="valigntop">' +114 ' <a href="profile_projeto.html?p='+pid+' " class="btn btn-info btn-xs">' +115 ' <i class="fa fa-eye "></i>'+116 ' </a>'+117 ' <a href="index.php?target=edit_projeto<=true&o=projetos&mode=edit&pid='+pid+' " class="btn btn-primary btn-xs">' +118 ' <i class="fa fa-pencil"></i>' +119 ' </a>' +120 ' <a href="javascript:getserp('+pid+'); " class="btn btn-info btn-xs">' +121 ' <i class="fa fa-bar-chart "></i>'+122 ' </a>'+123 '</td>';124 // string html do status125 var status = lst[i].status;126 var label = "label-info";127 var span = "Informação";128 if (status === "A") {129 label = "label-success";130 span = "Ativo";131 } else if (status === "I"){132 label = "label-danger";133 span = "Inativo";134 } else if (status === "B"){135 label = "label-danger";136 span = "Bloqueado";137 } else if (status === "P"){138 label = "label-warning";139 span = "Pendente";140 }141 var statushtml = '<span class="label label-sm '+ label +'"> '+span+' </span>';142 // Adiciona projeto na tabela143 t.row.add( [144 lst[i].projeto,145 lst[i].palavra_chave_exata,146 lst[i].nicho,147 statushtml,148 acoes149 ] ).draw( false );150 }151 }152} // fim function carregarTabelaProjetos153var popularSERPAnaliticoCallback = function (retorno, status) {154 //alert(retorno);155 156 // Apagar as linhas da TBody157 $('#table_serp_projetos_analitico > tbody').empty();158 // faz um parse no retorno159 var lst = JSON.parse(retorno);160 for (var i = 0; i < lst.length; i++) {161 var kwd = lst[i];162 163 $('#table_serp_projetos_analitico > tbody').append('<tr>'164 + '<td>'+ kwd.link +'</td>'165 + '<td>'+kwd.posicaoDA+'</td>'166 + '<td>'+kwd.posicaoPA+'</td>'167 + '<td>'+kwd.ranking+'</td>');168 }169}170function popularListaKeyword(){171 var request = $.ajax({172 url: '../php/classes/gateway/listKeywordController.php',173 method: "POST",174 success: popularListaKeywordSolicitadasClickCallback175 });176}177var popularListaKeywordSolicitadasClick = function() {178 popularListaKeyword();179}180var popularListaKeywordSolicitadasClickCallback = function (retorno, status) {181 // Apagar as linhas da TBody182 $('#support_table > tbody').empty();183 // faz um parse no retorno184 var lst = JSON.parse(retorno);185 for (var i = 0; i < lst.length; i++) {186 var kwd = lst[i];187 188 var diff = parseInt(kwd.niveldificuldade,10);189 var diffcss = "danger";190 var difftxt = "Muito DifÃcil";191 if (diff <= 20){192 difftxt = "Muito Fácil";193 diffcss = "success";194 } else if (diff <= 40) {195 difftxt = "Fácil";196 diffcss = "warning";197 } else if (status <= 60) {198 difftxt = "DifÃcil";199 diffcss = "warning";200 }201 var status = kwd.status;202 var statuscss = "info";203 var statustxt = "Processado";204 if (status === 'Q'){205 statustxt = "Na fila";206 statuscss = "warning";207 difftxt = "Na Fila";208 diffcss = statuscss;209 } else if (status === 'B') {210 statustxt = "Plano Excedido";211 statuscss = "danger";212 } else if (status === 'W') {213 statustxt = "Processando agora";214 statuscss = "sucess";215 }216 $('#support_table > tbody').append('<tr>'217 + '<td>'+ kwd.keyword +'</td>'218 + '<td>'+kwd.volumepesquisa+'</td>'219 + '<td>'+kwd.valorcpc+'</td>'220 + '<td>'+kwd.niveldificuldade+'</td>'221 + '<td>'222 + ' <span class="label label-sm label-'+diffcss+'">'+difftxt+'</span>'223 + '</td>'224 + '<td>'225 + ' <span class="label label-sm label-'+statuscss+'">'+statustxt+'</span>'226 + '</td>'227 + '<td>'+kwd.dataAtualizacao+'</td>'228 + '<td><a href="javascript:popularRelacionadas('+kwd.id+');javascript:popularSERP('+kwd.id+')" class="" data-toggle="tooltip" title="Palavras relacionadas" > <i class="fa fa-link"></i></a></td>'229 + '</tr>');230 }231}232function popularSERP(kwdid) {233 var request = $.ajax({234 url: '../php/classes/gateway/listKeywordSERPController.php',235 method: "POST",236 data: {237 keywordparentid: kwdid238 },239 success: popularSERPCallback240 });241}242var popularSERPCallback = function (retorno, status) {243 // Apagar as linhas da TBody244 $('#support_table_serp_concorrentes > tbody').empty();245 // faz um parse no retorno246 var lst = JSON.parse(retorno);247 for (var i = 0; i < lst.length; i++) {248 var kwd = lst[i];249 250 $('#support_table_serp_concorrentes > tbody').append('<tr>'251 + '<td>'+ kwd.link +'</td>'252 + '<td>'+kwd.posicaoDA+'</td>'253 + '<td>'+kwd.posicaoPA+'</td>'254 + '<td>'+kwd.linkRelQtd+'</td>'255 + '<td>'+kwd.facebooklike+'</td>'256 + '<td>'+kwd.ranking+'</td>'257 + '<td>'+kwd.visitas+'</td>');258 }259}260function popularRelacionadas(kwdid) {261 var request = $.ajax({262 url: '../php/classes/gateway/listKeywordRelatedController.php',263 method: "POST",264 data: {265 keywordparentid: kwdid266 },267 success: popularRelacionadasCallback268 });269}270var popularRelacionadasCallback = function (retorno, status) {271 // Apagar as linhas da TBody272 $('#support_table_related > tbody').empty();273 // faz um parse no retorno274 var lst = JSON.parse(retorno);275 for (var i = 0; i < lst.length; i++) {276 var kwd = lst[i];277 278 var diff = parseInt(kwd.niveldificuldade,10);279 var diffcss = "danger";280 var difftxt = "Muito DifÃcil";281 if (diff <= 20){282 difftxt = "Muito Fácil";283 diffcss = "success";284 } else if (diff <= 40) {285 difftxt = "Fácil";286 diffcss = "warning";287 } else if (status <= 60) {288 difftxt = "DifÃcil";289 diffcss = "warning";290 }291 var status = kwd.status;292 var statuscss = "info";293 var statustxt = "Processado";294 if (status === 'Q'){295 statustxt = "Na fila";296 statuscss = "warning";297 } else if (status === 'B') {298 statustxt = "Plano Excedido";299 statuscss = "danger";300 } else if (status === 'W') {301 statustxt = "Processando agora";302 statuscss = "sucess";303 }304 $('#support_table_related > tbody').append('<tr>'305 + '<td>'+ kwd.keyword +'</td>'306 + '<td>'+kwd.volumepesquisa+'</td>'307 + '<td>'+kwd.valorcpc+'</td>'308 + '<td>'+kwd.niveldificuldade+'</td>'309 + '<td>'310 + ' <span class="label label-sm label-'+diffcss+'">'+difftxt+'</span>'311 + '</td>'312 + '<td>'313 + ' <span class="label label-sm label-'+statuscss+'">'+statustxt+'</span>'314 + '</td>'315 + '<td>'+kwd.dataAtualizacao+'</td>'316 + '<td><a href="javascript:popularRelacionadas('+kwd.id+')" class="" data-toggle="tooltip" title="Palavras relacionadas" > <i class="fa fa-link"></i></a></td>'317 + '</tr>');318 }319}320//=============================================================================321/* após do DOM totalmente carregado configura e executa alguns procedimentos */322//=============================================================================323$(document).ready(function () {324 /* ==============================================325 CONFIGURA EVENTOS DO LINKS DO MENU326 ==============================================327 */328 $('#btn-refresh').click(popularListaKeywordSolicitadasClick);329 330 // Eventos imediatos após DOM carregado331 popularListaKeyword();332 popularProjetosSERP();...
css.js
Source:css.js
...3import {expect} from 'chai';4describe('diff/css', function() {5 describe('#diffCss', function() {6 it('should diff css', function() {7 const diffResult = diffCss(8 '.test,#value .test{margin-left:50px;margin-right:-40px}',9 '.test2, #value2 .test {\nmargin-top:50px;\nmargin-right:-400px;\n}');10 expect(convertChangesToXML(diffResult)).to.equal(11 '<del>.test</del><ins>.test2</ins>,<del>#value</del> <ins>#value2 </ins>.test<ins> </ins>{'12 + '<del>margin-left</del><ins>\nmargin-top</ins>:50px;<ins>\n</ins>'13 + 'margin-right:<del>-40px</del><ins>-400px;\n</ins>}');14 });15 });...
Using AI Code Generation
1module.exports = {2 {3 },4 {5 },6 {7 },8 {9 },10 {11 },12 paths: {13 },14 engineOptions: {15 },16};
Using AI Code Generation
1var backstopjs = require('backstopjs');2backstopjs('test', {config: 'backstop.json'}).then(function (result) {3 console.log(result);4}).catch(function (error) {5 console.error(error);6});
Using AI Code Generation
1var Backstop = require('backstopjs');2Backstop('test', {3 config: require('./backstop.json')4}).then(function (result) {5 console.log(result);6}).catch(function (error) {7 console.log(error);8});9{ scenarios:
Using AI Code Generation
1var backstopjs = require('backstopjs');2var fs = require('fs');3var path = require('path');4var config = require('./backstop.json');5var config2 = require('./backstop2.json');6var config3 = require('./backstop3.json');7var config4 = require('./backstop4.json');8var config5 = require('./backstop5.json');9var config6 = require('./backstop6.json');10var config7 = require('./backstop7.json');11var config8 = require('./backstop8.json');12var config9 = require('./backstop9.json');13var config10 = require('./backstop10.json');14var config11 = require('./backstop11.json');15var config12 = require('./backstop12.json');16var config13 = require('./backstop13.json');17var config14 = require('./backstop14.json');18var config15 = require('./backstop15.json');19var config16 = require('./backstop16.json');20var config17 = require('./backstop17.json');21var config18 = require('./backstop18.json');22var config19 = require('./backstop19.json');23var config20 = require('./backstop20.json');24var config21 = require('./backstop21.json');25var config22 = require('./backstop22.json');26var config23 = require('./backstop23.json');27var config24 = require('./backstop24.json');28var config25 = require('./backstop25.json');29var config26 = require('./backstop26.json');30var config27 = require('./backstop27.json');31var config28 = require('./backstop28.json');32var config29 = require('./backstop29.json');33var config30 = require('./backstop30.json');34var config31 = require('./backstop31.json');35var config32 = require('./backstop32.json');36var config33 = require('./backstop33.json');37var config34 = require('./backstop34.json');38var config35 = require('./backstop35.json');39var config36 = require('./backstop36.json');40var config37 = require('./backstop37.json');41var config38 = require('./backstop38.json');42var config39 = require('./backstop39.json');43var config40 = require('./backstop40.json');44var config41 = require('./backstop41.json');45var config42 = require('./backstop42.json');46var config43 = require('./backstop43.json');
Using AI Code Generation
1var diff = require('deep-diff').diff;2var fs = require('fs');3var backstopjs = require('backstopjs');4var css1 = fs.readFileSync('test.css', 'utf8');5var css2 = fs.readFileSync('test1.css', 'utf8');6var diffCss = backstopjs.diffCss(css1, css2);7console.log(diffCss);8var diffCss = require('backstopjs/core/util/diffCss');
Using AI Code Generation
1var diff = require('backstopjs').diff;2diff({3}).then(function (result) {4 console.log(result);5});6var reference = require('backstopjs').reference;7reference({8}).then(function (result) {9 console.log(result);10});11var test = require('backstopjs').test;12test({13}).then(function (result) {14 console.log(result);15});16var approve = require('backstopjs').approve;17approve({18}).then(function (result) {19 console.log(result);20});21var reject = require('backstopjs').reject;22reject({23}).then(function (result) {24 console.log(result);25});26var openReport = require('backstopjs').openReport;27openReport({28}).then(function (result) {29 console.log(result);30});31var openReport = require('backstopjs').openReport;32openReport({33}).then(function (result) {34 console.log(result);35});
Using AI Code Generation
1var diff = require('deep-diff').diff;2var fs = require('fs');3var backstopjs = require('backstopjs');4var css1 = fs.readFileSync('test.css', 'utf8');5var css2 = fs.readFileSync('test1.css', 'utf8');6var diffCss = backstopjs.diffCss(css1, css2);7console.log(diffCss);8var diffCss = require('backstopjs/core/util/diffCss');
Using AI Code Generation
1var diff = require('backstopjs').diff;2diff({3}).then(function (result) {4 console.log(result);5});6var reference = require('backstopjs').reference;7reference({8}).then(function (result) {9 console.log(result);10});11var test = require('backstopjs').test;12test({13}).then(function (result) {14 console.log(result);15});16var approve = require('backstopjs').approve;17approve({18}).then(function (result) {19 console.log(result);20});21var reject = require('backstopjs').reject;22reject({23}).then(function (result) {24 console.log(result);25});26var openReport = require('backstopjs').openReport;27openReport({28}).then(function (result) {29 console.log(result);30});31var openReport = require('backstopjs').openReport;32openReport({33}).then(function (result) {34 console.log(result);35});
Using AI Code Generation
1var backstopjs = require('backstopjs');2var config = require('./backstop.json');3var fs = require('fs');4var path = require('path');5var args = process.argv.slice(2);6var testConfig = args[0];7var testUrl = args[1];8var testConfigFile = path.join(__dirname, testConfig);9var testConfig = require(testConfigFile);10config.scenarios[0].url = testUrl;11backstopjs('reference', { config: config })12 .then(function () {13 return backstopjs('test', { config: config });14 })15 .then(function (testResult) {16 var failedCount = testResult.filter(function (scenario) {17 return scenario.status === 'fail';18 }).length;19 var passedCount = testResult.filter(function (scenario) {20 return scenario.status === 'pass';21 }).length;22 console.log('Passed: ' + passedCount);23 console.log('Failed: ' + failedCount);24 if (failedCount > 0) {25 process.exit(1);26 } else {27 process.exit(0);28 }29 })30 .catch(function (err) {31 console.log(err);32 process.exit(1);33 });
Using AI Code Generation
1var Backstop = require('backstopjs');2var fs = require('fs');3var config = JSON.parse(fs.readFileSync('./config.json'));4var scenarios = config.scenarios;5var viewports = config.viewports;6var referenceUrl = config.paths.bitmaps_reference;7var testUrl = config.paths.bitmaps_test;8var diffUrl = config.paths.bitmaps_diff;9var scenarioLength = scenarios.length;10var viewportLength = viewports.length;11for (var i = 0; i < scenarioLength; i++) {12 for (var j = 0; j < viewportLength; j++) {13 var referencePath = referenceUrl + '/' + scenarios[i].label + '/' + viewports[j].label + '.png';14 var testPath = testUrl + '/' + scenarios[i].label + '/' + viewports[j].label + '.png';15 var diffPath = diffUrl + '/' + scenarios[i].label + '/' + viewports[j].label + '.png';16 Backstop.diffCss(referencePath, testPath, diffPath);17 }18}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!