Commit 783e7dfc 783e7dfcf57fb2fec77cc6341a0767825b26fb33 by Nicolas Perriault

updated samples/googletesting.{js|coffee}

1 parent 3da89c4f
1 casper = require("casper").create 1 # Google sample testing.
2 logLevel: "debug" 2 #
3 3 # Usage:
4 casper.start "http://www.google.fr/", -> 4 # $ casperjs test googletesting.coffee
5 @test.assertTitle "Google", "google homepage title is the one expected" 5 casper.test.begin 'Google search retrieves 10 or more results', 5, (test) ->
6 @test.assertExists 'form[action="/search"]', "main form is found" 6 casper.start "http://www.google.fr/", ->
7 test.assertTitle "Google", "google homepage title is the one expected"
8 test.assertExists 'form[action="/search"]', "main form is found"
7 @fill 'form[action="/search"]', q: "foo", true 9 @fill 'form[action="/search"]', q: "foo", true
8 10
9 casper.then -> 11 casper.then ->
10 @test.assertTitle "foo - Recherche Google", "google title is ok" 12 test.assertTitle "foo - Recherche Google", "google title is ok"
11 @test.assertUrlMatch /q=foo/, "search term has been submitted" 13 test.assertUrlMatch /q=foo/, "search term has been submitted"
12 @test.assertEval (-> 14 test.assertEval (->
13 __utils__.findAll("h3.r").length >= 10 15 __utils__.findAll("h3.r").length >= 10
14 ), "google search for \"foo\" retrieves 10 or more results" 16 ), "google search for \"foo\" retrieves 10 or more results"
15 17
16 casper.run -> 18 casper.run -> test.done()
17 @test.renderResults true 19
20 casper.test.begin "Casperjs.org is first ranked", 1, (test) ->
21 casper.start "http://www.google.fr/", ->
22 @fill "form[action=\"/search\"]", q: "casperjs", true
23
24 casper.then ->
25 test.assertSelectorContains ".g", "casperjs.org", "casperjs.org is first ranked"
26
27 casper.run -> test.done()
28
......
...@@ -12,16 +12,32 @@ casper.test.begin('Google search retrieves 10 or more results', 5, function suit ...@@ -12,16 +12,32 @@ casper.test.begin('Google search retrieves 10 or more results', 5, function suit
12 test.assertTitle("Google", "google homepage title is the one expected"); 12 test.assertTitle("Google", "google homepage title is the one expected");
13 test.assertExists('form[action="/search"]', "main form is found"); 13 test.assertExists('form[action="/search"]', "main form is found");
14 this.fill('form[action="/search"]', { 14 this.fill('form[action="/search"]', {
15 q: "foo" 15 q: "casperjs"
16 }, true); 16 }, true);
17 }); 17 });
18 18
19 casper.then(function() { 19 casper.then(function() {
20 test.assertTitle("!!foo - Recherche Google", "google title is ok"); 20 test.assertTitle("casperjs - Recherche Google", "google title is ok");
21 test.assertUrlMatch(/q=foo/, "search term has been submitted"); 21 test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
22 test.assertEval(function() { 22 test.assertEval(function() {
23 return __utils__.findAll("h3.r").length >= 10; 23 return __utils__.findAll("h3.r").length >= 10;
24 }, "google search for \"foo\" retrieves 10 or more results"); 24 }, "google search for \"casperjs\" retrieves 10 or more results");
25 });
26
27 casper.run(function() {
28 test.done();
29 });
30 });
31
32 casper.test.begin('Casperjs.org is first ranked', 1, function suite(test) {
33 casper.start("http://www.google.fr/", function() {
34 this.fill('form[action="/search"]', {
35 q: "casperjs"
36 }, true);
37 });
38
39 casper.then(function() {
40 test.assertSelectorContains(".g", "casperjs.org", "casperjs.org is first ranked");
25 }); 41 });
26 42
27 casper.run(function() { 43 casper.run(function() {
......