Best JavaScript code snippet using playwright-internal
signatureTest.js
Source:signatureTest.js
...158 }, "the take callback didnt fire", 750);159 160 runs(function ()161 {162 expect(signatureTest.compareImages(signatureTest.empty100sq, signatureTest.callbackImage)).toBe(true);163 });164 });165 166 //bgcolor167 it('should capture an empty signature capture with a colored background', function() {168 runs(function ()169 {170 Rho.Signature.show({171 left:0,172 top:0,173 width:100,174 height:100,175 bgColor: "#FF0000FF",176 penColor: "#000000FF",177 penWidth: 1,178 border: false,179 outputFormat: 'image',180 compressionFormat: 'bmp'181 });182 Rho.Signature.capture(signatureTest.imageCompareCallback);183 });184 185 waitsFor(function ()186 {187 return signatureTest.callbackImageLoaded;188 }, "the take callback didnt fire", 750);189 190 runs(function ()191 {192 expect(signatureTest.compareImages(signatureTest.empty100sqRed, signatureTest.callbackImage)).toBe(true);193 });194 });195 196 it('should draw a simple box on the signature capture', function() {197 runs(function ()198 {199 Rho.Signature.show({200 left:0,201 top:0,202 width:100,203 height:100,204 bgColor: "#FFFFFFFF",205 penColor: "#000000FF",206 penWidth: 1,207 border: false,208 outputFormat: 'image',209 compressionFormat: 'bmp'210 });211 signatureTest.drawBox();212 Rho.Signature.capture(signatureTest.imageCompareCallback);213 });214 215 waitsFor(function ()216 {217 return signatureTest.callbackImageLoaded;218 }, "the take callback didnt fire", 750);219 220 runs(function ()221 {222 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);223 });224 });225 226 it('should draw a simple box with pen width 3 on the signature capture', function() {227 runs(function ()228 {229 Rho.Signature.show({230 left:0,231 top:0,232 width:100,233 height:100,234 bgColor: "#FFFFFFFF",235 penColor: "#000000FF",236 penWidth: 3,237 border: false,238 outputFormat: 'image',239 compressionFormat: 'bmp'240 });241 signatureTest.drawBox();242 Rho.Signature.capture(signatureTest.imageCompareCallback);243 });244 245 waitsFor(function ()246 {247 return signatureTest.callbackImageLoaded;248 }, "the take callback didnt fire", 750);249 250 runs(function ()251 {252 expect(signatureTest.compareImages(signatureTest.box100sqPen3, signatureTest.callbackImage)).toBe(true);253 });254 });255 256 it('should draw a simple blue box on the signature capture', function() {257 runs(function ()258 {259 Rho.Signature.show({260 left:0,261 top:0,262 width:100,263 height:100,264 bgColor: "#FFFFFFFF",265 penColor: "#0000FFFF",266 penWidth: 1,267 border: false,268 outputFormat: 'image',269 compressionFormat: 'bmp'270 });271 signatureTest.drawBox();272 Rho.Signature.capture(signatureTest.imageCompareCallback);273 });274 275 waitsFor(function ()276 {277 return signatureTest.callbackImageLoaded;278 }, "the take callback didnt fire", 750);279 280 runs(function ()281 {282 expect(signatureTest.compareImages(signatureTest.box100sqBlue, signatureTest.callbackImage)).toBe(true);283 });284 });285 286 it('should draw a simple cross on the signature capture', function() {287 runs(function ()288 {289 Rho.Signature.show({290 left:0,291 top:0,292 width:100,293 height:100,294 bgColor: "#FFFFFFFF",295 penColor: "#000000FF",296 penWidth: 1,297 border: false,298 outputFormat: 'image',299 compressionFormat: 'bmp'300 });301 signatureTest.drawCross();302 Rho.Signature.capture(signatureTest.imageCompareCallback);303 });304 305 waitsFor(function ()306 {307 return signatureTest.callbackImageLoaded;308 }, "the take callback didnt fire", 750);309 310 runs(function ()311 {312 expect(signatureTest.compareImages(signatureTest.cross100sq, signatureTest.callbackImage)).toBe(true);313 });314 });315 316 it('should draw a rim on the signature capture', function() {317 runs(function ()318 {319 Rho.Signature.show({320 left:0,321 top:0,322 width:100,323 height:100,324 bgColor: "#FFFFFFFF",325 penColor: "#000000FF",326 penWidth: 1,327 border: false,328 outputFormat: 'image',329 compressionFormat: 'bmp'330 });331 signatureTest.drawCross();332 Rho.Signature.capture(signatureTest.imageCompareCallback);333 });334 335 waitsFor(function ()336 {337 return signatureTest.callbackImageLoaded;338 }, "the take callback didnt fire", 750);339 340 runs(function ()341 {342 expect(signatureTest.compareImages(signatureTest.rim100sq, signatureTest.callbackImage)).toBe(true);343 });344 });345 346 it('should draw a non symmetrical line on the signature capture', function() {347 runs(function ()348 {349 Rho.Signature.show({350 left:0,351 top:0,352 width:100,353 height:100,354 bgColor: "#FFFFFFFF",355 penColor: "#000000FF",356 penWidth: 1,357 border: false,358 outputFormat: 'image',359 compressionFormat: 'bmp'360 });361 signatureTest.drawNonSym();362 Rho.Signature.capture(signatureTest.imageCompareCallback);363 });364 365 waitsFor(function ()366 {367 return signatureTest.callbackImageLoaded;368 }, "the take callback didnt fire", 750);369 370 runs(function ()371 {372 expect(signatureTest.compareImages(signatureTest.nonSym100sq, signatureTest.callbackImage)).toBe(true);373 });374 });375 376 it('should capture a file with the specified name', function() {377 var myFileName = Math.floor((Math.random() * 10000000)) + '';378 var myFileNameNExt = myFileName + '.bmp';379 380 runs(function ()381 {382 Rho.Signature.show({383 left:0,384 top:0,385 width:100,386 height:100,387 bgColor: "#FFFFFFFF",388 penColor: "#000000FF",389 penWidth: 1,390 border: false,391 outputFormat: 'image',392 compressionFormat: 'bmp',393 fileName: myFileName394 });395 Rho.Signature.capture(signatureTest.imageCompareCallback);396 });397 398 waitsFor(function ()399 {400 return signatureTest.callbackImageLoaded;401 }, "the take callback didnt fire", 750);402 403 runs(function ()404 {405 //Expects to end with406 expect(signatureTest.callbackImage.src.indexOf(myFileNameNExt, signatureTest.callbackImage.src.length - myFileNameNExt.length)).not.toEqual(-1);407 expect(Rho.Instrumentation.file_exists(signatureTest.callbackImage.src)).toBe(true);408 });409 });410 411 afterEach(function() {412 signatureTest.deleteFile(signatureTest.callbackImage.src);413 Rho.Signature.hide();414 Rho.Signature.clear();415 //signatureTest.simulateNavigation();416 });417 });418 419 describe('PNG File Capture specs', function() {420 beforeEach(function() {421 signatureTest.callbackImage = new Image();422 signatureTest.callbackImage.onload = signatureTest.callbackImageOnload;423 signatureTest.callbackImageLoaded = false;424 });425 426 it('should capture an empty signature capture', function() {427 runs(function ()428 {429 Rho.Signature.show({430 left:0,431 top:0,432 width:100,433 height:100,434 bgColor: "#FFFFFFFF",435 penColor: "#000000FF",436 penWidth: 1,437 border: false,438 outputFormat: 'image',439 compressionFormat: 'png'440 });441 Rho.Signature.capture(signatureTest.imageCompareCallback);442 });443 444 waitsFor(function ()445 {446 return signatureTest.callbackImageLoaded;447 }, "the take callback didnt fire", 750);448 449 runs(function ()450 {451 expect(signatureTest.compareImages(signatureTest.empty100sq, signatureTest.callbackImage)).toBe(true);452 });453 });454 455 it('should capture an empty signature capture with a colored background', function() {456 runs(function ()457 {458 Rho.Signature.show({459 left:0,460 top:0,461 width:100,462 height:100,463 bgColor: "#FF0000FF",464 penColor: "#000000FF",465 penWidth: 1,466 border: false,467 outputFormat: 'image',468 compressionFormat: 'png'469 });470 Rho.Signature.capture(signatureTest.imageCompareCallback);471 });472 473 waitsFor(function ()474 {475 return signatureTest.callbackImageLoaded;476 }, "the take callback didnt fire", 750);477 478 runs(function ()479 {480 expect(signatureTest.compareImages(signatureTest.empty100sqRed, signatureTest.callbackImage)).toBe(true);481 });482 });483 484 it('should draw a simple box on the signature capture', function() {485 runs(function ()486 {487 Rho.Signature.show({488 left:0,489 top:0,490 width:100,491 height:100,492 bgColor: "#FFFFFFFF",493 penColor: "#000000FF",494 penWidth: 1,495 border: false,496 outputFormat: 'image',497 compressionFormat: 'png'498 });499 signatureTest.drawBox();500 Rho.Signature.capture(signatureTest.imageCompareCallback);501 });502 503 waitsFor(function ()504 {505 return signatureTest.callbackImageLoaded;506 }, "the take callback didnt fire", 750);507 508 runs(function ()509 {510 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);511 });512 });513 514 it('should draw a simple box with pen width 3 on the signature capture', function() {515 runs(function ()516 {517 Rho.Signature.show({518 left:0,519 top:0,520 width:100,521 height:100,522 bgColor: "#FFFFFFFF",523 penColor: "#000000FF",524 penWidth: 3,525 border: false,526 outputFormat: 'image',527 compressionFormat: 'png'528 });529 signatureTest.drawBox();530 Rho.Signature.capture(signatureTest.imageCompareCallback);531 });532 533 waitsFor(function ()534 {535 return signatureTest.callbackImageLoaded;536 }, "the take callback didnt fire", 750);537 538 runs(function ()539 {540 expect(signatureTest.compareImages(signatureTest.box100sqPen3, signatureTest.callbackImage)).toBe(true);541 });542 });543 544 it('should draw a simple box with a transparent background on the signature capture', function() {545 runs(function ()546 {547 Rho.Signature.show({548 left:0,549 top:0,550 width:100,551 height:100,552 bgColor: "#FFFFFF00",553 penColor: "#000000FF",554 penWidth: 1,555 border: false,556 outputFormat: 'image',557 compressionFormat: 'png'558 });559 signatureTest.drawBox();560 Rho.Signature.capture(signatureTest.imageCompareCallback);561 });562 563 waitsFor(function ()564 {565 return signatureTest.callbackImageLoaded;566 }, "the take callback didnt fire", 750);567 568 runs(function ()569 {570 expect(signatureTest.compareImages(signatureTest.box100sqAlpha, signatureTest.callbackImage)).toBe(true);571 });572 });573 574 it('should draw a simple blue box on the signature capture', function() {575 runs(function ()576 {577 Rho.Signature.show({578 left:0,579 top:0,580 width:100,581 height:100,582 bgColor: "#FFFFFFFF",583 penColor: "#0000FFFF",584 penWidth: 1,585 border: false,586 outputFormat: 'image',587 compressionFormat: 'png'588 });589 signatureTest.drawBox();590 Rho.Signature.capture(signatureTest.imageCompareCallback);591 });592 593 waitsFor(function ()594 {595 return signatureTest.callbackImageLoaded;596 }, "the take callback didnt fire", 750);597 598 runs(function ()599 {600 expect(signatureTest.compareImages(signatureTest.box100sqBlue, signatureTest.callbackImage)).toBe(true);601 });602 });603 604 it('should draw a simple semi-transparent box on the signature capture', function() {605 runs(function ()606 {607 Rho.Signature.show({608 left:0,609 top:0,610 width:100,611 height:100,612 bgColor: "#FFFFFFFF",613 penColor: "#00000080",614 penWidth: 1,615 border: false,616 outputFormat: 'image',617 compressionFormat: 'png'618 });619 signatureTest.drawBox();620 Rho.Signature.capture(signatureTest.imageCompareCallback);621 });622 623 waitsFor(function ()624 {625 return signatureTest.callbackImageLoaded;626 }, "the take callback didnt fire", 750);627 628 runs(function ()629 {630 expect(signatureTest.compareImages(signatureTest.box100sqAlphaPen, signatureTest.callbackImage)).toBe(true);631 });632 });633 634 it('should draw a simple cross on the signature capture', function() {635 runs(function ()636 {637 Rho.Signature.show({638 left:0,639 top:0,640 width:100,641 height:100,642 bgColor: "#FFFFFFFF",643 penColor: "#000000FF",644 penWidth: 1,645 border: false,646 outputFormat: 'image',647 compressionFormat: 'png'648 });649 signatureTest.drawCross();650 Rho.Signature.capture(signatureTest.imageCompareCallback);651 });652 653 waitsFor(function ()654 {655 return signatureTest.callbackImageLoaded;656 }, "the take callback didnt fire", 750);657 658 runs(function ()659 {660 expect(signatureTest.compareImages(signatureTest.cross100sq, signatureTest.callbackImage)).toBe(true);661 });662 });663 664 it('should draw a rim on the signature capture', function() {665 runs(function ()666 {667 Rho.Signature.show({668 left:0,669 top:0,670 width:100,671 height:100,672 bgColor: "#FFFFFFFF",673 penColor: "#000000FF",674 penWidth: 1,675 border: false,676 outputFormat: 'image',677 compressionFormat: 'png'678 });679 signatureTest.drawCross();680 Rho.Signature.capture(signatureTest.imageCompareCallback);681 });682 683 waitsFor(function ()684 {685 return signatureTest.callbackImageLoaded;686 }, "the take callback didnt fire", 750);687 688 runs(function ()689 {690 expect(signatureTest.compareImages(signatureTest.rim100sq, signatureTest.callbackImage)).toBe(true);691 });692 });693 694 it('should draw a non symmetrical line on the signature capture', function() {695 runs(function ()696 {697 Rho.Signature.show({698 left:0,699 top:0,700 width:100,701 height:100,702 bgColor: "#FFFFFFFF",703 penColor: "#000000FF",704 penWidth: 1,705 border: false,706 outputFormat: 'image',707 compressionFormat: 'png'708 });709 signatureTest.drawNonSym();710 Rho.Signature.capture(signatureTest.imageCompareCallback);711 });712 713 waitsFor(function ()714 {715 return signatureTest.callbackImageLoaded;716 }, "the take callback didnt fire", 750);717 718 runs(function ()719 {720 expect(signatureTest.compareImages(signatureTest.nonSym100sq, signatureTest.callbackImage)).toBe(true);721 });722 });723 724 it('should capture a file with the specified name', function() {725 var myFileName = Math.floor((Math.random() * 10000000)) + '';726 var myFileNameNExt = myFileName + '.png';727 728 runs(function ()729 {730 Rho.Signature.show({731 left:0,732 top:0,733 width:100,734 height:100,735 bgColor: "#FFFFFFFF",736 penColor: "#000000FF",737 penWidth: 1,738 border: false,739 outputFormat: 'image',740 compressionFormat: 'png',741 fileName: myFileName742 });743 Rho.Signature.capture(signatureTest.imageCompareCallback);744 });745 746 waitsFor(function ()747 {748 return signatureTest.callbackImageLoaded;749 }, "the take callback didnt fire", 750);750 751 runs(function ()752 {753 //Expects to end with754 expect(signatureTest.callbackImage.src.indexOf(myFileNameNExt, signatureTest.callbackImage.src.length - myFileNameNExt.length)).not.toEqual(-1);755 expect(Rho.Instrumentation.file_exists(signatureTest.callbackImage.src)).toBe(true);756 });757 });758 759 afterEach(function() {760 signatureTest.deleteFile(signatureTest.callbackImage.src);761 Rho.Signature.hide();762 Rho.Signature.clear();763 //signatureTest.simulateNavigation();764 });765 });766 767 describe('DataUri Capture specs', function() {768 beforeEach(function() {769 signatureTest.callbackImage = new Image();770 signatureTest.callbackImage.onload = signatureTest.callbackImageOnload;771 signatureTest.callbackImageLoaded = false;772 });773 774 it('should capture an empty signature capture', function() {775 runs(function ()776 {777 Rho.Signature.show({778 left:0,779 top:0,780 width:100,781 height:100,782 bgColor: "#FFFFFFFF",783 penColor: "#000000FF",784 penWidth: 1,785 border: false,786 outputFormat: 'dataUri'787 });788 Rho.Signature.capture(signatureTest.imageCompareCallback);789 });790 791 waitsFor(function ()792 {793 return signatureTest.callbackImageLoaded;794 }, "the take callback didnt fire", 750);795 796 runs(function ()797 {798 expect(signatureTest.compareImages(signatureTest.empty100sq, signatureTest.callbackImage)).toBe(true);799 });800 });801 802 it('should capture an empty signature capture with a RGBA colored background', function() {803 runs(function ()804 {805 Rho.Signature.show({806 left:0,807 top:0,808 width:100,809 height:100,810 bgColor: "#FF0000FF",811 penColor: "#000000FF",812 penWidth: 1,813 border: false,814 outputFormat: 'dataUri'815 });816 Rho.Signature.capture(signatureTest.imageCompareCallback);817 });818 819 waitsFor(function ()820 {821 return signatureTest.callbackImageLoaded;822 }, "the take callback didnt fire", 750);823 824 runs(function ()825 {826 expect(signatureTest.compareImages(signatureTest.empty100sqRed, signatureTest.callbackImage)).toBe(true);827 });828 });829 830 it('should capture an empty signature capture with a RGB colored background', function() {831 runs(function ()832 {833 Rho.Signature.show({834 left:0,835 top:0,836 width:100,837 height:100,838 bgColor: "#FF0000",839 penColor: "#000000",840 penWidth: 1,841 border: false,842 outputFormat: 'dataUri'843 });844 Rho.Signature.capture(signatureTest.imageCompareCallback);845 });846 847 waitsFor(function ()848 {849 return signatureTest.callbackImageLoaded;850 }, "the take callback didnt fire", 750);851 852 runs(function ()853 {854 expect(signatureTest.compareImages(signatureTest.empty100sqRed, signatureTest.callbackImage)).toBe(true);855 });856 });857 858 it('should draw a simple box on the signature capture', function() {859 runs(function ()860 {861 Rho.Signature.show({862 left:0,863 top:0,864 width:100,865 height:100,866 bgColor: "#FFFFFFFF",867 penColor: "#000000FF",868 penWidth: 1,869 border: false,870 outputFormat: 'dataUri'871 });872 signatureTest.drawBox();873 Rho.Signature.capture(signatureTest.imageCompareCallback);874 });875 876 waitsFor(function ()877 {878 return signatureTest.callbackImageLoaded;879 }, "the take callback didnt fire", 750);880 881 runs(function ()882 {883 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);884 });885 });886 887 it('should draw a simple box with pen width 3 on the signature capture', function() {888 runs(function ()889 {890 Rho.Signature.show({891 left:0,892 top:0,893 width:100,894 height:100,895 bgColor: "#FFFFFFFF",896 penColor: "#000000FF",897 penWidth: 3,898 border: false,899 outputFormat: 'dataUri'900 });901 signatureTest.drawBox();902 Rho.Signature.capture(signatureTest.imageCompareCallback);903 });904 905 waitsFor(function ()906 {907 return signatureTest.callbackImageLoaded;908 }, "the take callback didnt fire", 750);909 910 runs(function ()911 {912 expect(signatureTest.compareImages(signatureTest.box100sqPen3, signatureTest.callbackImage)).toBe(true);913 });914 });915 916 it('should draw a simple box with a transparent background on the signature capture', function() {917 runs(function ()918 {919 Rho.Signature.show({920 left:0,921 top:0,922 width:100,923 height:100,924 bgColor: "#FFFFFF00",925 penColor: "#000000FF",926 penWidth: 1,927 border: false,928 outputFormat: 'dataUri'929 });930 signatureTest.drawBox();931 Rho.Signature.capture(signatureTest.imageCompareCallback);932 });933 934 waitsFor(function ()935 {936 return signatureTest.callbackImageLoaded;937 }, "the take callback didnt fire", 750);938 939 runs(function ()940 {941 expect(signatureTest.compareImages(signatureTest.box100sqAlpha, signatureTest.callbackImage)).toBe(true);942 });943 });944 945 it('should draw a simple RGBA blue box on the signature capture', function() {946 runs(function ()947 {948 Rho.Signature.show({949 left:0,950 top:0,951 width:100,952 height:100,953 bgColor: "#FFFFFFFF",954 penColor: "#0000FFFF",955 penWidth: 1,956 border: false,957 outputFormat: 'dataUri'958 });959 signatureTest.drawBox();960 Rho.Signature.capture(signatureTest.imageCompareCallback);961 });962 963 waitsFor(function ()964 {965 return signatureTest.callbackImageLoaded;966 }, "the take callback didnt fire", 750);967 968 runs(function ()969 {970 expect(signatureTest.compareImages(signatureTest.box100sqBlue, signatureTest.callbackImage)).toBe(true);971 });972 });973 974 it('should draw a simple RGB blue box on the signature capture', function() {975 runs(function ()976 {977 Rho.Signature.show({978 left:0,979 top:0,980 width:100,981 height:100,982 bgColor: "#FFFFFF",983 penColor: "#0000FF",984 penWidth: 1,985 border: false,986 outputFormat: 'dataUri'987 });988 signatureTest.drawBox();989 Rho.Signature.capture(signatureTest.imageCompareCallback);990 });991 992 waitsFor(function ()993 {994 return signatureTest.callbackImageLoaded;995 }, "the take callback didnt fire", 750);996 997 runs(function ()998 {999 expect(signatureTest.compareImages(signatureTest.box100sqBlue, signatureTest.callbackImage)).toBe(true);1000 });1001 });1002 1003 it('should draw a simple semi-transparent box on the signature capture', function() {1004 runs(function ()1005 {1006 Rho.Signature.show({1007 left:0,1008 top:0,1009 width:100,1010 height:100,1011 bgColor: "#FFFFFFFF",1012 penColor: "#00000080",1013 penWidth: 1,1014 border: false,1015 outputFormat: 'dataUri',1016 });1017 signatureTest.drawBox();1018 Rho.Signature.capture(signatureTest.imageCompareCallback);1019 });1020 1021 waitsFor(function ()1022 {1023 return signatureTest.callbackImageLoaded;1024 }, "the take callback didnt fire", 750);1025 1026 runs(function ()1027 {1028 expect(signatureTest.compareImages(signatureTest.box100sqAlphaPen, signatureTest.callbackImage)).toBe(true);1029 });1030 });1031 1032 it('should draw a simple cross on the signature capture', function() {1033 runs(function ()1034 {1035 Rho.Signature.show({1036 left:0,1037 top:0,1038 width:100,1039 height:100,1040 bgColor: "#FFFFFFFF",1041 penColor: "#000000FF",1042 penWidth: 1,1043 border: false,1044 outputFormat: 'dataUri'1045 });1046 signatureTest.drawCross();1047 Rho.Signature.capture(signatureTest.imageCompareCallback);1048 });1049 1050 waitsFor(function ()1051 {1052 return signatureTest.callbackImageLoaded;1053 }, "the take callback didnt fire", 750);1054 1055 runs(function ()1056 {1057 expect(signatureTest.compareImages(signatureTest.cross100sq, signatureTest.callbackImage)).toBe(true);1058 });1059 });1060 1061 it('should draw a rim on the signature capture', function() {1062 runs(function ()1063 {1064 Rho.Signature.show({1065 left:0,1066 top:0,1067 width:100,1068 height:100,1069 bgColor: "#FFFFFFFF",1070 penColor: "#000000FF",1071 penWidth: 1,1072 border: false,1073 outputFormat: 'dataUri'1074 });1075 signatureTest.drawCross();1076 Rho.Signature.capture(signatureTest.imageCompareCallback);1077 });1078 1079 waitsFor(function ()1080 {1081 return signatureTest.callbackImageLoaded;1082 }, "the take callback didnt fire", 750);1083 1084 runs(function ()1085 {1086 expect(signatureTest.compareImages(signatureTest.rim100sq, signatureTest.callbackImage)).toBe(true);1087 });1088 });1089 1090 it('should draw a non symmetrical line on the signature capture', function() {1091 runs(function ()1092 {1093 Rho.Signature.show({1094 left:0,1095 top:0,1096 width:100,1097 height:100,1098 bgColor: "#FFFFFFFF",1099 penColor: "#000000FF",1100 penWidth: 1,1101 border: false,1102 outputFormat: 'dataUri'1103 });1104 signatureTest.drawNonSym();1105 Rho.Signature.capture(signatureTest.imageCompareCallback);1106 });1107 1108 waitsFor(function ()1109 {1110 return signatureTest.callbackImageLoaded;1111 }, "the take callback didnt fire", 750);1112 1113 runs(function ()1114 {1115 expect(signatureTest.compareImages(signatureTest.nonSym100sq, signatureTest.callbackImage)).toBe(true);1116 });1117 });1118 1119 afterEach(function() {1120 Rho.Signature.hide();1121 Rho.Signature.clear();1122 //signatureTest.simulateNavigation();1123 });1124 });1125 1126 describe('Parameters that clear the signature area', function() {1127 beforeEach(function() {1128 signatureTest.callbackImage = new Image();1129 signatureTest.callbackImage.onload = signatureTest.callbackImageOnload;1130 signatureTest.callbackImageLoaded = false;1131 });1132 1133 1134 it('clears the signature capture area when penColor is set after drawing', function () {1135 runs(function ()1136 {1137 Rho.Signature.show({1138 left:0,1139 top:0,1140 width:100,1141 height:100,1142 bgColor: "#FFFFFFFF",1143 penColor: "#0000FFFF",1144 penWidth: 1,1145 border: false,1146 outputFormat: 'dataUri'1147 });1148 signatureTest.drawNonSym();1149 Rho.Signature.setProperty({penColor: '#000000FF'});1150 signatureTest.drawBox();1151 Rho.Signature.capture(signatureTest.imageCompareCallback);1152 });1153 1154 waitsFor(function ()1155 {1156 return signatureTest.callbackImageLoaded;1157 }, "the take callback didnt fire", 750);1158 1159 runs(function ()1160 {1161 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1162 });1163 });1164 1165 it('clears the signature capture area when bgColor is set after drawing', function () {1166 runs(function ()1167 {1168 Rho.Signature.show({1169 left:0,1170 top:0,1171 width:100,1172 height:100,1173 bgColor: "#FFFF00FF",1174 penColor: "#000000FF",1175 penWidth: 1,1176 border: false,1177 outputFormat: 'dataUri'1178 });1179 signatureTest.drawNonSym();1180 Rho.Signature.setProperty({bgColor: '#FFFFFFFF'});1181 signatureTest.drawBox();1182 Rho.Signature.capture(signatureTest.imageCompareCallback);1183 });1184 1185 waitsFor(function ()1186 {1187 return signatureTest.callbackImageLoaded;1188 }, "the take callback didnt fire", 750);1189 1190 runs(function ()1191 {1192 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1193 });1194 });1195 1196 it('clears the signature capture area when clear is called', function () {1197 runs(function ()1198 {1199 Rho.Signature.show({1200 left:0,1201 top:0,1202 width:100,1203 height:100,1204 bgColor: "#FFFFFFFF",1205 penColor: "#000000FF",1206 penWidth: 1,1207 border: false,1208 outputFormat: 'dataUri'1209 });1210 signatureTest.drawNonSym();1211 Rho.Signature.clear();1212 signatureTest.drawBox();1213 Rho.Signature.capture(signatureTest.imageCompareCallback);1214 });1215 1216 waitsFor(function ()1217 {1218 return signatureTest.callbackImageLoaded;1219 }, "the take callback didnt fire", 750);1220 1221 runs(function ()1222 {1223 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1224 });1225 });1226 1227 it('clears the signature capture area when height is changed', function () {1228 runs(function ()1229 {1230 Rho.Signature.show({1231 left:0,1232 top:0,1233 width:100,1234 height:99,1235 bgColor: "#FFFFFFFF",1236 penColor: "#000000FF",1237 penWidth: 1,1238 border: false,1239 outputFormat: 'dataUri'1240 });1241 signatureTest.drawNonSym();1242 Rho.Signature.setProperty({height: 100});1243 signatureTest.drawBox();1244 Rho.Signature.capture(signatureTest.imageCompareCallback);1245 });1246 1247 waitsFor(function ()1248 {1249 return signatureTest.callbackImageLoaded;1250 }, "the take callback didnt fire", 750);1251 1252 runs(function ()1253 {1254 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1255 });1256 });1257 1258 it('clears the signature capture area when width is changed', function () {1259 runs(function ()1260 {1261 Rho.Signature.show({1262 left:0,1263 top:0,1264 width:99,1265 height:100,1266 bgColor: "#FFFFFFFF",1267 penColor: "#000000FF",1268 penWidth: 1,1269 border: false,1270 outputFormat: 'dataUri'1271 });1272 signatureTest.drawNonSym();1273 Rho.Signature.setProperty({width: 100});1274 signatureTest.drawBox();1275 Rho.Signature.capture(signatureTest.imageCompareCallback);1276 });1277 1278 waitsFor(function ()1279 {1280 return signatureTest.callbackImageLoaded;1281 }, "the take callback didnt fire", 750);1282 1283 runs(function ()1284 {1285 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1286 });1287 });1288 1289 afterEach(function() {1290 Rho.Signature.hide();1291 Rho.Signature.clear();1292 //signatureTest.simulateNavigation();1293 });1294 });1295 1296 describe('Parameters that shouldnt clear the signature area', function() {1297 beforeEach(function() {1298 signatureTest.callbackImage = new Image();1299 signatureTest.callbackImage.onload = signatureTest.callbackImageOnload;1300 signatureTest.callbackImageLoaded = false;1301 });1302 1303 it('doesnt clear the signature capture area when left is changed', function () {1304 runs(function ()1305 {1306 Rho.Signature.show({1307 left:1,1308 top:0,1309 width:100,1310 height:100,1311 bgColor: "#FFFFFFFF",1312 penColor: "#000000FF",1313 penWidth: 1,1314 border: false,1315 outputFormat: 'dataUri'1316 });1317 signatureTest.drawBox();1318 Rho.Signature.setProperty({left: 0});1319 Rho.Signature.capture(signatureTest.imageCompareCallback);1320 });1321 1322 waitsFor(function ()1323 {1324 return signatureTest.callbackImageLoaded;1325 }, "the take callback didnt fire", 750);1326 1327 runs(function ()1328 {1329 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1330 });1331 });1332 1333 it('doesnt clear the signature capture area when top is changed', function () {1334 runs(function ()1335 {1336 Rho.Signature.show({1337 left:0,1338 top:1,1339 width:100,1340 height:100,1341 bgColor: "#FFFFFFFF",1342 penColor: "#000000FF",1343 penWidth: 1,1344 border: false,1345 outputFormat: 'dataUri'1346 });1347 signatureTest.drawBox();1348 Rho.Signature.setProperty({top: 0});1349 Rho.Signature.capture(signatureTest.imageCompareCallback);1350 });1351 1352 waitsFor(function ()1353 {1354 return signatureTest.callbackImageLoaded;1355 }, "the take callback didnt fire", 750);1356 1357 runs(function ()1358 {1359 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1360 });1361 });1362 1363 it('doesnt clear the signature capture area when border is changed', function () {1364 runs(function ()1365 {1366 Rho.Signature.show({1367 left:0,1368 top:0,1369 width:100,1370 height:100,1371 bgColor: "#FFFFFFFF",1372 penColor: "#000000FF",1373 penWidth: 1,1374 border: true,1375 outputFormat: 'dataUri'1376 });1377 signatureTest.drawBox();1378 Rho.Signature.setProperty({border: false});1379 Rho.Signature.capture(signatureTest.imageCompareCallback);1380 });1381 1382 waitsFor(function ()1383 {1384 return signatureTest.callbackImageLoaded;1385 }, "the take callback didnt fire", 750);1386 1387 runs(function ()1388 {1389 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1390 });1391 });1392 1393 it('doesnt clear the signature capture area when imageFormat is changed', function () {1394 runs(function ()1395 {1396 Rho.Signature.show({1397 left:0,1398 top:0,1399 width:100,1400 height:100,1401 bgColor: "#FFFFFFFF",1402 penColor: "#000000FF",1403 penWidth: 1,1404 border: true,1405 outputFormat: 'dataUri',1406 imageFormat: 'png'1407 });1408 signatureTest.drawBox();1409 Rho.Signature.setProperty({imageFormat: 'bmp'});1410 Rho.Signature.capture(signatureTest.imageCompareCallback);1411 });1412 1413 waitsFor(function ()1414 {1415 return signatureTest.callbackImageLoaded;1416 }, "the take callback didnt fire", 750);1417 1418 runs(function ()1419 {1420 expect(signatureTest.compareImages(signatureTest.box100sq, signatureTest.callbackImage)).toBe(true);1421 });1422 });1423 1424 afterEach(function() {1425 Rho.Signature.hide();1426 Rho.Signature.clear();1427 //signatureTest.simulateNavigation();1428 });1429 });1430 describe('Fullscreen Tests', function() {1431 beforeEach(function() {1432 signatureTest.callbackFired = false;1433 });1434 1435 it('Sends an \'ok\' status when fullscreen signature is captured using the capture function', function() {1436 runs(function ()1437 {1438 Rho.Signature.takeFullscreen({1439 left:0,1440 top:0,1441 width:100,1442 height:100,1443 bgColor: "#FFFFFFFF",1444 penColor: "#000000FF",1445 penWidth: 1,1446 border: false,1447 outputFormat: 'dataUri'1448 });1449 Rho.Signature.capture(signatureTest.statusCallback);1450 });1451 1452 waitsFor(function ()1453 {1454 return signatureTest.callbackFired;1455 }, "the take callback didnt fire", 750);1456 1457 runs(function ()1458 {1459 expect(signatureTest.callbackStatus).toEqual('ok');1460 });1461 });1462 1463 it('Sends a \'cancel\' status when fullscreen signature is closed using the hide function', function() {1464 runs(function ()1465 {1466 Rho.Signature.takeFullscreen({1467 left:0,1468 top:0,1469 width:100,1470 height:100,1471 bgColor: "#FFFFFFFF",1472 penColor: "#000000FF",1473 penWidth: 1,1474 border: false,1475 outputFormat: 'dataUri'1476 }, signatureTest.statusCallback);1477 Rho.Signature.hide();1478 });1479 1480 waitsFor(function ()1481 {1482 return signatureTest.callbackFired;1483 }, "the take callback didnt fire", 750);1484 1485 runs(function ()1486 {1487 expect(signatureTest.callbackStatus).toEqual('cancel');1488 });1489 });1490 1491 afterEach(function() {1492 Rho.Signature.hide();1493 Rho.Signature.clear();1494 //signatureTest.simulateNavigation();1495 });1496 });1497 1498 describe('Vector Tests', function() {1499 beforeEach(function() {1500 signatureTest.vectorCallbackFired = false;1501 signatureTest.vectorCallbackData = null;1502 });1503 1504 it('should get vectors for a vertical line', function() {1505 runs(function ()1506 {1507 Rho.Signature.setVectorCallback(signatureTest.vectorCallback);1508 Rho.Signature.show({1509 left:0,1510 top:0,1511 width:100,1512 height:100,1513 bgColor: "#FFFFFFFF",1514 penColor: "#000000FF",1515 penWidth: 1,1516 border: false,1517 outputFormat: 'dataUri'1518 });1519 signatureTest.doDrawLine(20,20,20,60);1520 });1521 1522 waitsFor(function ()1523 {1524 return signatureTest.vectorCallbackFired;1525 }, "the vectorCallback didnt fire", 750);1526 1527 runs(function ()1528 {1529 expect(signatureTest.vectorCallbackData).toEqual([20,20,20,60,65535,65535]);1530 });1531 });1532 1533 it('should get vectors for a horizontal line', function() {1534 runs(function ()1535 {1536 Rho.Signature.setVectorCallback(signatureTest.vectorCallback);1537 Rho.Signature.show({1538 left:0,1539 top:0,1540 width:100,1541 height:100,1542 bgColor: "#FFFFFFFF",1543 penColor: "#000000FF",1544 penWidth: 1,1545 border: false,1546 outputFormat: 'dataUri'1547 });1548 signatureTest.doDrawLine(20,20,60,20);1549 });1550 1551 waitsFor(function ()1552 {1553 return signatureTest.vectorCallbackFired;1554 }, "the vectorCallback didnt fire", 750);1555 1556 runs(function ()1557 {1558 expect(signatureTest.vectorCallbackData).toEqual([20,20,60,20,65535,65535]);1559 });1560 });1561 1562 it('should get vectors for a box', function() {1563 runs(function ()1564 {1565 Rho.Signature.setVectorCallback(signatureTest.vectorCallback);1566 Rho.Signature.show({1567 left:0,1568 top:0,1569 width:100,1570 height:100,1571 bgColor: "#FFFFFFFF",1572 penColor: "#000000FF",1573 penWidth: 1,1574 border: false,1575 outputFormat: 'dataUri'1576 });1577 signatureTest.drawBox();1578 });1579 1580 waitsFor(function ()1581 {1582 return signatureTest.vectorCallbackFired;1583 }, "the vectorCallback didnt fire", 750);1584 1585 runs(function ()1586 {1587 expect(signatureTest.vectorCallbackData).toEqual([20,20,20,60,60,60,60,20,20,20,65535,65535]);1588 });1589 });1590 1591 it('should receive two separate vector events for two separate lines', function() {1592 runs(function ()1593 {1594 Rho.Signature.setVectorCallback(signatureTest.vectorCallback);1595 Rho.Signature.show({1596 left:0,1597 top:0,1598 width:100,1599 height:100,1600 bgColor: "#FFFFFFFF",1601 penColor: "#000000FF",1602 penWidth: 1,1603 border: false,1604 outputFormat: 'dataUri'1605 });1606 signatureTest.doDrawLine(20,20,20,60);1607 });1608 1609 waitsFor(function ()1610 {1611 return signatureTest.vectorCallbackFired;1612 }, "the vectorCallback didnt fire", 750);1613 1614 runs(function ()1615 {1616 eexpect(signatureTest.vectorCallbackData).toEqual([20,20,20,60,65535,65535]);1617 signatureTest.vectorCallbackFired = false;1618 signatureTest.doDrawLine(30,30,30,60);1619 });1620 1621 1622 waitsFor(function ()1623 {1624 return signatureTest.vectorCallbackFired;1625 }, "the vectorCallback didnt fire", 750);1626 1627 runs(function ()1628 {1629 expect(signatureTest.vectorCallbackData).toEqual([30,30,30,60,65535,65535]);1630 });1631 1632 });1633 1634 afterEach(function() {1635 Rho.Signature.setVectorCallback(null);1636 Rho.Signature.hide();1637 Rho.Signature.clear();1638 //signatureTest.simulateNavigation();1639 });1640 });1641 1642 describe('Defaults Tests', function() {1643 beforeEach(function() {1644 signatureTest.callbackFired = false;1645 });1646 1647 it('Doesnt exception if take is given an empty parameter object', function(){1648 runs(function ()1649 {1650 Rho.Signature.show({}, signatureTest);1651 Rho.Signature.hide();1652 });1653 1654 waitsFor(function ()1655 {1656 return signatureTest.callbackFired;1657 }, "the take callback didnt fire", 750);1658 1659 runs(function ()1660 {1661 expect(signatureTest.callbackStatus).toEqual('cancel');1662 });1663 });1664 1665 it('Captures using default values if take is given an empty parameter object', function(){1666 runs(function ()1667 {1668 Rho.Signature.show({});1669 signatureTest.drawDefaultBox();1670 Rho.Signature.capture(signatureTest.imageCompareCallback);1671 });1672 1673 waitsFor(function ()1674 {1675 return signatureTest.callbackImageLoaded;1676 }, "the take callback didnt fire", 750);1677 1678 runs(function ()1679 {1680 expect(signatureTest.compareImages(signatureTest.box200150, signatureTest.callbackImage)).toBe(true);1681 signatureTest.deleteFile(signatureTest.callbackImage.src);1682 });1683 });1684 1685 it('Captures using default values if take is given an parameter object with only one parameter', function(){1686 runs(function ()1687 {1688 Rho.Signature.show({outputFormat:'dataUri'});1689 signatureTest.drawDefaultBox();1690 Rho.Signature.capture(signatureTest.imageCompareCallback);1691 });1692 1693 waitsFor(function ()1694 {1695 return signatureTest.callbackImageLoaded;1696 }, "the take callback didnt fire", 750);1697 1698 runs(function ()1699 {1700 expect(signatureTest.compareImages(signatureTest.box200150, signatureTest.callbackImage)).toBe(true);1701 });1702 });1703 1704 afterEach(function() {1705 Rho.Signature.hide();1706 Rho.Signature.clear();1707 //signatureTest.simulateNavigation();1708 }); 1709 });1710});1711//Q. What happens on device rotate?1712////INVALID cases1713//Bad compression1714//invalid compression for platform...
image-base64.js
Source:image-base64.js
...74 }75 )76 .should.be.eventually.fulfilled77 .then(function(img) {78 compareImages(img.data, TEST_FORMAT);79 })80 .should.notify(done);81 });82 it('applying crop operation', function(done) {83 var TEST_CROP =84 'Qk2aAAAAAAAAAIoAAAB8AAAAAgAAAAIAAAABABgAAAAAABAAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+85 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAAAAAAAA'+86 'AEAAAAAAAAAAAAAAAAAAAAZmZmAP8AAAAAAP9/AAAAAA==';87 getImageModified('crop=(0,0,2,2)')88 .then(function(img) {89 compareImages(img.data, TEST_CROP);90 })91 .should.notify(done);92 });93 it('applying blur operation', function(done) {94 var TEST_BLUR =95 'Qk2uAAAAAAAAAIoAAAB8AAAAAwAAAAMAAAABABgAAAAAAC'+96 'QAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+97 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAA'+98 'AAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAA'+99 'AAAAAAAEAAAAAAAAAAAAAAAAAAAAyatKvVxetBZ'+100 'PAAAAc3JpZmRmVlRwAAAALyuVLlx9GpWaAAAA';101 getImageModified('blur=(0.1 , 1.2)')102 .then(function(img) {103 compareImages(img.data, TEST_BLUR);104 })105 .should.notify(done);106 });107 it('applying resizeWidth operation', function(done) {108 var TEST_RESIZE_WIDTH =109 'Qk2aAAAAAAAAAIoAAAB8AAAAAgAAAAIAAAABABgAAAAAABAAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+110 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAAAAAAAA'+111 'AEAAAAAAAAAAAAAAAAAAAAv7ZTox5bAAAsPHEQl3kAAA==';112 getImageModified('resizeWidth=2')113 .then(function(img) {114 compareImages(img.data, TEST_RESIZE_WIDTH);115 })116 .should.notify(done);117 });118 it('applying resizeHeight operation', function(done) {119 var TEST_RESIZE_HEIGHT =120 'Qk2aAAAAAAAAAIoAAAB8AAAAAgAAAAIAAAABABgAAAAAABAAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+121 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAAAAAAAA'+122 'AEAAAAAAAAAAAAAAAAAAAAv7ZTox5bAAAsPHEQl3kAAA==';123 getImageModified('resizeHeight=2')124 .then(function(img) {125 compareImages(img.data, TEST_RESIZE_HEIGHT);126 })127 .should.notify(done);128 });129 it('applying resizeAndFill operation', function(done) {130 var TEST_RESIZE_AND_FILL =131 'Qk2uAAAAAAAAAIoAAAB8AAAAAwAAAAMAAAABABgAAAAAACQAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+132 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAAAAAAAA'+133 'AEAAAAAAAAAAAAAAAAAAAA//8A/wD//wAAAAAAZmZmAP8AAAB/AAAAAAD/fwAAAP//AAAA';134 getImageModified('resizeAndFill=(3, 0000FF)')135 .then(function(img) {136 compareImages(img.data, TEST_RESIZE_AND_FILL);137 })138 .should.notify(done);139 });140 it('applying cropFromCenter operation', function(done) {141 var TEST_CROP_FROM_CENTER =142 'Qk2OAAAAAAAAAIoAAAB8AAAAAQAAAAEAAAABABgAAAAAAAQAAAATCwAAEwsAAAAAAAAAAAAAAAD/AAD/A'+143 'AD/AAAAAAAA/0JHUnMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0M7Mvr0fhQz8KV4UAAAAAAAAAAAAAAA'+144 'AEAAAAAAAAAAAAAAAAAAAAAP8AAA==';145 getImageModified('cropFromCenter=(1, 1)')146 .then(function(img) {147 compareImages(img.data, TEST_CROP_FROM_CENTER);148 })149 .should.notify(done);150 });151 } else {152 it.skip('This (Chrome) browser is not supported!', function() {});153 }154 });155 });...
tests-imagediff-blackbox.js
Source:tests-imagediff-blackbox.js
...12 assert(result.status === status, `Result does not have expected status ${status}: ${JSON.stringify(result, null, 2)}`);13 }14 it(`should return status ${Status.IMAGES_SAME} for two same images`, function () {15 const imagePath = path.join(baselineDir, imageName);16 const result = compareImages(createConfig(imagePath, imagePath));17 assertStatus(result, Status.IMAGES_SAME);18 });19 it(`should return status ${Status.IMAGES_SAME} for two directories with same images`, function () {20 const result = compareImages(createConfig(baselineDir, baselineDir));21 assertStatus(result, Status.IMAGES_SAME);22 });23 it(`should return status ${Status.IMAGES_DIFFERENT} for two different images`, function () {24 const baselineImagePath = path.join(baselineDir, imageName);25 const capturedImagePath = path.join(capturedDir, imageName);26 const result = compareImages(createConfig(baselineImagePath, capturedImagePath));27 assertStatus(result, Status.IMAGES_DIFFERENT);28 });29 it(`should return status ${Status.IMAGES_DIFFERENT} for two directories with different images`, function () {30 const result = compareImages(createConfig(baselineDir, capturedDir));31 assertStatus(result, Status.IMAGES_DIFFERENT);32 });33 it(`should return status ${Status.IMAGES_DIFFERENT} if a baseline image is missing - dir comparison`, function () {34 const badBaselineDir = path.join(baselineDir, '..');35 const result = compareImages(createConfig(badBaselineDir, capturedDir));36 assertStatus(result, Status.IMAGES_DIFFERENT);37 });38 it(`should return status ${Status.PATHS_INCORRECT} if a baseline image is missing - file comparison`, function () {39 const baselineImagePath = path.join(baselineDir, 'bad_image.png');40 const capturedImagePath = path.join(capturedDir, imageName);41 const result = compareImages(createConfig(baselineImagePath, capturedImagePath));42 assertStatus(result, Status.PATHS_INCORRECT);43 });44 it(`should return status ${Status.IMAGE_NAMES_ARE_DIFFERENT} for image with different name`, function () {45 const baselineImagePath = path.join(baselineDir, imageName);46 const capturedImagePath = path.join(capturedDir, '..', 'backup', 'baseline_image.png');47 const result = compareImages(createConfig(baselineImagePath, capturedImagePath));48 assertStatus(result, Status.IMAGE_NAMES_ARE_DIFFERENT);49 });50 it(`should return status ${Status.PATHS_INCORRECT} for two incorrect paths`, function () {51 const result = compareImages(createConfig('/bad/path/1', '/bad/path/2'));52 assertStatus(result, Status.PATHS_INCORRECT);53 });54 it(`should return status ${Status.PATHS_INCORRECT} for even one incorrect path`, function () {55 const result = compareImages(createConfig('/bad/path/1', capturedDir));56 assertStatus(result, Status.PATHS_INCORRECT);57 });58 it(`should return status ${Status.PATHS_COMBINATION_INCORRECT} for one path being a directory and the second a file (not supported use case)`, function () {59 const result = compareImages(createConfig(path.join(baselineDir, imageName), capturedDir));60 assertStatus(result, Status.PATHS_COMBINATION_INCORRECT);61 });62 it(`should return status ${Status.UNKNOWN_ERROR} for two files that are not images`, function () {63 // Diff library in this comparison pollutes stderr, disable it for a moment so we get cleaner test output,64 // error message is captured in the result anyway, no need to have it printed randomly in the result list65 turnOffStderr();66 const result = compareImages(createConfig(__filename, __filename));67 turnOnStderr();68 assertStatus(result, Status.UNKNOWN_ERROR);69 });70 it(`should return status ${Status.MULTIPLE_CONSOLES_RUNNING} if there are already multiple consoles running`, function () {71 const consoles = [72 startConsole(createResultFile(baselineDir, capturedDir)),73 startConsole(createResultFile(baselineDir, capturedDir), 43211)74 ];75 try {76 const config = {...createConfig(baselineDir, capturedDir), mode: Mode.WITH_CONSOLE};77 const result = compareImages(config);78 assertStatus(result, Status.MULTIPLE_CONSOLES_RUNNING);79 } finally {80 consoles.forEach(c => c.kill(9));81 }82 });...
depage-compare-images.js
Source:depage-compare-images.js
...88 /* }}} */89 /* {{{ $.fn.depageCompareImages() */90 $.fn.depageCompareImages = function(options){91 return this.each(function(){92 (new $.depage.compareImages(this, options));93 });94 };95 /* }}} */96})(jQuery);...
compareImages.test.js
Source:compareImages.test.js
...7 test("Buffers data", async () => {8 const readImg1 = readFile("./demoassets/People.jpg");9 const readImg2 = readFile("./demoassets/People2.jpg");10 const readComparison = readFile("./nodejs-tests/assets/PeopleComparedToPeople2.png");11 const data = await compareImages(await readImg1, await readImg2);12 const buffer = data.getBuffer();13 const comparison = await readComparison;14 expect(data.isSameDimensions).toBe(true);15 expect(data.misMatchPercentage).toEqual("8.66");16 expect(buffer).toBeInstanceOf(Buffer);17 expect(buffer.length).toBe(91876);18 expect(buffer.equals(comparison)).toBe(true);19 });20 test("Buffer data includeOriginal", async () => {21 const readImg1 = readFile("./demoassets/People.jpg");22 const readImg2 = readFile("./demoassets/People2.jpg");23 const readComparison = readFile("./nodejs-tests/assets/PeopleComparedToPeople2WithOriginal.png");24 const data = await compareImages(await readImg1, await readImg2);25 const buffer = data.getBuffer(true);26 const comparison = await readComparison;27 expect(buffer.equals(comparison)).toBe(true);28 });29 test("throws when failed", async () => {30 const promise = compareImages(fs.readFileSync("./demoassets/People.jpg"), "bogus data");31 await expect(promise).rejects.toMatch("Error: ENOENT, No such file or directory 'bogus data'");32 });33 test("returns early", async () => {34 const readImg1 = readFile("./demoassets/People.jpg");35 const readImg2 = readFile("./demoassets/People2.jpg");36 const options = {37 returnEarlyThreshold: 538 };39 const data = await compareImages(await readImg1, await readImg2, options);40 expect(data.misMatchPercentage).toEqual("5.00");41 });...
App.js
Source:App.js
1import React, { useState, useEffect } from "react";2import AllImages from "./components/AllImages";3import Pagination from "./components/Pagination";4import Comparisiontable from "./components/Comparisiontable";5import axios from "axios";6import "./App.css";7const App = () => {8 const [images, setImages] = useState([]);9 const [compareImages, setCompareImages] = useState([]);10 const [loading, setLoading] = useState(false);11 const [currentPage, setCurrentPage] = useState(1);12 const [imagesPerPage] = useState(10);13 useEffect(() => {14 const fetchImages = async () => {15 setLoading(true);16 const res = await axios.get(17 "https://jsonplaceholder.typicode.com/photos"18 );19 setImages(res.data);20 setLoading(false);21 };22 fetchImages();23 }, []);24 // Get current images25 const indexOfLastImage = currentPage * imagesPerPage;26 const indexOfFirstImage = indexOfLastImage - imagesPerPage;27 const currentImages = images.slice(indexOfFirstImage, indexOfLastImage);28 // Change page29 const paginate = (pageNumber) => setCurrentPage(pageNumber);30 //add to table31 const addComparision = (img) => {32 setCompareImages((compareImages) => [...compareImages, img]);33 console.log(compareImages);34 };35 const removeComparision = (img) => {36 setCompareImages(compareImages.filter((item) => item.id !== img.id));37 console.log(compareImages);38 };39 return (40 <div className="container mt-5">41 <h1 className="text-primary mb-3">42 All Images Current PageNo {currentPage}{" "}43 </h1>44 <AllImages45 images={currentImages}46 loading={loading}47 addComparision={addComparision}48 removeComparision={removeComparision}49 comparedImages={compareImages}50 />51 <Pagination52 imagesPerPage={imagesPerPage}53 totalImages={images.length}54 paginate={paginate}55 />56 <Comparisiontable imagesListing={compareImages} />57 </div>58 );59};...
compare-slider.js
Source:compare-slider.js
1const divider = document.querySelector('.compare-slider__divider');2const compareImages = (event) => {3 const containerCoords = document.querySelector('.compare-slider').getBoundingClientRect();4 const imgAfter = document.querySelector('.compare-slider__after');5 const dividerHalf = divider.offsetWidth / 2;6 const dividerPos = event.clientX - dividerHalf - containerCoords.left;7 if (dividerPos < (0 - dividerHalf) || dividerPos > (containerCoords.width - dividerHalf)) {8 return;9 }10 divider.style.left = `${dividerPos / containerCoords.width * 100}%`;11 imgAfter.style.width = `${(dividerPos + dividerHalf) / containerCoords.width * 100}%`;12};13divider.addEventListener('pointerdown', (event) => {14 event.preventDefault();15 document.addEventListener('pointermove', compareImages);16});17document.addEventListener('pointerup', () => {18 document.removeEventListener('pointermove', compareImages);19});20divider.addEventListener('touchstart', (event) => {21 event.preventDefault();22 document.addEventListener('touchmove', compareImages);23});24document,addEventListener('touchend', () => {25 document.removeEventListener('touchmove', compareImages);...
resemble.js
Source:resemble.js
1//var resemble = require('../resemble.js');2(function () {3 $("#run1").click(function(){compareImages("Login_antes.png", "Login_despues.png",1);});4 $("#run2").click(function(){compareImages("Crear_Desafio_antes.png", "Crear_Desafio_despues.png",2);});5 $("#run3").click(function(){compareImages("Crear_Habito_antes.png","Crear_Habito_despues.png",3);});6})();7function compareImages(image1, image2, result) {8 var response;9 resemble(image1).compareTo(image2).ignoreLess().onComplete(function (data) {10 console.log(data);11 response = 'RESULTADO: \n' + JSON.stringify(data);12 $('#result'+result).html(response);13 });...
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const image = await page.screenshot();6 const result = await page._delegate.compareImages(image, image);7 console.log(result);8 await browser.close();9})();10{11}
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const image = await page.screenshot();6 const { mismatchedPixels } = await page._delegate.compareImages(image, image);7 console.log(mismatchedPixels);8 await browser.close();9})();
Using AI Code Generation
1const { compareImages } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement.js');2const fs = require('fs');3const path = require('path');4const { chromium } = require('playwright-core');5const { toMatchImageSnapshot } = require('jest-image-snapshot');6expect.extend({ toMatchImageSnapshot });7const BASE_DIR = path.join(__dirname, 'screenshots');8if (!fs.existsSync(BASE_DIR)) {9 fs.mkdirSync(BASE_DIR);10}11describe('playwright image comparison', () => {12 let browser;13 beforeAll(async () => {14 browser = await chromium.launch({15 });16 });17 afterAll(async () => {18 await browser.close();19 });20 test('image comparison', async () => {21 const page = await browser.newPage();22 await page.screenshot({ path: path.join(BASE_DIR, 'google.png') });23 const result = await compareImages(24 path.join(BASE_DIR, 'google.png'),25 path.join(BASE_DIR, 'google.png')26 );27 expect(result).toMatchImageSnapshot();28 });29});30const result = await compareImages(31 path.join(BASE_DIR, 'google.png'),32 path.join(BASE_DIR, 'google.png')33);34expect(result).toMatchImageSnapshot();35 ✓ image comparison (1137 ms)
Using AI Code Generation
1const { compareImages } = require('@playwright/test');2const fs = require('fs');3const path = require('path');4(async () => {5 const { artifact, diffOutput } = await compareImages({6 baselineFolder: path.join(__dirname, 'baseline'),7 screenshotFolder: path.join(__dirname, 'screenshots'),8 diffFolder: path.join(__dirname, 'diff'),9 });10 fs.writeFileSync(path.join(__dirname, 'report.json'), JSON.stringify(artifact, null, 2));11 fs.writeFileSync(path.join(__dirname, 'diff', 'diff.png'), diffOutput);12})();13"scripts": {14 }15const { test, expect } = require('@playwright/test');16test('example test', async ({ page }) => {17 const image = await page.screenshot();18 expect(image).toMatchSnapshot('playwright-homepage.png');19});20"scripts": {21 }22const { test, expect } = require('@playwright/test');23test('example test', async ({ page }) => {24 const image = await page.screenshot();25 expect(image).toMatchSnapshot('playwright-homepage.png');26});27"scripts": {28 }29const { test, expect } = require('@playwright/test');30test('example test', async ({ page }) => {31 const image = await page.screenshot();32 expect(image).toMatchSnapshot('playwright-homepage.png');33});34"scripts": {35 }
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!