|
| 1 | +// Test the 'add a test case' feature |
| 2 | +var outputDir = "/test-testcases-outputs" |
| 3 | + |
| 4 | + |
| 5 | +var baseUrl = 'http://localhost:8003/'; |
| 6 | + |
| 7 | +// test visualize.html (mode=edit, mode=display), iframe-embed.html, and live.html |
| 8 | +var urlFragments = [ |
| 9 | + 'http://localhost:8003/visualize.html#code=def+multiply(a,+b,+c%29%3A%0A++++return+a+*+b+*+c&mode=edit&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=2&rawInputLstJSON=%5B%5D&testCasesJSON=%5B%22assert+multiply(1,2,3%29+%3D%3D+6%22,%22assert+multiply(3,2,1%29+%3D%3D+5%22,%22assert+multiply(1,2%29+%3D%3D+2%5Cn%23+assert+%3Ctest+condition%3E%22,%22assert+multiply(1,2%29+%3D+3%5Cn%23+assert+%3Ctest+condition%3E%22%5D', |
| 10 | + |
| 11 | +] |
| 12 | + |
| 13 | + |
| 14 | +var DELAY_MS = 100; |
| 15 | + |
| 16 | +var fs = require('fs'); |
| 17 | +var path = fs.absolute(fs.workingDirectory + '/phantomcss.js'); |
| 18 | +var phantomcss = require(path); |
| 19 | + |
| 20 | +casper.test.begin('Testing OPT test cases, loading from URL strings', function (test) { |
| 21 | + // boring setup code taken from PhantomCSS demo |
| 22 | + phantomcss.init({ |
| 23 | + rebase: casper.cli.get( "rebase" ), |
| 24 | + // SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths |
| 25 | + casper: casper, |
| 26 | + libraryRoot: fs.absolute( fs.workingDirectory + '' ), |
| 27 | + screenshotRoot: fs.absolute( fs.workingDirectory + outputDir + '/screenshots' ), |
| 28 | + failedComparisonsRoot: fs.absolute( fs.workingDirectory + outputDir + '/failures' ), |
| 29 | + addLabelToFailedImage: false, |
| 30 | + }); |
| 31 | + |
| 32 | + casper.on('remote.message', function(msg) {this.echo(msg);}); |
| 33 | + casper.on('error', function (err) {this.die( "PhantomJS has errored: " + err );}); |
| 34 | + casper.on('resource.error', function (err) {casper.log( 'Resource load error: ' + err, 'warning' );}); |
| 35 | + |
| 36 | + |
| 37 | + // start with a baseline image |
| 38 | + casper.start(); |
| 39 | + casper.viewport(1440, 900); |
| 40 | + casper.options.waitTimeout = 10000; // longer default timeout |
| 41 | + |
| 42 | + casper.each(urlFragments, function then(self, e) { |
| 43 | + // the TRICK is to first go to a different URL or else the app |
| 44 | + // doesn't recognize the URL hashstate change ... which is admittedly a |
| 45 | + // bug in OPT right now. but to work around it, simply open a |
| 46 | + // different URL between page loads: |
| 47 | + self.thenOpen('about:blank'); |
| 48 | + |
| 49 | + self.thenOpen(e, function() { |
| 50 | + phantomcss.screenshot('#pyInputPane', 'pageLoaded'); |
| 51 | + |
| 52 | + casper.wait(DELAY_MS, function() { |
| 53 | + this.click("#runAllTestsButton"); |
| 54 | + casper.wait(2000, function then() { |
| 55 | + phantomcss.screenshot('#pyInputPane', 'testsRun'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + casper.thenClick('#vizTestCase_3', function() { |
| 60 | + casper.waitFor(function check() { |
| 61 | + return this.evaluate(function() { |
| 62 | + return document.querySelectorAll("#dataViz").length > 0; |
| 63 | + }); |
| 64 | + }, function then() { |
| 65 | + phantomcss.screenshot('.visualizer', 'failingTest'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + }); |
| 71 | + |
| 72 | + |
| 73 | + // run all tests: |
| 74 | + casper.then(function now_check_the_screenshots() { |
| 75 | + phantomcss.compareAll(); // compare screenshots |
| 76 | + }); |
| 77 | + |
| 78 | + casper.run(function() { |
| 79 | + //phantomcss.getExitStatus() // pass or fail? |
| 80 | + casper.test.done(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments