Revisions

gist: 67874 Download_button fork
public
Public Clone URL: git://gist.github.com/67874.git
products_and_services_selector.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Feature: Ajax Interface for selecting products and services for a registered providers
  As a registered provider
  In order to select products and services for my projects
  I should be able to select products and services from the ajax style interface
 
  Scenario: a provider drilldowns and adds a product to their company
    Given an active provider_user named 'skeebo'
    When he logs in with username 'skeebo' and password 'turtles'
    And he clicks the 'My Company' link
    And he waits for the page to load
    And he clicks on the 'Products & Services' tab
    And he waits for the page to load
    Then the page should contain the text 'Manage Products & Services'
    When he clicks the 'On-Site Energy Generation' link
    Then a link 'Solar' should appear
    When he clicks the 'Solar' link
    Then a link 'Solar › Solar Electric' should appear
    When he clicks the 'Solar › Solar Electric' link
    Then a link 'Solar Photovoltaic Panels' should appear
    When he clicks the 'Solar Photovoltaic Panels' link
    Then a link 'Retail' should appear
    And a link 'Wholesale' should appear
    And a link 'Installation' should appear
    And a link 'Maintenance' should appear
    And a link 'Design & Consulting' should appear
    And a link 'Manufacturing' should appear
    When he clicks the 'Wholesale' link
    
  Scenario: a wattbot admin drills down and adds a product to a company
    Given an admin wattbot_user
    When he logs in with username 'addie' and password '1234addie'
    And he goes to /admin
    And he clicks on the 'Providers' tab
    And he waits for the page to load
    And he clicks the 'California Green Designs' link
    And he waits for the page to load
    And he clicks on the 'Products & Services' tab
    And he waits for the page to load
    And he clicks the 'On-Site Energy Generation' link
    Then a link 'Solar' should appear
    When he clicks the 'Solar' link
    Then a link 'Solar › Solar Electric' should appear
    When he clicks the 'Solar › Solar Electric' link
    Then a link 'Solar Photovoltaic Thin Film' should appear
    When he clicks the 'Solar Photovoltaic Thin Film' link
    Then a link 'Retail' should appear
    And a link 'Wholesale' should appear
    And a link 'Installation' should appear
    And a link 'Maintenance' should appear
    And a link 'Design & Consulting' should appear
    And a link 'Manufacturing' should appear
    When he clicks the 'Wholesale' link
   
  Scenario: wattbot admin can apply products and services to an Incentive
    Given an admin wattbot_user
    When he goes to /admin
    And he clicks the 'Incentives' link
    And he waits for the page to load
    And he clicks the 'First sales tax exemption' link
    And he waits for the page to load
    And he clicks on the 'Products & Services' tab
    And he waits for the page to load
    And he clicks the 'On-Site Energy Generation' link
    Then a link 'Solar' should appear
    When he clicks the 'Solar' link
    Then a link 'Solar › Solar Electric' should appear
    When he clicks the 'Solar › Solar Electric' link
    Then a link 'Solar Photovoltaic Thin Film' should appear
    When he clicks the 'Solar Photovoltaic Thin Film' link
    Then a link 'Solar Photovoltaic Thin Film' should appear
 
selenium.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
  When "$actor goes to $path" do |actor, path|
    case
    when path == 'the home page' then $selenium.open '/'
    when path =~ /the '?([^']*)'? (page|form)/i then $selenium.open $1
    else $selenium.open path
    end
  end
 
  #
  # Destinations. Ex:
  # She should be at the new kids page
  # Tarkin should be at the destroy alderaan page
  # The visitor should be at the '/lolcats/download' form
  # The visitor should be redirected to '/hi/mom'
  #
  # It doesn't know anything about actual routes -- it just
  # feeds its output to render_template or redirect_to
  #
  Then "$actor should be at $path" do |_, path|
    $selenium.location.should == grok_path(path)
  end
  
  Then "$actor should be invited to sign in" do |_|
    $selenium.location.should == '/login'
  end
 
  Then "$actor should be redirected to $path" do |_, path|
    $selenium.location.should == grok_path(path)
  end
 
  When "$actor follows that redirect!" do |actor|
  end
  
  When "$actor types '$text' into the $field field" do |actor, text, field|
    $selenium.type field, text
  end
 
   When "$actor set the $controller dropdown box to $value" do |_,controller,value|
     $selenium.select("id=#{controller}",value);
     @profile_values = @profile_values.merge Hash[controller, value] if @profile_values != nil
   end
 
   When "$actor selects the option at the position $number from the $controller dropdown box" do |_,number,controller|
     $selenium.select("id=#{controller}","index=#{number.to_s}");
   end
  
  When "$actor clicks the $button button" do |button|
    $selenium.click button
  end
  
  When "$actor clicks the '$link' link" do |_, link|
    $selenium.click "link=" + link
  end
  
  When "$actor clicks on the link button containing the text '$text'" do |_,text|
    $selenium.click "//a/strong[contains(text(),'#{text}')]"
  end
  
  When "$actor clicks on the '$link' tab" do |_,link|
    $selenium.click "//a/span[text()='#{link}']"
  end
 
  When "$actor clicks on the link containing the text '$text'" do |_,text|
   $selenium.click "//a[contains(text(),'#{text}')]"
  end
 
  When "$a link containing the text '$text' should appear" do |_,text|
   $selenium.should have_element_present("//a[contains(text(),'#{text}')]")
  end
 
  When "$actor clicks the first submit button that $actor sees" do |_, _|
    $selenium.click "//button[@type='submit']"
  end
  
  When "$actor checks the $field checkbox" do |_, field|
    $selenium.check field
  end
  
  When "$actor unchecks the $field checkbox" do |_, field|
    $selenium.uncheck field
  end
  
  When "$actor waits for the page to load" do |_|
    $selenium.wait_for_page_to_load 10000
  end
 
  When "$actor waits for $number seconds" do |_, number|
    sleep(number.to_i)
  end
 
  When "$actor waits $seconds seconds for the page to load" do |_, seconds|
    $selenium.wait_for_page_to_load seconds.to_i*1000
  end
  
  Then "the title should be '$title'" do |title|
    $selenium.title.should == title
  end
  
  Then "the page should contain the text '$text'" do |text|
    $selenium.should have_text_present(text)
  end
  
  Then "$username should see that $actor is logged in" do |username, _|
    $selenium.should have_text_present("Welcome back, #{username}")
  end
  
  Then "$username should not be logged in" do |username|
    $selenium.should_not have_text_present("Welcome back, #{username}")
    $selenium.should have_text_present("Register for Free | Log in")
  end
  
  Then "there should be a field named '$field'" do |field|
    $selenium.should have_element_present(field)
  end
  
  Then "there should be a file-upload field named '$field'" do |field|
    $selenium.should have_element_present("//input[@type='file'][@name='#{field}']")
  end
  
  Then "there should be a submit button named '$name', with the label '$label'" do |name, label|
    $selenium.should have_element_present("//input[@type='submit'][@name='#{name}'][@value='#{label}']")
  end
  
  Then "$actor clicks on a submit button that says '$name'" do |_,name|
    $selenium.click("//input[@type='submit'][@value='#{name}']")
  end
  
  Then "$actor clicks on the first image submit button $theactor sees" do |_,_|
    $selenium.click("//input[@type='image']")
  end
 
  Then "a link '$item' should appear" do |item|
    wait_for_element_present("link=#{item}")
  end
 
  def wait_for_element_present(locator)
    $selenium.wait_for_condition("selenium.isElementPresent(\"#{locator}\")", 10000)
  end
 
  # check for ActiveRecord validation messages
  Then "$actor should see a validation error '$message'" do |_, message|
    $selenium.should have_element_present("//div[@id='errorExplanation']/ul/li[contains(text(), \"#{message}\")]")
  end
  
  Then "$actor should not see a validation error '$message'" do |_, message|
    $selenium.should_not have_element_present("//div[@id='errorExplanation']/ul/li[contains(text(), \"#{message}\")]")
  end
  
  # this is for other types of error messages:
  # <div id="flash" class="error rnd jrcRounded" style="overflow: visible; position: relative;">
  # e.g. when entering a wrong email address at the password recovery page
  Then "$actor should see error message '$message'" do |_, message|
    $selenium.should have_element_present("//div[@class='error rnd jrcRounded'][contains(text(), \"#{message}\")]")
  end
  
  #
  # Flash messages
  #
  Then "$actor should see $an $notice message '$message'" do |_, _, notice, message|
    $selenium.should have_element_present("//div[@id='flash'][contains(@class,'#{notice}')][contains(text(), \"#{message}\")]")
  end
  
  Then "$actor should not see $an $notice message '$message'" do |_, _, notice, message|
    $selenium.should_not have_element_present("//div[@id='flash'][contains(@class,'#{notice}')]")
  end
  
  Then "$actor should see no messages" do |_|
    $selenium.should_not have_element_present("//div[@id='flash']")
  end
  
  Then "$actor should see the title '$title'" do |_, title|
    title = title.gsub(" ", "%20")
    title = title.gsub("/", "%2F")
    $selenium.should have_element_present("//embed[@type='application/x-shockwave-flash'][contains(@flashvars,'#{'txt=' + title + '&'}')]")
  end
  
  Then "$actor should see the subtitle '$subtitle'" do |_, subtitle|
    $selenium.should have_element_present("//h3[contains(text(),'#{subtitle}')]")
  end
 
  When "$actor should see a link button with the text '$link'" do |_,link|
    $selenium.should have_element_present("//a/strong[contains(text(),'#{link}')]")
  end
  
  When "$actor should see a '$label' label" do |_, label|
    $selenium.should have_element_present("//label[contains(text(),'#{label}')]")
  end
  
def escape_xpath_string(message)
  message.gsub(/'/,"&quot;")
end