This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed obsolete isolation tricks from test suite
- Loading branch information
Showing
28 changed files
with
725 additions
and
769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
*.xml | ||
*.png | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
(function(t) { | ||
var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png'; | ||
var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png'; | ||
|
||
if (fs.exists(testFile) && fs.isFile(testFile)) { | ||
fs.remove(testFile); | ||
} | ||
if (fs.exists(testFile) && fs.isFile(testFile)) { | ||
fs.remove(testFile); | ||
} | ||
|
||
casper.start('tests/site/index.html', function(self) { | ||
self.viewport(300, 200); | ||
t.comment('Casper.capture()'); | ||
self.capture(testFile); | ||
t.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); | ||
}); | ||
casper.start('tests/site/index.html', function(self) { | ||
self.viewport(300, 200); | ||
this.test.comment('Casper.capture()'); | ||
self.capture(testFile); | ||
this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); | ||
}); | ||
|
||
try { | ||
fs.remove(testFile); | ||
} catch(e) {} | ||
try { | ||
fs.remove(testFile); | ||
} catch(e) {} | ||
|
||
casper.run(function(self) { | ||
t.done(); | ||
}); | ||
})(casper.test); | ||
casper.run(function(self) { | ||
this.test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
(function(t) { | ||
casper.start('tests/site/index.html', function() { | ||
this.click('a[href="test.html"]'); | ||
}); | ||
casper.start('tests/site/index.html', function() { | ||
this.click('a[href="test.html"]'); | ||
}); | ||
|
||
casper.then(function() { | ||
t.comment('Casper.click()'); | ||
t.assertTitle('CasperJS test target', 'Casper.click() can click on a link'); | ||
}).thenClick('a', function() { | ||
t.comment('Casper.thenClick()'); | ||
t.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link'); | ||
}); | ||
casper.then(function() { | ||
this.test.comment('Casper.click()'); | ||
this.test.assertTitle('CasperJS test target', 'Casper.click() can click on a link'); | ||
}).thenClick('a', function() { | ||
this.test.comment('Casper.thenClick()'); | ||
this.test.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link'); | ||
}); | ||
|
||
// onclick variants tests | ||
casper.thenOpen('tests/site/click.html', function() { | ||
t.comment('CasperUtils.click()'); | ||
this.test.assert(this.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link'); | ||
this.test.assert(this.click('#test2'), 'CasperUtils.click() can click an `href="#"` link'); | ||
this.test.assert(this.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link'); | ||
this.test.assert(this.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link'); | ||
var results = this.getGlobal('results'); | ||
this.test.assert(results.test1, 'CasperUtils.click() has clicked an `href="javascript:` link'); | ||
this.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link'); | ||
this.test.assert(results.test3, 'CasperUtils.click() has clicked an `onclick=".*; return false"` link'); | ||
this.test.assert(results.test4, 'CasperUtils.click() has clicked an unobstrusive js handled link'); | ||
}); | ||
// onclick variants tests | ||
casper.thenOpen('tests/site/click.html', function() { | ||
this.test.comment('CasperUtils.click()'); | ||
this.test.assert(this.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link'); | ||
this.test.assert(this.click('#test2'), 'CasperUtils.click() can click an `href="#"` link'); | ||
this.test.assert(this.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link'); | ||
this.test.assert(this.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link'); | ||
var results = this.getGlobal('results'); | ||
this.test.assert(results.test1, 'CasperUtils.click() has clicked an `href="javascript:` link'); | ||
this.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link'); | ||
this.test.assert(results.test3, 'CasperUtils.click() has clicked an `onclick=".*; return false"` link'); | ||
this.test.assert(results.test4, 'CasperUtils.click() has clicked an unobstrusive js handled link'); | ||
}); | ||
|
||
// casper.mouse | ||
casper.then(function() { | ||
t.comment('Mouse.down()'); | ||
this.mouse.down(200, 100); | ||
var results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position'); | ||
// casper.mouse | ||
casper.then(function() { | ||
this.test.comment('Mouse.down()'); | ||
this.mouse.down(200, 100); | ||
var results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position'); | ||
|
||
t.comment('Mouse.up()'); | ||
this.mouse.up(200, 100); | ||
results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position'); | ||
this.test.comment('Mouse.up()'); | ||
this.mouse.up(200, 100); | ||
results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position'); | ||
|
||
t.comment('Mouse.move()'); | ||
this.mouse.move(200, 100); | ||
results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position'); | ||
}); | ||
this.test.comment('Mouse.move()'); | ||
this.mouse.move(200, 100); | ||
results = this.getGlobal('results'); | ||
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position'); | ||
}); | ||
|
||
casper.run(function() { | ||
t.done(); | ||
}); | ||
})(casper.test); | ||
casper.run(function() { | ||
this.test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
(function(t) { | ||
t.comment('ClientUtils.encode()'); | ||
var fs = require('fs'); | ||
var clientutils = require('clientutils').create(); | ||
var testCases = { | ||
'an empty string': '', | ||
'a word': 'plop', | ||
'a null char': 'a\u0000', | ||
'an utf8 string': 'ÀÁÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', | ||
'song lyrics': ("Voilà l'été, j'aperçois le soleil\n" + | ||
"Les nuages filent et le ciel s'éclaircit\n" + | ||
"Et dans ma tête qui bourdonnent?\n" + | ||
"Les abeilles!"), | ||
'a file contents': fs.read(phantom.casperPath + '/tests/site/alert.html') | ||
}; | ||
|
||
var fs = require('fs'); | ||
var clientutils = require('clientutils').create(); | ||
var testCases = { | ||
'an empty string': '', | ||
'a word': 'plop', | ||
'a null char': 'a\u0000', | ||
'an utf8 string': 'ÀÁÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', | ||
'song lyrics': ("Voilà l'été, j'aperçois le soleil\n" + | ||
"Les nuages filent et le ciel s'éclaircit\n" + | ||
"Et dans ma tête qui bourdonnent?\n" + | ||
"Les abeilles!"), | ||
'a file contents': fs.read(phantom.casperPath + '/tests/site/alert.html') | ||
}; | ||
casper.test.comment('ClientUtils.encode()'); | ||
|
||
for (var what in testCases) { | ||
var source = testCases[what]; | ||
var encoded = clientutils.encode(source); | ||
t.assertEquals(clientutils.decode(encoded), source, 'ClientUtils can encode and decode ' + what); | ||
} | ||
for (var what in testCases) { | ||
var source = testCases[what]; | ||
var encoded = clientutils.encode(source); | ||
casper.test.assertEquals(clientutils.decode(encoded), source, 'ClientUtils can encode and decode ' + what); | ||
} | ||
|
||
t.done(); | ||
})(casper.test); | ||
casper.test.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
(function(t) { | ||
casper.start('tests/site/index.html', function(self) { | ||
var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png'; | ||
var image = self.base64encode(imageUrl); | ||
var fs = require('fs'); | ||
var fs = require('fs'); | ||
|
||
t.comment('Casper.base64encode()'); | ||
t.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents'); | ||
casper.start('tests/site/index.html', function() { | ||
var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png'; | ||
var image = this.base64encode(imageUrl); | ||
|
||
t.comment('Casper.download()'); | ||
self.download(imageUrl, 'logo.png'); | ||
t.assert(fs.exists('logo.png'), 'Casper.download() downloads a file'); | ||
if (fs.exists('logo.png')) { | ||
fs.remove('logo.png'); | ||
} | ||
}); | ||
this.test.comment('Casper.base64encode()'); | ||
this.test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents'); | ||
|
||
casper.run(function(self) { | ||
t.done(); | ||
}); | ||
})(casper.test); | ||
this.test.comment('Casper.download()'); | ||
this.download(imageUrl, 'logo.png'); | ||
this.test.assert(fs.exists('logo.png'), 'Casper.download() downloads a file'); | ||
if (fs.exists('logo.png')) { | ||
fs.remove('logo.png'); | ||
} | ||
}); | ||
|
||
casper.run(function() { | ||
this.test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
(function(t) { | ||
t.comment('Casper.evaluate()'); | ||
casper.test.comment('Casper.evaluate()'); | ||
|
||
casper.start(); | ||
casper.start(); | ||
|
||
var params = { | ||
"boolean true": true, | ||
"boolean false": false, | ||
"int number": 42, | ||
"float number": 1337.42, | ||
"string": "plop! \"Ÿ£$\" 'no'", | ||
"array": [1, 2, 3], | ||
"object": {a: 1, b: 2} | ||
}; | ||
var params = { | ||
"boolean true": true, | ||
"boolean false": false, | ||
"int number": 42, | ||
"float number": 1337.42, | ||
"string": "plop! \"Ÿ£$\" 'no'", | ||
"array": [1, 2, 3], | ||
"object": {a: 1, b: 2} | ||
}; | ||
|
||
var casperParams = casper.evaluate(function() { | ||
return __casper_params__; | ||
}, params); | ||
var casperParams = casper.evaluate(function() { | ||
return __casper_params__; | ||
}, params); | ||
|
||
casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object'); | ||
casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length'); | ||
casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object'); | ||
casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length'); | ||
|
||
for (var param in casperParams) { | ||
casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param); | ||
casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type'); | ||
} | ||
for (var param in casperParams) { | ||
casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param); | ||
casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type'); | ||
} | ||
|
||
t.done(); | ||
})(casper.test); | ||
casper.test.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
(function(t) { | ||
t.comment('Casper.exists()'); | ||
casper.test.comment('Casper.exists()'); | ||
|
||
casper.start('tests/site/index.html', function(self) { | ||
t.assert(self.exists('a') && !self.exists('chucknorriz'), 'Casper.exists() can check if an element exists'); | ||
}); | ||
casper.start('tests/site/index.html', function() { | ||
this.test.assert(this.exists('a') && !this.exists('chucknorriz'), 'Casper.exists() can check if an element exists'); | ||
}); | ||
|
||
casper.run(function(step) { | ||
t.done(); | ||
}); | ||
})(casper.test); | ||
casper.run(function() { | ||
this.test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
(function(t) { | ||
t.comment('Casper.fetchText()'); | ||
casper.test.comment('Casper.fetchText()'); | ||
|
||
casper.start('tests/site/index.html', function(self) { | ||
t.assertEquals(self.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents'); | ||
}); | ||
casper.start('tests/site/index.html', function() { | ||
this.test.assertEquals(this.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents'); | ||
}); | ||
|
||
casper.run(function() { | ||
t.done(); | ||
}); | ||
})(casper.test); | ||
casper.run(function() { | ||
this.test.done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
do(casper) -> | ||
step = 0 | ||
step = 0 | ||
|
||
# testing resources | ||
casper.start "tests/site/resources.html", -> | ||
@test.assertEquals ++step, 1, "step 1" | ||
@wait 400, -> | ||
@test.assertEquals ++step, 2, "step 1.1" | ||
# testing resources | ||
casper.start "tests/site/resources.html", -> | ||
@test.assertEquals ++step, 1, "step 1" | ||
@wait 400, -> | ||
@test.assertEquals ++step, 2, "step 1.1" | ||
@wait 200, -> | ||
@test.assertEquals ++step, 3, "step 1.1.1" | ||
@wait 200, -> | ||
@test.assertEquals ++step, 3, "step 1.1.1" | ||
@wait 200, -> | ||
@test.assertEquals ++step, 4, "step 1.1.1.1" | ||
@then -> | ||
@test.assertEquals ++step, 5, "step 1.1.2.1" | ||
@wait 400, -> | ||
@test.assertEquals ++step, 6, "step 1.2" | ||
@test.assertEquals ++step, 4, "step 1.1.1.1" | ||
@then -> | ||
@test.assertEquals ++step, 5, "step 1.1.2.1" | ||
@wait 400, -> | ||
@test.assertEquals ++step, 6, "step 1.2" | ||
|
||
casper.wait 200, -> | ||
@test.assertEquals ++step, 7, "step 2" | ||
casper.wait 200, -> | ||
@test.assertEquals ++step, 7, "step 2" | ||
|
||
casper.waitForSelector( | ||
'#noneExistingSelector' | ||
-> @test.fail "should run into timeout" | ||
-> @test.assertEquals ++step, 8, "step 3 sucessfully timed out" | ||
1000 | ||
) | ||
casper.then -> | ||
@test.assertEquals ++step, 9, "step 4" | ||
casper.waitForSelector( | ||
'#noneExistingSelector' | ||
-> @test.fail "should run into timeout" | ||
-> @test.assertEquals ++step, 8, "step 3 sucessfully timed out" | ||
1000 | ||
) | ||
casper.then -> | ||
@test.assertEquals ++step, 9, "step 4" | ||
@wait 300, -> | ||
@test.assertEquals ++step, 10, "step 4.1" | ||
@wait 300, -> | ||
@test.assertEquals ++step, 10, "step 4.1" | ||
@wait 300, -> | ||
@test.assertEquals ++step, 11, "step 4.1.1" | ||
@wait 100, -> | ||
@test.assertEquals ++step, 12, "step 5.2" | ||
@test.assertEquals ++step, 11, "step 4.1.1" | ||
@wait 100, -> | ||
@test.assertEquals ++step, 12, "step 5.2" | ||
|
||
casper.then -> | ||
@test.assertEquals ++step, 13, "last step" | ||
casper.then -> | ||
@test.assertEquals ++step, 13, "last step" | ||
|
||
casper.run(-> @test.done()) | ||
casper.run(-> @test.done()) |
Oops, something went wrong.