updated tests regarding phantomjs version used
Showing
1 changed file
with
28 additions
and
23 deletions
... | @@ -2,66 +2,72 @@ | ... | @@ -2,66 +2,72 @@ |
2 | 2 | ||
3 | #jshint strict:false | 3 | #jshint strict:false |
4 | 4 | ||
5 | SERVER = 'http://localhost:54321/' | 5 | utils = require "utils" |
6 | ORIGINAL_URL = "tests/site/index.html" | ||
7 | CHANGED_URL = "tests/site/index.html?foo=bar" | ||
8 | 6 | ||
9 | setToTrueOnResourceRequested = false | 7 | if utils.ltVersion(phantom.version, '1.9.0') |
10 | setToTrueOnResourceReceived = false | 8 | casper.test.skip(6, 'PhantomJS version <1.9.0 does not implement request.abort()') |
11 | requestURLRequested = '' | 9 | casper.test.done() |
12 | requestURLReceived = '' | 10 | else |
11 | SERVER = 'http://localhost:54321/' | ||
12 | ORIGINAL_URL = "tests/site/index.html" | ||
13 | CHANGED_URL = "tests/site/index.html?foo=bar" | ||
13 | 14 | ||
14 | onResourceRequested = (casper, requestData, request) -> | 15 | setToTrueOnResourceRequested = false |
16 | setToTrueOnResourceReceived = false | ||
17 | requestURLRequested = '' | ||
18 | requestURLReceived = '' | ||
19 | |||
20 | onResourceRequested = (casper, requestData, request) -> | ||
15 | if requestData.url == (SERVER + ORIGINAL_URL) | 21 | if requestData.url == (SERVER + ORIGINAL_URL) |
16 | setToTrueOnResourceRequested = true | 22 | setToTrueOnResourceRequested = true |
17 | requestURLRequested = requestData.url | 23 | requestURLRequested = requestData.url |
18 | 24 | ||
19 | onResourceRequestedWithAbort = (casper, requestData, request) -> | 25 | onResourceRequestedWithAbort = (casper, requestData, request) -> |
20 | if requestData.url == (SERVER + ORIGINAL_URL) | 26 | if requestData.url == (SERVER + ORIGINAL_URL) |
21 | request.abort() | 27 | request.abort() |
22 | 28 | ||
23 | onResourceRequestedWithChangeURL = (casper, requestData, request) -> | 29 | onResourceRequestedWithChangeURL = (casper, requestData, request) -> |
24 | if requestData.url == (SERVER + ORIGINAL_URL) | 30 | if requestData.url == (SERVER + ORIGINAL_URL) |
25 | request.changeUrl(SERVER + CHANGED_URL) | 31 | request.changeUrl(SERVER + CHANGED_URL) |
26 | 32 | ||
27 | onResourceReceived = (casper, response) -> | 33 | onResourceReceived = (casper, response) -> |
28 | if response.url == (SERVER + ORIGINAL_URL) | 34 | if response.url == (SERVER + ORIGINAL_URL) |
29 | setToTrueOnResourceReceived = true | 35 | setToTrueOnResourceReceived = true |
30 | requestURLReceived = response.url | 36 | requestURLReceived = response.url |
31 | 37 | ||
32 | onResourceReceivedWithChangeURL = (casper, response) -> | 38 | onResourceReceivedWithChangeURL = (casper, response) -> |
33 | if response.url == (SERVER + CHANGED_URL) | 39 | if response.url == (SERVER + CHANGED_URL) |
34 | requestURLReceived = response.url | 40 | requestURLReceived = response.url |
35 | 41 | ||
36 | setUp = (test) -> | 42 | setUp = (test) -> |
37 | casper.options.onResourceRequested = onResourceRequested | 43 | casper.options.onResourceRequested = onResourceRequested |
38 | casper.options.onResourceReceived = onResourceReceived | 44 | casper.options.onResourceReceived = onResourceReceived |
39 | casper.start() | 45 | casper.start() |
40 | 46 | ||
41 | setUpWithAbort = (test) -> | 47 | setUpWithAbort = (test) -> |
42 | casper.options.onResourceRequested = onResourceRequestedWithAbort | 48 | casper.options.onResourceRequested = onResourceRequestedWithAbort |
43 | casper.options.onResourceReceived = onResourceReceived | 49 | casper.options.onResourceReceived = onResourceReceived |
44 | casper.start() | 50 | casper.start() |
45 | 51 | ||
46 | setUpWithChangeURL = (test) -> | 52 | setUpWithChangeURL = (test) -> |
47 | casper.options.onResourceRequested = onResourceRequestedWithChangeURL | 53 | casper.options.onResourceRequested = onResourceRequestedWithChangeURL |
48 | casper.options.onResourceReceived = onResourceReceivedWithChangeURL | 54 | casper.options.onResourceReceived = onResourceReceivedWithChangeURL |
49 | casper.start() | 55 | casper.start() |
50 | 56 | ||
51 | tearDown = (test) -> | 57 | tearDown = (test) -> |
52 | setToTrueOnResourceRequested = false | 58 | setToTrueOnResourceRequested = false |
53 | setToTrueOnResourceReceived = false | 59 | setToTrueOnResourceReceived = false |
54 | casper.options.onResourceRequested = null | 60 | casper.options.onResourceRequested = null |
55 | casper.options.onResourceReceived = null | 61 | casper.options.onResourceReceived = null |
56 | 62 | ||
57 | 63 | ||
58 | casper.test.begin "onResourceRequested tests without abort/override", 4, | 64 | casper.test.begin "onResourceRequested tests without abort/override", 4, |
59 | setUp: setUp | 65 | setUp: setUp |
60 | tearDown: tearDown | 66 | tearDown: tearDown |
61 | test: (test) -> | 67 | test: (test) -> |
62 | casper.open(ORIGINAL_URL).then -> | 68 | casper.open(ORIGINAL_URL).then -> |
63 | 69 | ||
64 | casper.wait 3000, -> | 70 | casper.wait 200, -> |
65 | test.assertEquals setToTrueOnResourceRequested, true, "Casper.options.onResourceRequested called successfully" | 71 | test.assertEquals setToTrueOnResourceRequested, true, "Casper.options.onResourceRequested called successfully" |
66 | test.assertEquals requestURLRequested, SERVER+ORIGINAL_URL, "request url successfully recorded" | 72 | test.assertEquals requestURLRequested, SERVER+ORIGINAL_URL, "request url successfully recorded" |
67 | test.assertEquals setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived called successfully" | 73 | test.assertEquals setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived called successfully" |
... | @@ -71,28 +77,27 @@ casper.test.begin "onResourceRequested tests without abort/override", 4, | ... | @@ -71,28 +77,27 @@ casper.test.begin "onResourceRequested tests without abort/override", 4, |
71 | test.done() | 77 | test.done() |
72 | 78 | ||
73 | 79 | ||
74 | casper.test.begin "onResourceRequested tests with request.abort()", 1, | 80 | casper.test.begin "onResourceRequested tests with request.abort()", 1, |
75 | setUp: setUpWithAbort | 81 | setUp: setUpWithAbort |
76 | tearDown: tearDown | 82 | tearDown: tearDown |
77 | test: (test) -> | 83 | test: (test) -> |
78 | casper.open(ORIGINAL_URL).then -> | 84 | casper.open(ORIGINAL_URL).then -> |
79 | 85 | ||
80 | casper.wait 3000, -> | 86 | casper.wait 200, -> |
81 | test.assertNotEquals setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived correctly never called" | 87 | test.assertNotEquals setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived correctly never called" |
82 | 88 | ||
83 | casper.run -> | 89 | casper.run -> |
84 | test.done() | 90 | test.done() |
85 | 91 | ||
86 | 92 | ||
87 | casper.test.begin "onResourceRequested tests with request.changeUrl()", 1, | 93 | casper.test.begin "onResourceRequested tests with request.changeUrl()", 1, |
88 | setUp: setUpWithChangeURL | 94 | setUp: setUpWithChangeURL |
89 | tearDown: tearDown | 95 | tearDown: tearDown |
90 | test: (test) -> | 96 | test: (test) -> |
91 | casper.open(ORIGINAL_URL).then -> | 97 | casper.open(ORIGINAL_URL).then -> |
92 | 98 | ||
93 | casper.wait 3000, -> | 99 | casper.wait 200, -> |
94 | test.assertEquals requestURLReceived, SERVER+CHANGED_URL, "response url successfully changed" | 100 | test.assertEquals requestURLReceived, SERVER+CHANGED_URL, "response url successfully changed" |
95 | 101 | ||
96 | casper.run -> | 102 | casper.run -> |
97 | test.done() | 103 | test.done() |
98 | ... | ... |
-
Please register or sign in to post a comment