Browse code

Funkcionalne testy v CasperJS

Cinan Rakosnik authored on 31/03/2013 at 12:29:47
Showing 6 changed files
... ...
@@ -47,6 +47,8 @@ group :test do
47 47
 	gem "factory_girl_rails"
48 48
     gem 'guard-spork'
49 49
     gem 'spork'
50
+    gem "phantomjs-binaries"
51
+    gem "casperjs"
50 52
 end
51 53
 
52 54
 gem 'jquery-rails'
... ...
@@ -50,6 +50,7 @@ GEM
50 50
       rack-test (>= 0.5.4)
51 51
       selenium-webdriver (~> 2.0)
52 52
       xpath (~> 1.0.0)
53
+    casperjs (1.0.0)
53 54
     childprocess (0.3.8)
54 55
       ffi (~> 1.0, >= 1.0.11)
55 56
     chunky_png (1.2.7)
... ...
@@ -155,6 +156,8 @@ GEM
155 155
     nokogiri (1.5.6)
156 156
     normalize-rails (2.0.1)
157 157
     origin (1.0.11)
158
+    phantomjs-binaries (1.8.1.1)
159
+      sys-uname (= 0.9.0)
158 160
     polyglot (0.3.3)
159 161
     powerbar (1.0.11)
160 162
       ansi (~> 1.4.0)
... ...
@@ -224,6 +227,8 @@ GEM
224 224
       multi_json (~> 1.0)
225 225
       rack (~> 1.0)
226 226
       tilt (~> 1.1, != 1.3.0)
227
+    sys-uname (0.9.0)
228
+      ffi (>= 1.0.0)
227 229
     test-unit (2.5.4)
228 230
     thin (1.5.0)
229 231
       daemons (>= 1.0.9)
... ...
@@ -260,6 +265,7 @@ DEPENDENCIES
260 260
   binding_of_caller
261 261
   capistrano
262 262
   capybara
263
+  casperjs
263 264
   coffee-rails (~> 3.2.1)
264 265
   compass-rails
265 266
   factory_girl_rails
... ...
@@ -275,6 +281,7 @@ DEPENDENCIES
275 275
   minitest-reporters (>= 0.5.0)
276 276
   mongoid (~> 3.0.20)
277 277
   normalize-rails
278
+  phantomjs-binaries
278 279
   rails (~> 3.2.11)
279 280
   rails-backbone
280 281
   rspec-rails
281 282
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+CasperJS tests are run like this:
1
+ $ bundle exec casperjs spec/features/*.coffee
0 2
deleted file mode 100644
... ...
@@ -1,50 +0,0 @@
1
-require "spec_helper"
2
-
3
-describe "Chatting behaviour" do
4
-
5
-    #todo change subject in testing roster and chatting window
6
-	subject { page }
7
-
8
-	describe "should show account info" do
9
-		before { visit chat_path }
10
-
11
-		it { should have_selector('h1', text: 'Cinan Rakosnik') }
12
-		it { should have_selector('h2', text: 'frontend developer') }
13
-		it { should have_selector('h3', text: 'available') }
14
-	end
15
-
16
-	describe "should show contact list" do
17
-		before { visit chat_path }
18
-
19
-		it { should have_selector('h1', 'Friends') }
20
-
21
-		it { should have_selector('h1', 'John Savage') }
22
-		it { should have_selector('h1', 'Adam Wolsky') }
23
-    end
24
-
25
-    describe "should show tabbar" do
26
-        before { visit chat_path }
27
-
28
-        it { should have_selector(class: 'tabbar') }
29
-        it { should have_selector('h1', text: 'Adam and John', class: 'tab') }
30
-    end
31
-
32
-    describe "should a conversation" do
33
-        before { visit chat_path }
34
-
35
-        describe "show some messages" do
36
-            it { should have_selector('img') }
37
-            it { should have_selector(class: 'date') }
38
-            #todo should have a message text
39
-        end
40
-
41
-        describe "should show event dates" do
42
-            it { should have_selector(text: 'Monday 13.2.2013') }
43
-        end
44
-
45
-        describe "should allow write a new message" do
46
-            it { should have_selector('input', placeholder: 'Type your message here') }
47
-            it { should have_button('Send') }
48
-        end
49
-    end
50
-end
51 1
\ No newline at end of file
52 2
new file mode 100644
... ...
@@ -0,0 +1,60 @@
0
+casper = require('./spec/spec_helper.js').Fantomas
1
+
2
+casper.start('http://www.xmpp.dev/', ->
3
+  @login()
4
+)
5
+
6
+#Click on the first person from the inactive list
7
+casper.then(->
8
+  @test.assertNotExists('#js-active-friends ul', 'Active list doesn\'t exists')
9
+  inactiveListLengthBefore = @inactiveListLength()
10
+
11
+  @click('#js-inactive-friends ul li:nth-child(1)')
12
+  @echo 'Clicked on the first person in the inactive roster'
13
+
14
+  inactiveListLengthAfter = @inactiveListLength()
15
+
16
+  @test.assertExists('#conversation-js', 'Conversation window created')
17
+  @test.assertExists('#tabbar .tab.active', 'Created new tab in the tabbar')
18
+  @test.assert(inactiveListLengthBefore - 1 == inactiveListLengthAfter, 'User isn\'t in the inactive list')
19
+  @test.assertExists('#js-active-friends ul li', 'User is in the active list')
20
+)
21
+
22
+#Click on another person from the inactive list
23
+casper.then(->
24
+  inactiveListLengthBefore = @inactiveListLength()
25
+
26
+  @click('#js-inactive-friends ul li:nth-child(1)')
27
+  @echo 'Clicked on the first person in the inactive roster'
28
+
29
+  tabsLength = @tabsLength()
30
+
31
+  activeListLength = @activeListLength()
32
+
33
+  inactiveListLengthAfter = @inactiveListLength()
34
+
35
+  @test.assert(tabsLength == 2, 'Number of opened tabs')
36
+  @test.assert(activeListLength == 1, 'Length of the active list')
37
+  @test.assert(inactiveListLengthBefore == inactiveListLengthAfter, 'Users from the active and the inactive list swapped')
38
+)
39
+
40
+#Test tab closing behaviour
41
+casper.then(->
42
+  @click('#tabbar .tab.active .js-close')
43
+  @echo 'Closed active tab'
44
+
45
+  @test.assertExists('#tabbar .tab.active', 'There\'s another active tab')
46
+  @click('#tabbar .tab.active .js-close')
47
+  @echo 'Closed another active tab'
48
+
49
+  tabsLength = @tabsLength()
50
+  activeListLength = @activeListLength()
51
+
52
+  @test.assert(tabsLength == 0, 'No more tabs')
53
+  @test.assert(activeListLength == 0, 'Nobody in active list')
54
+)
55
+
56
+casper.run(->
57
+  @test.done()
58
+  @test.renderResults(true)
59
+)
0 60
\ No newline at end of file
1 61
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+casper = require('casper').create()
1
+
2
+casper.login = ->
3
+  @fill('form[action="/sessions"]', {
4
+    jid: 'testovaci1@jabbim.cz'
5
+    password: 'heslo'
6
+  }, true)
7
+
8
+  casper.echo 'Loading roster. This may take some time.'
9
+
10
+  casper.waitFor(->
11
+    #test
12
+    casper.evaluate(->
13
+      __utils__.findAll('#js-inactive-friends ul li').length >= 2
14
+    )
15
+  , ->
16
+    # on success
17
+    casper.echo('loaded roster')
18
+  , ->
19
+    # on timeout
20
+    casper.die('roster not loaded', 1)
21
+  )
22
+
23
+casper.inactiveListLength = ->
24
+  casper.evaluate(-> __utils__.findAll('#js-inactive-friends ul li').length)
25
+
26
+casper.activeListLength = ->
27
+  casper.evaluate(-> __utils__.findAll('#js-active-friends ul li').length)
28
+
29
+casper.tabsLength = ->
30
+  casper.evaluate(-> __utils__.findAll('#tabbar .tab').length)
31
+
32
+exports.Fantomas = casper
0 33
\ No newline at end of file