selenium_steps.rb
4.43 KB
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
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
def string_to_element_locator(selector)
if selector.gsub!(/^\./, '')
"css=[class='#{selector}']"
elsif selector.gsub!(/^value[.=]/, '')
"xpath=//input[@value='#{selector}']"
elsif selector.gsub!(/^option=/, '')
"xpath=//option[@value='#{selector}']"
elsif selector.gsub!(/^#/, '')
"css=[id='#{selector}']"
elsif selector.gsub!(/^content=/, '')
"xpath=//*[.='#{selector}']"
elsif selector.gsub!(/^li=/, '')
"xpath=//li[contains(.,'#{selector}')]"
else
selector
end
end
Then /^the "([^\"]*)" should be visible$/ do |selector|
(selenium.is_element_present(string_to_element_locator(selector)) && selenium.is_visible(string_to_element_locator(selector))).should be_true
end
Then /^the content "([^\"]*)" should be visible$/ do |selector|
selenium.is_visible(string_to_element_locator("content=#{selector}")).should be_true
end
Then /^the "([^\"]*)" should not be visible$/ do |selector|
(selenium.is_element_present(string_to_element_locator(selector)) && selenium.is_visible(string_to_element_locator(selector))).should be_false
end
Then /^the content "([^\"]*)" should not be visible$/ do |selector|
selenium.is_visible(string_to_element_locator("content=#{selector}")).should be_false
end
When /^I click "([^\"]*)"$/ do |selector|
selenium.click(string_to_element_locator(selector))
end
Then /^the "([^\"]*)" button should not be enabled$/ do |text|
selenium.is_editable(string_to_element_locator(text)).should be_false
end
Then /^the "([^\"]*)" button should be enabled$/ do |text|
selenium.is_editable(string_to_element_locator("value.#{text}")).should be_true
end
Then /^I should see "([^\"]*)" above of "([^\"]*)"$/ do |above, below|
above_position = selenium.get_element_position_top(string_to_element_locator("li=#{above}"))
below_position = selenium.get_element_position_top(string_to_element_locator("li=#{below}"))
above_position.to_i.should < below_position.to_i
end
When /^I drag "([^\"]*)" to "([^\"]*)"$/ do |from, to|
selenium.drag_and_drop_to_object(string_to_element_locator("li=#{from}"), string_to_element_locator("li=#{to}"))
selenium.wait_for_ajax
end
When /^I select "([^\"]*)" and wait for (jquery)$/ do |value, framework|
select(value)
# FIXME ugly hack to make selenium tests waiting to render page
# "select(value, :wait_for => :ajax)" did not effect
selenium.wait_for(:wait_for => :ajax, :javascript_framework => framework)
end
When /^I select window "([^\"]*)"$/ do |selector|
selenium.select_window(selector)
end
When /^I fill in "([^\"]*)" within "([^\"]*)" with "([^\"]*)"$/ do |field_label, parent_class, value|
selenium.type("xpath=//*[contains(@class, '#{parent_class}')]//*[@id=//label[contains(., '#{field_label}')]/@for]", value)
end
When /^I press "([^\"]*)" within "([^\"]*)"$/ do |button_value, selector|
selenium.click("css=#{selector} input[value=#{button_value}]")
selenium.wait_for_page_to_load(10000)
end
Then /^there should be ([1-9][0-9]*) "([^\"]*)" within "([^\"]*)"$/ do |number, child_class, parent_class|
# Using xpath is the only way to count
response.selenium.get_xpath_count("//*[contains(@class,'#{parent_class}')]//*[contains(@class,'#{child_class}')]").to_i.should be(number.to_i)
end
Then /^"([^\"]*)" should be (left|right) aligned$/ do |element_class, align|
# Using xpath is the only way to count
response.selenium.get_xpath_count("//*[contains(@class,'#{element_class}') and contains(@style,'float: #{align}')]").to_i.should be(1)
end
When /^I confirm$/ do
selenium.get_confirmation
end
When /^I type "([^\"]*)" in TinyMCE field "([^\"]*)"$/ do |value, field_id|
response.selenium.type("dom=document.getElementById('#{field_id}_ifr').contentDocument.body", value)
end
When /^I refresh the page$/ do
response.selenium.refresh
end
When /^I click on the logo$/ do
selenium.click("css=h1#site-title a")
selenium.wait_for_page_to_load(10000)
end
When /^I open (.*)$/ do |url|
selenium.open(URI.join(response.selenium.get_location, url))
end
Then /^the page title should be "([^"]+)"$/ do |text|
selenium.get_text("//title").should == text
end
#### Noosfero specific steps ####
Then /^the select for category "([^\"]*)" should be visible$/ do |name|
sleep 2 # FIXME horrible hack to wait categories selection scolling to right
category = Category.find_by_name(name)
selenium.is_visible(string_to_element_locator("option=#{category.id}")).should be_true
end