gxt-widgets 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +21 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +11 -0
  4. data/Rakefile +33 -0
  5. data/cucumber.yml +12 -0
  6. data/features/gxt_grid.feature +87 -0
  7. data/features/gxt_grid_with_grouping.feature +48 -0
  8. data/features/gxt_pager.feature +37 -0
  9. data/features/step_definitions/common_steps.rb +11 -0
  10. data/features/step_definitions/gxt_grid_steps.rb +131 -0
  11. data/features/step_definitions/gxt_grid_with_grouping_steps.rb +8 -0
  12. data/features/step_definitions/gxt_pager_steps.rb +32 -0
  13. data/features/support/env.rb +8 -0
  14. data/features/support/hooks.rb +7 -0
  15. data/features/support/pages/basic_grid_example.rb +9 -0
  16. data/features/support/pages/grouping_grid_example.rb +5 -0
  17. data/features/support/pages/gxt_examples_page.rb +9 -0
  18. data/features/support/pages/local_pagination_example.rb +6 -0
  19. data/features/support/persistent_browser.rb +20 -0
  20. data/gxt-widget.gemspec +31 -0
  21. data/lib/gxt-widgets.rb +15 -0
  22. data/lib/gxt-widgets/gxt_column_menu.rb +11 -0
  23. data/lib/gxt-widgets/gxt_column_selection_menu.rb +7 -0
  24. data/lib/gxt-widgets/gxt_grid.rb +34 -0
  25. data/lib/gxt-widgets/gxt_grid_header_row.rb +23 -0
  26. data/lib/gxt-widgets/gxt_grid_row.rb +31 -0
  27. data/lib/gxt-widgets/gxt_header_cell.rb +15 -0
  28. data/lib/gxt-widgets/gxt_pager.rb +36 -0
  29. data/lib/gxt-widgets/modules/selectable_column.rb +13 -0
  30. data/lib/gxt-widgets/modules/sortable_column.rb +12 -0
  31. data/lib/gxt-widgets/platforms/selenium_webdriver/gxt_grid.rb +25 -0
  32. data/lib/gxt-widgets/platforms/selenium_webdriver/gxt_grid_header_row.rb +23 -0
  33. data/lib/gxt-widgets/platforms/selenium_webdriver/gxt_grid_row.rb +15 -0
  34. data/lib/gxt-widgets/platforms/watir_webdriver/gxt_grid.rb +35 -0
  35. data/lib/gxt-widgets/platforms/watir_webdriver/gxt_grid_header_row.rb +22 -0
  36. data/lib/gxt-widgets/platforms/watir_webdriver/gxt_grid_row.rb +17 -0
  37. data/lib/gxt-widgets/version.rb +4 -0
  38. data/readme.md +15 -0
  39. data/spec/gxt-widgets/gxt_grid_row_spec.rb +67 -0
  40. data/spec/gxt-widgets/gxt_grid_spec.rb +96 -0
  41. metadata +223 -0
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))
2
+
3
+ require 'rspec/expectations'
4
+ require 'page-object'
5
+ require 'page-object/page_factory'
6
+ require 'gxt-widgets'
7
+
8
+ World(PageObject::PageFactory)
@@ -0,0 +1,7 @@
1
+ Before do
2
+ @browser = PageObject::PersistantBrowser.get_browser
3
+ end
4
+
5
+ at_exit do
6
+ PageObject::PersistantBrowser.quit
7
+ end
@@ -0,0 +1,9 @@
1
+ class BasicGridExample
2
+ include PageObject
3
+
4
+ gxt_grid(:grid, :class => "x-grid3")
5
+ gxt_column_menu(:column_menu, :xpath=>"//div[contains(@class,' x-menu-list')]")
6
+ gxt_column_selection_menu(:column_selection_menu, :xpath=>"(//div[contains(@class,'x-menu-list') and not(contains(@class, 'x-menu-list-item'))])[2]")
7
+
8
+
9
+ end
@@ -0,0 +1,5 @@
1
+ class GroupingGridExample
2
+ include PageObject
3
+
4
+
5
+ end
@@ -0,0 +1,9 @@
1
+ class GxtExamplesPage
2
+ include PageObject
3
+
4
+ page_url "http://gxtexamplegallery.appspot.com/"
5
+
6
+ div(:basic_grid, :class => "label_basic_grid")
7
+ div(:local_pagination, :class => "label_paging_grid")
8
+ div(:grouping_grid, :class => "label_grouping_grid")
9
+ end
@@ -0,0 +1,6 @@
1
+ class LocalPaginationExample
2
+ include PageObject
3
+
4
+ gxt_grid(:grid, :class => "x-grid3")
5
+ gxt_pager(:pager, :class =>"x-toolbar-ct")
6
+ end
@@ -0,0 +1,20 @@
1
+ require 'watir-webdriver'
2
+ require 'selenium-webdriver'
3
+
4
+ module PageObject
5
+ module PersistantBrowser
6
+ @@browser = false
7
+ def self.get_browser
8
+ if !@@browser
9
+ target_browser = ENV['BROWSER'].to_sym
10
+ @@browser = Watir::Browser.new target_browser if ENV['DRIVER'] == 'WATIR'
11
+ @@browser = Selenium::WebDriver.for target_browser if ENV['DRIVER'] == 'SELENIUM'
12
+ end
13
+
14
+ @@browser
15
+ end
16
+ def self.quit
17
+ @@browser.quit
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gxt-widgets/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gxt-widgets"
7
+ s.version = GxtWidgets::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["William J. Powell", "Jeff Morgan"]
10
+ s.email = ["williamjpowell@gmail.com", "jeff.morgan@leandog.com"]
11
+ s.homepage = "http://github.com/wjpowell/gxt-widgets"
12
+ s.summary = %q{PageObject Widgets to simplify testing GXT applications}
13
+ s.description = %q{An Extension to page-object gem which provides widgets for interacting with GXT controls found on the Gxt Example Gallery http://gxtexamplegallery.appspot.com/}
14
+
15
+ s.rubyforge_project = "gxt-widgets"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'page-object', '>= 0.8.2'
23
+
24
+ s.add_development_dependency 'rspec', '>= 2.12.0'
25
+ s.add_development_dependency 'cucumber', '< 1.2.0'
26
+ s.add_development_dependency 'yard', '>= 0.7.2'
27
+ s.add_development_dependency 'rack', '>= 1.0'
28
+ s.add_development_dependency 'watir-webdriver', '>= 0.6.2'
29
+ s.add_development_dependency 'selenium-webdriver', '>= 2.27.2'
30
+
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'page-object'
2
+ require 'gxt-widgets/version'
3
+ require 'gxt-widgets/gxt_grid'
4
+ require 'gxt-widgets/gxt_pager'
5
+ require 'gxt-widgets/gxt_grid_row'
6
+ require 'gxt-widgets/gxt_grid_header_row'
7
+ require 'gxt-widgets/gxt_header_cell'
8
+ require 'gxt-widgets/modules/selectable_column'
9
+ require 'gxt-widgets/modules/sortable_column'
10
+ require 'gxt-widgets/gxt_column_menu'
11
+ require 'gxt-widgets/gxt_column_selection_menu'
12
+
13
+ module GxtWidgets
14
+
15
+ end
@@ -0,0 +1,11 @@
1
+ module GxtWidgets
2
+ class GxtColumnMenu < PageObject::Elements::Div
3
+ include ::GxtWidgets::SortableColumn
4
+
5
+ PageObject.register_widget(:gxt_column_menu, GxtColumnMenu, 'div')
6
+
7
+ def open_column_selection_menu
8
+ link_element(:text=>"Columns").hover
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module GxtWidgets
2
+ class GxtColumnSelectionMenu < PageObject::Elements::Div
3
+ include ::GxtWidgets::SelectableColumn
4
+
5
+ PageObject.register_widget(:gxt_column_selection_menu, GxtColumnSelectionMenu, 'div')
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'watir-webdriver'
2
+ require 'page-object/platforms/watir_webdriver/table'
3
+ module GxtWidgets
4
+ class GxtGrid < PageObject::Elements::Table
5
+
6
+ PageObject.register_widget :gxt_grid, GxtGrid, 'div'
7
+
8
+ protected
9
+ def child_xpath
10
+ ".//descendant::tr"
11
+ end
12
+
13
+ def initialize_row(row_element, platform)
14
+ Object::GxtWidgets::GxtGridRow.new(row_element, self, platform)
15
+ end
16
+
17
+ def initialize_header(header_element, platform)
18
+ Object::GxtWidgets::GxtGridHeaderRow.new(header_element, self, platform)
19
+ end
20
+
21
+ def include_platform_for platform
22
+ super
23
+ if platform[:platform] == :watir_webdriver
24
+ require 'gxt-widgets/platforms/watir_webdriver/gxt_grid'
25
+ self.class.send :include, GxtWidgets::Platforms::WatirWebDriver::GxtGrid
26
+ elsif platform[:platform] == :selenium_webdriver
27
+ require 'gxt-widgets/platforms/selenium_webdriver/gxt_grid'
28
+ self.class.send :include, GxtWidgets::Platforms::SeleniumWebDriver::GxtGrid
29
+ else
30
+ raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ require 'gxt-widgets/gxt_header_cell'
2
+ module GxtWidgets
3
+ class GxtGridHeaderRow < GxtGridRow
4
+ protected
5
+
6
+ def initialize_cell(row_element, platform)
7
+ Object::GxtWidgets::GxtHeaderCell.new(row_element, platform)
8
+ end
9
+
10
+ def include_platform_for platform
11
+ super
12
+ if platform[:platform] == :watir_webdriver
13
+ require 'gxt-widgets/platforms/watir_webdriver/gxt_grid_header_row'
14
+ self.class.send :include, GxtWidgets::Platforms::WatirWebDriver::GxtGridHeaderRow
15
+ elsif platform[:platform] == :selenium_webdriver
16
+ require 'gxt-widgets/platforms/selenium_webdriver/gxt_grid_header_row'
17
+ self.class.send :include, GxtWidgets::Platforms::SeleniumWebDriver::GxtGridHeaderRow
18
+ else
19
+ raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module GxtWidgets
2
+ class GxtGridRow < PageObject::Elements::TableRow
3
+
4
+ attr_reader :container
5
+
6
+ def initialize(element, container, platform)
7
+ @element = element
8
+ @container = container
9
+ include_platform_for platform
10
+ end
11
+
12
+ protected
13
+
14
+ def initialize_cell(row_element, platform)
15
+ PageObject::Elements::TableCell.new(row_element, platform)
16
+ end
17
+
18
+ def include_platform_for platform
19
+ super
20
+ if platform[:platform] == :watir_webdriver
21
+ require 'gxt-widgets/platforms/watir_webdriver/gxt_grid_row'
22
+ self.class.send :include, GxtWidgets::Platforms::WatirWebDriver::GxtGridRow
23
+ elsif platform[:platform] == :selenium_webdriver
24
+ require 'gxt-widgets/platforms/selenium_webdriver/gxt_grid_row'
25
+ self.class.send :include, GxtWidgets::Platforms::SeleniumWebDriver::GxtGridRow
26
+ else
27
+ raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module GxtWidgets
2
+ class GxtHeaderCell < PageObject::Elements::TableCell
3
+
4
+ def initialize(element, platform, *menu_controls)
5
+ super(element, platform)
6
+ menu_controls.each do |menu_control|
7
+ self.class.send include, menu_control
8
+ end
9
+ end
10
+
11
+ def open_menu
12
+ link_element.fire_event("onclick")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module GxtWidgets
2
+ class GxtPager < PageObject::Elements::Div
3
+ PageObject.register_widget :gxt_pager, GxtPager, 'table'
4
+
5
+ def first
6
+ first_cell = cell_elements(:class=>"x-toolbar-cell")[0]
7
+ first_cell.button_element(:tag_name=>"button").click
8
+ end
9
+
10
+ def previous
11
+ next_cell = cell_elements(:class=>"x-toolbar-cell")[1]
12
+ next_cell.button_element(:tag_name=>"button").click
13
+ end
14
+
15
+ def last
16
+ next_cell = cell_elements(:class=>"x-toolbar-cell")[8]
17
+ next_cell.button_element(:tag_name=>"button").click
18
+ end
19
+
20
+ def next
21
+ next_cell = cell_elements(:class=>"x-toolbar-cell")[7]
22
+ next_cell.button_element(:tag_name=>"button").click
23
+ end
24
+
25
+ def page
26
+ page_cell = cell_elements(:class=>"x-toolbar-cell")[4]
27
+ page_cell.text_field_element.value
28
+ end
29
+
30
+ def page=(page_number)
31
+ page_cell = cell_elements(:class=>"x-toolbar-cell")[4]
32
+ page_cell.text_field_element.value=page_number
33
+ page_cell.text_field_element.send_keys :return
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module GxtWidgets
2
+ module SelectableColumn
3
+ def include_column(column_name)
4
+ column = link_element(:text=>column_name)
5
+ column.click unless column.attribute("class").include? "x-menu-checked"
6
+ end
7
+
8
+ def exclude_column(column_name)
9
+ column = link_element(:text=>column_name)
10
+ column.click if column.attribute("class").include? "x-menu-checked"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module GxtWidgets
2
+ module SortableColumn
3
+ def sort_ascending
4
+ link_element(:text=>"Sort Ascending").click
5
+ end
6
+
7
+ def sort_descending
8
+ link_element(:text=>"Sort Descending").click
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,25 @@
1
+ require "gxt-widgets/gxt_grid_row"
2
+ require 'gxt-widgets/gxt_grid_header_row'
3
+ module GxtWidgets
4
+ module Platforms
5
+ module SeleniumWebDriver
6
+ module GxtGrid
7
+ include PageObject::Platforms::SeleniumWebDriver::Table
8
+
9
+ def [](idx)
10
+ eles = table_rows
11
+ idx = find_index_by_title(idx, eles) if idx.kind_of?(String)
12
+ return nil unless idx
13
+ initialize_row(eles[idx], :platform => :selenium_webdriver)
14
+ end
15
+
16
+ def header
17
+ initialize_header(table_rows[0], :platform => :selenium_webdriver)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,23 @@
1
+ module GxtWidgets
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+ module GxtGridHeaderRow
5
+ include GxtWidgets::Platforms::SeleniumWebDriver::GxtGridRow
6
+
7
+ #
8
+ # Return the PageObject::Elements::TableCell for the index provided. Index
9
+ # is zero based. If the index provided is a String then it
10
+ # will be matched with the text from the columns in the first row.
11
+ # The text can be a substring of the full column text.
12
+ #
13
+ def [](idx)
14
+ els = table_cells
15
+ idx = find_index_by_title(idx) if idx.kind_of?(String)
16
+ return nil unless idx && columns >= idx + 1
17
+ initialize_cell(els[idx], :platform => :selenium_webdriver)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require "page-object/platforms/selenium_webdriver/table_row"
2
+ module GxtWidgets
3
+ module Platforms
4
+ module SeleniumWebDriver
5
+ module GxtGridRow
6
+ include PageObject::Platforms::SeleniumWebDriver::TableRow
7
+
8
+ def find_index_by_title(title)
9
+ first_row = @container.first_row
10
+ first_row.find_index {|column| column.text.include? title }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require "gxt-widgets/gxt_grid_row"
2
+ require 'gxt-widgets/gxt_grid_header_row'
3
+ module GxtWidgets
4
+ module Platforms
5
+ module WatirWebDriver
6
+ module GxtGrid
7
+ include PageObject::Platforms::WatirWebDriver::Table
8
+
9
+ def [](idx)
10
+ idx = find_index_by_title(idx) if idx.kind_of?(String)
11
+ return nil unless idx
12
+ initialize_row(row_collection[idx], :platform => :watir_webdriver)
13
+ end
14
+
15
+ def header
16
+ initialize_header(row_collection[0], :platform => :watir_webdriver)
17
+ end
18
+
19
+ private
20
+
21
+ def find_index_by_title(row_title)
22
+ row_collection.find_index do |row|
23
+ row.cells.any? { |col| col.text.include? row_title }
24
+ end
25
+ end
26
+
27
+ def row_collection
28
+ element.trs(:xpath => child_xpath)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+
@@ -0,0 +1,22 @@
1
+ module GxtWidgets
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module GxtGridHeaderRow
5
+ include GxtWidgets::Platforms::WatirWebDriver::GxtGridRow
6
+
7
+ #
8
+ # Return the PageObject::Elements::TableCell for the index provided. Index
9
+ # is zero based. If the index provided is a String then it
10
+ # will be matched with the text from the columns in the first row.
11
+ # The text can be a substring of the full column text.
12
+ #
13
+ def [](idx)
14
+ idx = find_index_by_title(idx) if idx.kind_of?(String)
15
+ return nil unless idx && columns >= idx + 1
16
+ initialize_cell(element[idx], :platform => :watir_webdriver)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end