Commit 783e7dfc 783e7dfcf57fb2fec77cc6341a0767825b26fb33 by Nicolas Perriault

updated samples/googletesting.{js|coffee}

1 parent 3da89c4f
casper = require("casper").create
logLevel: "debug"
casper.start "http://www.google.fr/", ->
@test.assertTitle "Google", "google homepage title is the one expected"
@test.assertExists 'form[action="/search"]', "main form is found"
# Google sample testing.
#
# Usage:
# $ casperjs test googletesting.coffee
casper.test.begin 'Google search retrieves 10 or more results', 5, (test) ->
casper.start "http://www.google.fr/", ->
test.assertTitle "Google", "google homepage title is the one expected"
test.assertExists 'form[action="/search"]', "main form is found"
@fill 'form[action="/search"]', q: "foo", true
casper.then ->
@test.assertTitle "foo - Recherche Google", "google title is ok"
@test.assertUrlMatch /q=foo/, "search term has been submitted"
@test.assertEval (->
casper.then ->
test.assertTitle "foo - Recherche Google", "google title is ok"
test.assertUrlMatch /q=foo/, "search term has been submitted"
test.assertEval (->
__utils__.findAll("h3.r").length >= 10
), "google search for \"foo\" retrieves 10 or more results"
casper.run ->
@test.renderResults true
casper.run -> test.done()
casper.test.begin "Casperjs.org is first ranked", 1, (test) ->
casper.start "http://www.google.fr/", ->
@fill "form[action=\"/search\"]", q: "casperjs", true
casper.then ->
test.assertSelectorContains ".g", "casperjs.org", "casperjs.org is first ranked"
casper.run -> test.done()
......
......@@ -12,16 +12,32 @@ casper.test.begin('Google search retrieves 10 or more results', 5, function suit
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "foo"
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertTitle("!!foo - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=foo/, "search term has been submitted");
test.assertTitle("casperjs - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
test.assertEval(function() {
return __utils__.findAll("h3.r").length >= 10;
}, "google search for \"foo\" retrieves 10 or more results");
}, "google search for \"casperjs\" retrieves 10 or more results");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casperjs.org is first ranked', 1, function suite(test) {
casper.start("http://www.google.fr/", function() {
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertSelectorContains(".g", "casperjs.org", "casperjs.org is first ranked");
});
casper.run(function() {
......