Permalink
Browse files

updated samples/googletesting.{js|coffee}

  • Loading branch information...
1 parent 3da89c4 commit 783e7dfcf57fb2fec77cc6341a0767825b26fb33 @n1k0 n1k0 committed Dec 30, 2012
Showing with 45 additions and 18 deletions.
  1. +25 −14 samples/googletesting.coffee
  2. +20 −4 samples/googletesting.js
@@ -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
@@ -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() {

0 comments on commit 783e7df

Please sign in to comment.