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: #
# 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(/'/,""") end