Created
February 18, 2010 13:51
-
-
Save bonyiii/307667 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'culerity' | |
Before do | |
$rails_server ||= Culerity::run_rails | |
sleep 5 | |
$server ||= Culerity::run_server | |
$browser = Culerity::RemoteBrowserProxy.new $server, {:browser => :firefox3#, | |
#:resynchronize => true, | |
#:javascript_exceptions=>true, | |
#:refresh_handler=> :waiting, | |
#:log_level=> :all | |
} | |
@host = 'http://localhost:3001' | |
end | |
at_exit do | |
$browser.exit if $browser | |
$server.exit_server if $server | |
Process.kill(6, $rails_server.pid.to_i) if $rails_server | |
end | |
When /I press "(.*)"/ do |button| | |
$browser.button(:text, button).click | |
assert_successful_response | |
end | |
When /I follow "(.*)"/ do |link| | |
$browser.link(:text, /#{link}/).click | |
assert_successful_response | |
end | |
When /I fill in "(.*)" for "(.*)"/ do |value, field| | |
#$browser.resynchronized do | |
$browser.text_field(:id, find_label(field).for).set(value) | |
#end | |
end | |
When /I check "(.*)"/ do |field| | |
$browser.check_box(:id, find_label(field).for).set(true) | |
end | |
When /^I uncheck "(.*)"$/ do |field| | |
$browser.check_box(:id, find_label(field).for).set(false) | |
end | |
When /^I select "(.*)" from "(.*)"$/ do |value, field| | |
$browser.select_list(:id, find_label(field).for).select value | |
end | |
When /I choose "(.*)"/ do |field| | |
$browser.radio(:id, find_label(field).for).set(true) | |
end | |
When /I go to (.+)/ do |path| | |
$browser.goto @host + path_to(path) | |
assert_successful_response | |
end | |
When /I wait for the AJAX call to finish/ do | |
$browser.wait | |
end | |
Then /I should see "(.*)"/ do |text| | |
# if we simply check for the browser.html content we don't find content that has been added dynamically, e.g. after an ajax call | |
div = $browser.div(:text, /#{text}/) | |
begin | |
div.html | |
rescue | |
Given "I want to see where I am" | |
raise("div with '#{text}' not found") | |
end | |
end | |
Then /I should not see "(.*)"/ do |text| | |
div = $browser.div(:text, /#{text}/).html rescue nil | |
begin | |
div.should be_nil | |
rescue | |
Given "I want to see where I am" | |
raise("div with '#{text}' found") | |
end | |
end | |
def find_label(text) | |
$browser.label :text, text | |
end | |
def assert_successful_response | |
status = $browser.page.web_response.status_code | |
if(status == 302 || status == 301) | |
location = $browser.page.web_response.get_response_header_value('Location') | |
puts "Being redirected to #{location}" | |
$browser.goto location | |
assert_successful_response | |
elsif status != 200 | |
Given "I want to see where I am" | |
raise "Brower returned Response Code #{$browser.page.web_response.status_code}" | |
end | |
end | |
## Added by Boni | |
def assert_unauthorized_response | |
status = $browser.page.web_response.status_code | |
if status != 401 | |
Given "I want to see where I am" | |
raise "Brower returned Response Code #{$browser.page.web_response.status_code}" | |
end | |
end | |
Given /^I am logged in as "([^\"]*)" with password "([^\"]*)"$/ do |username, password| | |
unless username.blank? | |
$browser.goto @host + path_to(login_path) | |
# $browser.goto @host + path_to(login_path) # a rails -es path változók elérhetőek! | |
$browser.text_field(:id,"login_username").set(username) | |
$browser.text_field(:id,"login_password").set(password) | |
$browser.button(:text, "Bejelentkezés").click | |
assert_successful_response | |
div = $browser.div(:text, /Nem tud belépni mint '#{username}'/).html rescue nil | |
div.should be_nil | |
end | |
end | |
Given /^I want to see where I am$/ do | |
tmp = Tempfile.new 'culerity_results' | |
tmp << $browser.html | |
tmp.close | |
`konqueror #{tmp.path}` | |
end | |
When /^I focus on AJAX field "([^\"]*)"$/ do |field| | |
$browser.text_field(:id, find_label(field).for).focus | |
$browser.wait | |
end | |
When /^I focus on AJAX field "(.*)" by "(.*)"$/ do |field,by| | |
$browser.text_field(by.to_sym, field).focus | |
$browser.wait | |
end | |
When /^I fill in "(.*)" for by id "(.*)"$/ do |value, field| | |
$browser.text_field(:id, field).set(value) | |
end | |
When /^I fill in "(.*)" for by name "(.*)"$/ do |value, field| | |
$browser.text_field(:name, field).set(value) | |
end | |
When /^I fill in by id "([^\"]*)" with multiline query$/ do |field, value| | |
#$browser.resynchronized do | |
$browser.text_field(:id, field).set(value) | |
#end | |
end | |
When /^I click option "(.*)"$/ do |arg1| | |
$browser.link(:text, /#{arg1}/).click | |
end | |
When /^I focus on link "(.*)"$/ do |link| | |
$browser.link(:text, /#{link}/).focus | |
end | |
When /^I follow link "([^\"]*)" by "([^\"]*)"$/ do |link, by| | |
$browser.link(by.to_sym, link).click | |
assert_successful_response | |
end | |
When /I by "(.*)" select "(.*)" from "(.*)"/ do |by, value, field| | |
$browser.select_list(by.to_sym, field).select value | |
end | |
Then /page should contains "(.*)"$/ do |text| | |
$browser.contains_text(text).should_not be_nil | |
end | |
Then /^"(.*)" value should be "(.*)"$/ do |field_name,value| | |
#http://rdoc.info/projects/jarib/celerity | |
$browser.hidden(:name, field_name).verify_contains(/#{value}/) | |
#$browser.hidden(:xpath,"//input[@name='likvidation[organization_id]']") | |
end | |
Then /^hidden field "(.*)" by "(.*)" value should "(.*)"$/ do |field_name,by,value| | |
#http://rdoc.info/projects/jarib/celerity | |
#$browser.hidden(:name, field_name).verify_contains(/#{value}/) | |
$browser.hidden(by.to_sym,field_name).verify_contains(/#{value}/) | |
end | |
Then /^text field by name "(.*)" value should be "(.*)"$/ do |field_name,value| | |
#http://rdoc.info/projects/jarib/celerity | |
$browser.text_field(:name, field_name).verify_contains(/#{value}/) | |
#$browser.hidden(:xpath,"//input[@name='likvidation[organization_id]']") | |
end | |
Then /^within "(.*)" it should be "(.*)"$/ do |selector,text| | |
# if we simply check for the browser.html content we don't find content that has been added dynamically, e.g. after an ajax call | |
element = $browser.send( selector, { :text => /#{text}/ } ) | |
begin | |
element.html | |
rescue | |
Given "I want to see where I am" | |
raise("div with '#{text}' not found") | |
end | |
end | |
Then /^select_list "(.*)" value should be "(.*)"$/ do |select_list,value| | |
$browser.select_list(:id, find_label(field).for).selected?( value ) | |
end | |
Then /^select_list "(.*)" value should not be "(.*)"$/ do |select_list,value| | |
$browser.select_list(:id, find_label(field).for).selected?( value ).should be_nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment