Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
updated samples/googletesting.{js|coffee}
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Dec 30, 2012
1 parent 3da89c4 commit 783e7df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
39 changes: 25 additions & 14 deletions samples/googletesting.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
casper = require("casper").create
logLevel: "debug"
# 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.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 (->
__utils__.findAll("h3.r").length >= 10
), "google search for \"foo\" retrieves 10 or more results"

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.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()

casper.run ->
@test.renderResults true
24 changes: 20 additions & 4 deletions samples/googletesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 783e7df

Please sign in to comment.