Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed some buggy methods

added some unit tests
converting some scripts to unit
using run_single_test.sh
updating documentation
  • Loading branch information...
commit 5cd45f2473ebce9c97fa9b5e493cc376ee3b06ce 1 parent 14c8d76
jlbfalcao authored
View
26 README.rdoc
@@ -27,35 +27,39 @@ Please, take a look at "/test" files.
===Simple
- appfeedgrid = Ext::find(:xtype => "appfeedgrid")
+ @selenium = [..your selenium object..]
- button = Ext::find(:xtype => "button", :text => 'Open All', :xparent => appfeedgrid)
+ appfeedgrid = @selenium.find_ext(:xtype => "appfeedgrid")
+
+ button = @selenium.find_ext(:xtype => "button", :text => 'Open All', :xparent => appfeedgrid)
+
# click method wait for any request complete
button.click
=== Working with Form
# search for form.
- form = Ext::find(:xtype => "form", :title_has => 'Simple')
+ form = @selenium.find_ext(:xtype => "form", :title_has => 'Simple')
+
+ form.field[:email].value = "NotAEmail"
- # change every field at form.
- form.fields.each do |name, field|
- p field.value = "Loren Ipsun"
- end
+ # convert to "isValid" and run at client.
+ assert_false form.field[:email].valid?
- p form.fields[:email].has_error?
form.fields[:email].value = 'myemail@domain.br'
- p form.fields[:email].has_error?
+
+ assert_true form.field[:email].valid?
+
=== Working with Grid and Ajax Content.
# :wait blocks test, waiting for window
- window = Ext::find(:xtype => 'window', :wait => true, :title => 'Store Load Callback')
+ window = @selenium.find_ext(:xtype => 'window', :wait => true, :title => 'Store Load Callback')
# close the window
window.close
# search for editorgrid component.
- editorgrid = Ext::find(:xtype => "editorgrid")
+ editorgrid = @selenium.find(:xtype => "editorgrid")
# number of lines
print editorgrid.num_rows()
View
1  Rakefile
@@ -14,6 +14,7 @@ require 'selenium-extjs'
desc 'Test Selenium-ExtJS.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
+ t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
View
44 lib/selenium-extjs/Ext.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'selenium/client'
-require 'selenium-extjs/Selenium'
+# require 'selenium-extjs/Selenium'
require 'selenium-extjs/component/Component'
require 'selenium-extjs/component/Button'
require 'selenium-extjs/component/Field'
@@ -9,6 +9,7 @@
require 'selenium-extjs/component/Grid'
require 'selenium-extjs/component/Panel'
require 'selenium-extjs/component/Window'
+require 'json'
module Ext
@@ -19,7 +20,46 @@ def self.reg(xtype, cls)
def self.create(xtype, id, parent, selenium)
Ext::ComponentMgr.create(xtype, cls)
end
-
+
+ # build arguments list.
+ def self.arguments(args)
+ if args.is_a? Array
+ return args.to_json[1..-2] || ""
+ else
+ return args.to_json
+ end
+ end
+
+ def self.build_remote_call(id, method_name, arguments)
+ code = []
+ code << "(function(_) {"
+ code << " var r;"
+ code << " if (typeof _.#{method_name} == 'function') {"
+ code << " r = _.#{method_name}(#{arguments});"
+ code << " } else {"
+ code << " r = _.#{method_name};"
+ code << " }"
+ code << " if (typeof r.getId == 'function') {" # return hash map
+ code << " return Ext.util.JSON.encode({\"id\":r.getId()});"
+ code << " } else {"
+ code << " return r;"
+ code << " }"
+ code << "}(window.Ext.getCmp('#{id}'));"
+ (code.collect {|t| t.strip }).join
+ end
+
+ # convert some ruby-style methods to ext-style
+ def self.extfy(method_name)
+ if method_name.end_with? '?'
+ method_name = "is_" + method_name
+ method_name.chop!
+ end
+ tokens = method_name.split("_")
+ tmp = tokens.shift
+ tokens.collect! {|t| t.capitalize }
+ tokens.unshift tmp
+ return tokens.join
+ end
class ComponentMgr
@@all = {}
View
55 lib/selenium-extjs/component/Component.rb
@@ -1,4 +1,6 @@
+require 'json'
+
module Ext
class Component
attr_accessor :parent
@@ -18,55 +20,36 @@ def init_component()
# obj.items_component_array -> serializar o retorno em uma lista
# tratar obj.store
+ def method_missing(method_name, *args, &block)
- def method_missing(m, *args, &block)
- prefix = "window.Ext.getCmp('#{@id}')"
+ #
+ cmp = "window.Ext.getCmp('#{@id}')"
# TODO: unit for validate this :p
# registered?
# is_registered
# isRegistered()
- m = m.to_s
-
- if m.end_with? "?"
- m.chop!
- m = "is_" + m
- end
if m.end_with? "="
- m.chop!
- m = "get_" + m
+ # set value?
end
+
+ # convert method name to ext model.
+ method_name = Ext::extfy(method_name.to_s)
- tokens = m.split("_")
- if ( tokens.length > 1 )
- new_name = tokens.shift()
- new_name += tokens.map{|c| c.capitalize() }.join("")
- else
- new_name = m
- end
+ # build js arguments list
+ arguments = Ext::arguments(args)
- #TODO: tratar o erro e verificar se o method existe
- cmd = "(function(_s) { if(typeof _s.#{new_name} == 'function') { return _s.#{new_name}("
- args.each do |p|
- if p.is_a? String
- cmd += "'#{p}',"
- elsif p.is_a? Fixnum
- cmd += "#{p},"
+ # move to selenium.
+ cmd = Ext::build_remote_call(@id, method_name, arguments)
+ ret = @selenium.get_eval(cmd)
+
+ if ret.is_a? Hash
+ if ret.has_key? 'id'
+ return @selenium.get_cmp(id, nil)
else
- cmd += "#{p},"
+ return ret
end
- end
- cmd.chop! if cmd.end_with? ","
- cmd += "); } else { return _s.#{new_name}; }})(#{prefix})"
-
- new_cmd = "(function(_obj) { return (_obj.getId)?('\@ID:'+_obj.getId()):_obj; })(#{cmd});";
-
- ret = @selenium.get_eval(new_cmd);
-
- if ret.start_with? "@ID:"
- id = ret.split(":")[1]
- @selenium.get_cmp(id, nil)
else
return ret
end
View
3  run_single_test.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+testrb -I test/:lib/ $1
View
2  selenium-extjs.gemspec
@@ -4,6 +4,8 @@ Gem::Specification.new do |s|
s.name = %q{selenium-extjs}
s.version = "0.0.1"
+ # dependency: json
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ronald Andreu Kaiser"]
s.date = %q{2009-11-12}
View
42 test/edit_grid_test.rb
@@ -0,0 +1,42 @@
+
+require 'test/unit'
+require 'selenium-extjs'
+require 'setup'
+
+class EditGridTest < Test::Unit::TestCase
+
+ include Setup
+
+ def test_grid
+ # TODO: add aserts.
+ @s.open 'deploy/dev/examples/grid/edit-grid.html'
+
+ # wait for window.
+ window = @s.find_ext(:xtype => 'window', :wait => true, :title => 'Store Load Callback')
+
+ assert_equal window.class, Ext::Window
+
+ # close the window
+ window.close
+
+ # search for editorgrid component.
+ editorgrid = @s.find_ext(:xtype => "editorgrid")
+
+ # number of lines (on store?)
+ print editorgrid.num_rows()
+
+ # set row 1 with data
+ editorgrid.edit_row(1, ["Jorge", "Shade", "10.10", "24/03/06", true]);
+
+ # get row
+ print editorgrid.get_row(3)
+
+ # clica at cell x,y
+ editorgrid.click_at_cell(2, 5)
+ sleep 10
+ end
+
+ def test_add_plant
+ end
+
+end
View
69 test/form_test.rb
@@ -1,52 +1,51 @@
-require "rubygems"
-require "selenium/client"
-
-$LOAD_PATH.unshift("../lib")
+require 'test/unit'
require 'selenium-extjs'
+require 'setup'
+class FormTest < Test::Unit::TestCase
-begin
- s = Ext::Selenium.new \
- :host => "localhost",
- :port => 4444,
- :browser => "*firefox",
- :url => "http://www.extjs.com/",
- :timeout_in_second => 60
+ include Setup
- s.start_new_browser_session
- s.open 'deploy/dev/examples/form/dynamic.html'
+ def test_very_simple_form
- # search for editorgrid component.
- form = s.find_ext(:xtype => "form", :title_has => 'Simple')
-
- form.fields.each do |name, field|
- p name
- p field.value
- p field.value = "Loren Ipsun"
+ @s.open 'deploy/dev/examples/form/dynamic.html'
+
+ # search for editorgrid component.
+ form = $s.find_ext(:xtype => "form", :title_has => 'Simple')
+ form.fields.each do |name, field|
+ p name
+ p field.value
+ p field.value = "Loren Ipsun"
+ end
+ assert_false form.fields[:email].valid?
+ form.fields[:email].value = 'myemail@domain.br'
+ end
+
+ def test_adding_fieldsets
+ assert_true form.fields[:email].valid?
+
+ # search for editorgrid component.
+ form = $s.find_ext(:xtype => "form", :title_has => 'FieldSet')
+
+ form.fields.each do |name, field|
+ p name
+ p field.value
+ end
end
- p form.fields[:email].valid?
-
- form.fields[:email].value = 'myemail@domain.br'
- p form.fields[:email].valid?
-
+ def test_a_little_complex
+
+ end
- # search for editorgrid component.
- form = s.find_ext(:xtype => "form", :title_has => 'FieldSet')
+ def test_form_as_a_tab_panel
+ end
- form.fields.each do |name, field|
- p name
- p field.value
+ def test_form_with_tab_panel
end
- sleep 10
-
-ensure
- s.close_current_browser_session
end
-
View
43 test/functions_test.rb
@@ -0,0 +1,43 @@
+
+require 'test/unit'
+
+$LOAD_PATH.unshift("../lib")
+
+require 'selenium-extjs'
+
+class FunctionTest < Test::Unit::TestCase
+
+ def test_for_underscore_method
+ assert_equal Ext::extfy("get_cmp"), "getCmp"
+ assert_equal Ext::extfy("get_foo_bar"), "getFooBar"
+ end
+
+ def test_for_normal_method
+ assert_equal Ext::extfy("getCmp"), "getCmp"
+ assert_equal Ext::extfy("getSomeMethod"), "getSomeMethod"
+ assert_equal Ext::extfy("method"), "method"
+ end
+
+ def test_for_boolean_method
+ assert_equal Ext::extfy("valid?"), "isValid"
+ end
+
+ def test_arguments_convertion
+ assert_equal Ext::arguments([1,'foo', true, 0.0]), '1,"foo",true,0.0'
+ #emprt
+ assert_equal Ext::arguments([]), ''
+ # arrays
+ assert_equal Ext::arguments([[1,2,3,4]]), '[1,2,3,4]'
+ # simple elements
+ assert_equal Ext::arguments("string"), '"string"'
+ assert_equal Ext::arguments(1), '1'
+ assert_equal Ext::arguments(true), 'true'
+
+ end
+
+ # def test_call_method
+ # Ext::build_remote_call(1, "foo", [1,2,3,4])
+ # end
+
+
+end
View
51 test/grid_test.rb
@@ -1,51 +0,0 @@
-
-require "rubygems"
-require "selenium/client"
-
-$LOAD_PATH.unshift("../lib")
-require 'selenium-extjs'
-
-begin
-
- s = Ext::Selenium.new \
- :host => "localhost",
- :port => 4444,
- :browser => "*firefox",
- :url => "http://www.extjs.com/",
- :timeout_in_second => 60
-
- s.start_new_browser_session
- s.open 'deploy/dev/examples/grid/edit-grid.html'
-
- # wait for window.
- window = s.find_ext(:xtype => 'window', :wait => true, :title => 'Store Load Callback')
- # close the window
- window.close
-
-
- # search for editorgrid component.
- editorgrid = s.find_ext(:xtype => "editorgrid")
-
- # number of lines (on store?)
- print editorgrid.num_rows()
-
- # set row 1 with data
- editorgrid.edit_row(1, ["Jorge", "Shade", "10.10", "24/03/06", true]);
-
- # get row
- print editorgrid.get_row(3)
-
-
- # clica at cell x,y
- editorgrid.click_at_cell(2, 5)
-
- sleep 10
-
-ensure
- s.close_current_browser_session
-end
-
-
-
-
-
View
26 test/setup.rb
@@ -0,0 +1,26 @@
+
+require "rubygems"
+require "selenium/client"
+
+$LOAD_PATH.unshift("../lib")
+require 'selenium-extjs'
+
+module Setup
+ def setup()
+ @s = Ext::Selenium.new \
+ :host => "localhost",
+ :port => 4444,
+ :browser => "*firefox",
+ :url => "http://www.extjs.com/",
+ :timeout_in_second => 60
+ @s.start_new_browser_session
+ end
+
+ def teardown()
+ @s.close_current_browser_session
+ end
+end
+
+
+
+
View
40 test/simple_test.rb
@@ -1,27 +1,23 @@
-require "rubygems"
-require "selenium/client"
-
-$LOAD_PATH.unshift("../lib")
+require 'test/unit'
require 'selenium-extjs'
-
-begin
- s = Ext::Selenium.new \
- :host => "localhost",
- :port => 4444,
- :browser => "*firefox",
- :url => "http://www.extjs.com/",
- :timeout_in_second => 60
-
- s.start_new_browser_session
- s.open 'deploy/dev/examples/feed-viewer/view.html'
- appfeedgrid = s.find_ext(:xtype => "appfeedgrid")
-
- appfeedgrid.highlight
- sleep 5
-
- button = s.find_ext(:xtype => "button", :text => 'Open All', :xparent => appfeedgrid)
- button.click
+require 'setup'
+
+class SimpleTest < Test::Unit::TestCase
+
+ include Setup
+
+ def test_simple
+
+ @s.open 'deploy/dev/examples/feed-viewer/view.html'
+ appfeedgrid = @s.find_ext(:xtype => "appfeedgrid")
+
+ appfeedgrid.highlight
+ sleep 5
+
+ button = @s.find_ext(:xtype => "button", :text => 'Open All', :xparent => appfeedgrid)
+ button.click
+ end
end
View
39 test/tab_test.rb
@@ -1,39 +1,28 @@
-require "rubygems"
-require "selenium/client"
-
-$LOAD_PATH.unshift("../lib")
+require 'test/unit'
require 'selenium-extjs'
+require 'setup'
-begin
- s = Ext::Selenium.new \
- :host => "localhost",
- :port => 4444,
- :browser => "*firefox",
- :url => "http://www.extjs.com/",
- :timeout_in_second => 60
+class TabTest < Test::Unit::TestCase
- s.start_new_browser_session
- s.open 'deploy/dev/examples/tabs/tabs.html'
+ include Setup
- tabpanel = s.find_ext(:xtype => "tabpanel")
+ def test_active_panel
-
- p "active panel:" + tabpanel.getActiveTab().title
+ s.open 'deploy/dev/examples/tabs/tabs.html'
- # work with position
- p tabpanel.active_tab = 2
+ tabpanel = s.find_ext(:xtype => "tabpanel")
- p tabpanel.getActiveTab().title
- p tabpanel.getActiveTab().title == "Long Text"
-
- sleep 10
+ assert_equal tabpanel.class, TabPanel
-ensure
- s.close_current_browser_session
-end
+ assert_equal tabpanel.getActiveTab().title, "Short Text"
+ tabpanel.active_tab = 2
+
+ assert_equal tabpanel.getActiveTab().title, "Long Text"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.