thistle 0.0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README +1 -0
  2. data/lib/thistle.rb +159 -0
  3. data/lib/thistle_class.rb +106 -0
  4. metadata +87 -0
data/README ADDED
@@ -0,0 +1 @@
1
+ Thistle is a language- and framework agnostic vocabulary for testing web sites.
@@ -0,0 +1,159 @@
1
+ #
2
+ # when time is ripe, drag this out to it's own ruby-gem
3
+ #
4
+
5
+ # the regex's should be part of the Thistle helper?
6
+
7
+ # Thistle API for cucumber
8
+
9
+ require 'thistle_class.rb'
10
+
11
+ # register actions
12
+ #World(Thistle)
13
+
14
+ # NAVIGATION
15
+ When /^(?:I )?(?:visit|navigate to|go to|browse) (.+)$/ do |page|
16
+ visit(page)
17
+ end
18
+
19
+ # CLICKING
20
+ When /^(?:I )?(?:click|press|choose) (?:the )?(?:\")?(.+?)(?:\")?(?: button)?$/ do |locator|
21
+ click(locator)
22
+ end
23
+
24
+ # ENTERING DATA
25
+ When /^(?:I )?(?:enter|type|insert) (?:\")?(.+)(?:\")? (?:in the field|in|into|in the) (?:\")?([^\"]*?)(?:\")?(?: field)?$/ do |text, locator|
26
+ enter_text(text, locator)
27
+ end
28
+
29
+ Given /^(?:I )?(?:enter|type|insert)(?: the following):$/ do |input_table|
30
+ input_table.raw.each do |row|
31
+ enter_text(row[1], row[0])
32
+ end
33
+ end
34
+
35
+ # CONVIENIENCE MATCHER (version 2.0 stuff!)
36
+ Given /^(?:I )?login as "([^\"]*)" \/ "([^\"]*)"$/ do |username, password|
37
+ login(username, password)
38
+ end
39
+
40
+ # check for matching title / refactor for any element
41
+ Then /^(?:the )?(?:\")?([^\"]*)(?:\")? should (?:be|equal) (?:\")?([^\"]*)(?:\")?$/ do |locator, expected_value|
42
+ check_locator_value(locator, expected_value)
43
+ end
44
+
45
+ Then /^(?:the )?([^\"]*) should (?:match) ([^\"]*)$/ do |locator, regex_pattern|
46
+ match_locator_value(locator, regex_pattern)
47
+ end
48
+
49
+ Then /^(?:I )?should see (?:the text )?(?:\")?([^\"]*)(?:\")?$/ do |expected_text|
50
+ check_for_text(expected_text)
51
+ end
52
+
53
+ Then /^(?:I )?should not see (?:the text )?(?:\")?([^\"]*)(?:\")?$/ do |expected_text|
54
+ check_for_text(expected_text, false)
55
+ end
56
+
57
+
58
+ # below here is inspiration! =)
59
+
60
+ =begin
61
+
62
+ Then /^the page should load in less than (\d+) seconds$/ do |timeout|
63
+ # no need for this in Watir, all checks wait by default
64
+ # see http://wiki.openqa.org/display/WTR/How+to+wait+with+Watir
65
+ end
66
+ =end
67
+
68
+
69
+
70
+
71
+
72
+ =begin
73
+ case PLATFORM
74
+ when /darwin/
75
+ require 'safariwatir'
76
+ Browser = Watir::Safari
77
+ when /win32|mingw/
78
+ require 'watir'
79
+ Browser = Watir::IE
80
+ # Browser.speed = :fast
81
+ when /java/
82
+ require 'celerity'
83
+ Browser = Celerity::Browser
84
+ else
85
+ raise "This platform is not supported (#{PLATFORM})"
86
+ end
87
+ =end
88
+
89
+ =begin
90
+ # default from cukes
91
+ # http://github.com/aslakhellesoy/cucumber/raw/9ecb25dcf645d0f55cb27c2383ae3d9763399f93/generators/cucumber/templates/common_webrat.rb
92
+ When /I press "(.*)"/ do |button|
93
+ clicks_button(button)
94
+ end
95
+
96
+ When /I follow "(.*)"/ do |link|
97
+ clicks_link(link)
98
+ end
99
+
100
+ When /I enter "(.*)" for "(.*)"/ do |value, field|
101
+ fills_in(field, :with => value)
102
+ end
103
+
104
+ When /I check "(.*)"/ do |field|
105
+ checks(field)
106
+ end
107
+
108
+
109
+
110
+ Then /I should see "(.*)"/ do |text|
111
+ response.body.should =~ /#{text}/m
112
+ end
113
+
114
+ Then /I should not see "(.*)"/ do |text|
115
+ response.body.should_not =~ /#{text}/m
116
+ end
117
+
118
+
119
+
120
+
121
+
122
+ #require 'celerity'
123
+ require 'spec'
124
+ require 'hpricot'
125
+
126
+ #Before do
127
+ # @browser = Browser.new #Celerity::IE.new #Browser.new
128
+ # @browser.speed = :fast
129
+ #end
130
+
131
+ After do
132
+ @browser.close
133
+ end
134
+
135
+ Given /^I navigate to (.+)$/ do |url|
136
+ @browser.goto url
137
+ end
138
+
139
+ Then /^the title should be "(.+)"$/ do |text|
140
+ @browser.title.should == text
141
+ end
142
+
143
+ Then /^there should be a link to (.+)(?: present)?$/ do |url|
144
+ @browser.link(:url, url)
145
+ end
146
+
147
+ When /^I enter "(.+)" in the (.+) field$/ do |text, locator|
148
+ @browser.text_field(:name, locator).set(text)
149
+ end
150
+
151
+ When /^press the "(.+)" button$/ do |locator|
152
+ @browser.button(:value, locator).click
153
+ end
154
+
155
+ Then /^the page should load in less than (\d+) seconds$/ do |timeout|
156
+ # no need for this in Watir, all checks wait by default
157
+ # see http://wiki.openqa.org/display/WTR/How+to+wait+with+Watir
158
+ end
159
+ =end
@@ -0,0 +1,106 @@
1
+ require 'spec'
2
+ require 'spec/expectations'
3
+ require 'webrat'
4
+
5
+ # Helper code for Thistle, take 1
6
+ module Thistle
7
+ class Thistle
8
+ #include Spec::Matchers
9
+ #include Webrat::Locators
10
+
11
+ def initialize(session = nil) #:nodoc:
12
+ @webrat_session = session
13
+ end
14
+
15
+ #def webrat_session=(session)
16
+ # @webrat_session = session
17
+ #end
18
+
19
+ #@path_to = {
20
+ # "the home page" => "/"
21
+ #}
22
+
23
+ def visit (page)
24
+ #@browser.goto page # celerity
25
+ #visits(@path_to[page]) # webrat
26
+ @webrat_session.visit page
27
+ end
28
+
29
+ def check_locator_value (locator, expected_value)
30
+ # refactor pls!
31
+ if locator == "title"
32
+ @webrat_session.response.title.should =~ /#{Regexp.escape(expected_value)}/m
33
+ else
34
+ @webrat_session.response.body.should =~ /#{Regexp.escape(expected_value)}/m
35
+ end
36
+ end
37
+
38
+ def enter_text (text, locator)
39
+ #@browser.text_field(:name, locator).set(text) # celerity
40
+ # todo add FieldPrependedByLocator to webrat
41
+ puts "Looking for field #{locator}"
42
+
43
+ =begin
44
+ if @webrat_session.field(locator) != nil
45
+ puts "Found field #{locator} as field"
46
+ elsif Webrat::XML.attribute(field_element, "id") =~ /#{Regexp.escape(locator)}/
47
+ puts "Found field #{locator} by regex"
48
+ end
49
+ =end
50
+
51
+ # use FieldLabeledLocator as well?
52
+ @webrat_session.fill_in locator, :with => text
53
+ end
54
+
55
+ def login (username, password)
56
+ # find the two fields and the submit-button
57
+ raise "Thistle Login-method not implemented yet!"
58
+ end
59
+
60
+
61
+
62
+ def match_locator_value (locator, regex_pattern)
63
+ # @browser.title.should =~ Regexp.new(regex_pattern) # celerity
64
+ pending
65
+ raise "Thistle match_locator_value-method not implemented yet!"
66
+ end
67
+
68
+ def check_for_text (text, should_be_present = true)
69
+ if !should_be_present
70
+ @webrat_session.response.body.should_not =~ /#{Regexp.escape(text)}/m
71
+ else
72
+ @webrat_session.response.body.should =~ /#{Regexp.escape(text)}/m
73
+ end
74
+ end
75
+
76
+ def click (locator)
77
+ #@browser.button(:value, locator).click # celerity
78
+ # refactor me!
79
+ =begin
80
+ if @webrat_session.find_button(locator) != nil
81
+ puts "Found button #{locator}"
82
+ elsif @webrat_session.find_link(locator) != nil
83
+ puts "Found link #{locator}"
84
+ else
85
+ puts "Nothing found to click"
86
+ end
87
+ =end
88
+
89
+ begin
90
+ @webrat_session.click_button locator
91
+ rescue
92
+ begin
93
+ @webrat_session.click_link /#{Regexp.escape(locator)}/
94
+ rescue
95
+ $stderr.puts $!.inspect
96
+ raise "Cannot find #{locator}"
97
+ end
98
+ end
99
+
100
+ #end
101
+ end
102
+
103
+ end
104
+ end
105
+
106
+ #World(Thistle)
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thistle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Pal Brattberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-25 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.6
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.7
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: webrat
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.4.4
44
+ version:
45
+ description: Thistle is a language- and framework agnostic vocabulary for testing web sites.
46
+ email: brattberg@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - README
55
+ - lib/thistle.rb
56
+ - lib/thistle_class.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/pal/thistle
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --inline-source
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements:
80
+ - cucumber, rspec and webrat
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.3
83
+ signing_key:
84
+ specification_version: 2
85
+ summary: Thistle is a language- and framework agnostic vocabulary for testing web sites.
86
+ test_files: []
87
+