Improved helper (use internal select and set).

This commit is contained in:
Martin Edenhofer 2016-03-21 13:51:55 +01:00
parent abb049ecec
commit 5e11344fb9

View file

@ -507,6 +507,7 @@ class TestCase < Test::Unit::TestCase
browser: browser1, browser: browser1,
css: '.some_class', css: '.some_class',
value: 'Some Value', value: 'Some Value',
deselect_all: false, # default false
) )
=end =end
@ -535,12 +536,18 @@ class TestCase < Test::Unit::TestCase
begin begin
element = instance.find_elements(css: params[:css])[0] element = instance.find_elements(css: params[:css])[0]
dropdown = Selenium::WebDriver::Support::Select.new(element) dropdown = Selenium::WebDriver::Support::Select.new(element)
if params[:deselect_all]
dropdown.deselect_all
end
dropdown.select_by(:text, params[:value]) dropdown.select_by(:text, params[:value])
puts "select - #{params.inspect}" puts "select - #{params.inspect}"
rescue rescue
# just try again # just try again
element = instance.find_elements(css: params[:css])[0] element = instance.find_elements(css: params[:css])[0]
dropdown = Selenium::WebDriver::Support::Select.new(element) dropdown = Selenium::WebDriver::Support::Select.new(element)
if params[:deselect_all]
dropdown.deselect_all
end
dropdown.select_by(:text, params[:value]) dropdown.select_by(:text, params[:value])
puts "select2 - #{params.inspect}" puts "select2 - #{params.inspect}"
end end
@ -1298,33 +1305,48 @@ wait untill text in selector disabppears
sleep 2 sleep 2
if data[:name] if data[:name]
element = instance.find_elements(css: '.modal input[name=name]')[0] set(
element.clear browser: instance,
element.send_keys(data[:name]) css: '.modal input[name=name]',
value: data[:name],
mute_log: true,
)
end end
if data[:role] if data[:role]
element = instance.find_elements(css: '.modal select[name="role_id"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data[:role]) css: '.modal select[name="role_id"]',
value: data[:role],
mute_log: true,
)
end end
if data[:selector] if data[:selector]
data[:selector].each {|key, value| data[:selector].each {|key, value|
element = instance.find_elements(css: '.modal .ticket_selector .js-attributeSelector select')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, key) css: '.modal .ticket_selector .js-attributeSelector select',
value: key,
mute_log: true,
)
sleep 0.5 sleep 0.5
element = instance.find_elements(css: '.modal .ticket_selector .js-value select')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.deselect_all css: '.modal .ticket_selector .js-value select',
dropdown.select_by(:text, value) value: value,
deselect_all: true,
mute_log: true,
)
} }
end end
if data['order::direction'] if data['order::direction']
element = instance.find_elements(css: '.modal select[name="order::direction"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data['order::direction']) css: '.modal select[name="order::direction"]',
value: data['order::direction'],
mute_log: true,
)
end end
instance.find_elements(css: '.modal button.js-submit')[0].click instance.find_elements(css: '.modal button.js-submit')[0].click
@ -1379,33 +1401,48 @@ wait untill text in selector disabppears
sleep 2 sleep 2
if data[:name] if data[:name]
element = instance.find_elements(css: '.modal input[name=name]')[0] set(
element.clear browser: instance,
element.send_keys(data[:name]) css: '.modal input[name=name]',
value: data[:name],
mute_log: true,
)
end end
if data[:role] if data[:role]
element = instance.find_elements(css: '.modal select[name="role_id"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data[:role]) css: '.modal select[name="role_id"]',
value: data[:role],
mute_log: true,
)
end end
if data[:selector] if data[:selector]
data[:selector].each {|key, value| data[:selector].each {|key, value|
element = instance.find_elements(css: '.modal .ticket_selector .js-attributeSelector select')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, key) css: '.modal .ticket_selector .js-attributeSelector select',
instance.execute_script("$('#content .modal .ticket_selector .js-attributeSelector select').first().trigger('change')") value: key,
element = instance.find_elements(css: '.modal .ticket_selector .js-value select')[0] mute_log: true,
dropdown = Selenium::WebDriver::Support::Select.new(element) )
dropdown.deselect_all sleep 0.5
dropdown.select_by(:text, value) select(
browser: instance,
css: '.modal .ticket_selector .js-value select',
value: value,
deselect_all: true,
mute_log: true,
)
} }
end end
if data['order::direction'] if data['order::direction']
element = instance.find_elements(css: '.modal select[name="order::direction"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data['order::direction']) css: '.modal select[name="order::direction"]',
value: data['order::direction'],
mute_log: true,
)
end end
instance.find_elements(css: '.modal button.js-submit')[0].click instance.find_elements(css: '.modal button.js-submit')[0].click
@ -1481,31 +1518,40 @@ wait untill text in selector disabppears
# check count of agents, should be only 1 / - selection on init screen # check count of agents, should be only 1 / - selection on init screen
count = instance.find_elements(css: '.active .newTicket select[name="owner_id"] option').count count = instance.find_elements(css: '.active .newTicket select[name="owner_id"] option').count
assert_equal(1, count, 'check if owner selection is empty per default') assert_equal(1, count, 'check if owner selection is empty per default')
select(
element = instance.find_elements(css: '.active .newTicket select[name="group_id"]')[0] browser: instance,
dropdown = Selenium::WebDriver::Support::Select.new(element) css: '.active .newTicket select[name="group_id"]',
dropdown.select_by(:text, data[:group]) value: data[:group],
mute_log: true,
)
sleep 0.2 sleep 0.2
end end
end end
if data[:priority] if data[:priority]
element = instance.find_elements(css: '.active .newTicket select[name="priority_id"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data[:priority]) css: '.active .newTicket select[name="priority_id"]',
sleep 0.2 value: data[:priority],
mute_log: true,
)
end end
if data[:title] if data[:title]
element = instance.find_elements(css: '.active .newTicket input[name="title"]')[0] set(
element.clear browser: instance,
element.send_keys(data[:title]) css: '.active .newTicket input[name="title"]',
sleep 0.2 value: data[:title],
clear: true,
mute_log: true,
)
end end
if data[:body] if data[:body]
#instance.execute_script('$(".active .newTicket div[data-name=body]").focus()') set(
sleep 0.5 browser: instance,
element = instance.find_elements(css: '.active .newTicket div[data-name=body]')[0] css: '.active .newTicket div[data-name=body]',
element.clear value: data[:body],
element.send_keys(data[:body]) clear: true,
mute_log: true,
)
# it's not working stable via selenium, use js # it's not working stable via selenium, use js
value = instance.find_elements(css: '.content .newTicket div[data-name=body]')[0].text value = instance.find_elements(css: '.content .newTicket div[data-name=body]')[0].text
@ -1675,11 +1721,12 @@ wait untill text in selector disabppears
end end
if data[:body] if data[:body]
#instance.execute_script('$(".content.active div[data-name=body]").focus()') set(
sleep 0.5 browser: instance,
element = instance.find_elements(css: '.content.active div[data-name=body]')[0] css: '.content.active div[data-name=body]',
element.clear value: data[:body],
element.send_keys(data[:body]) mute_log: true,
)
# it's not working stable via selenium, use js # it's not working stable via selenium, use js
value = instance.find_elements(css: '.content.active div[data-name=body]')[0].text value = instance.find_elements(css: '.content.active div[data-name=body]')[0].text
@ -1702,26 +1749,32 @@ wait untill text in selector disabppears
assert_equal(3, count, 'check if owner selection is - selection + master + agent per default') assert_equal(3, count, 'check if owner selection is - selection + master + agent per default')
else else
select(
element = instance.find_elements(css: '.active .sidebar select[name="group_id"]')[0] browser: instance,
dropdown = Selenium::WebDriver::Support::Select.new(element) css: '.active .sidebar select[name="group_id"]',
dropdown.select_by(:text, data[:group]) value: data[:group],
mute_log: true,
)
sleep 0.2 sleep 0.2
end end
end end
if data[:priority] if data[:priority]
element = instance.find_elements(css: '.active .sidebar select[name="priority_id"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data[:priority]) css: '.active .sidebar select[name="priority_id"]',
sleep 0.2 value: data[:priority],
mute_log: true,
)
end end
if data[:state] if data[:state]
element = instance.find_elements(css: '.active .sidebar select[name="state_id"]')[0] select(
dropdown = Selenium::WebDriver::Support::Select.new(element) browser: instance,
dropdown.select_by(:text, data[:state]) css: '.active .sidebar select[name="state_id"]',
sleep 0.2 value: data[:state],
mute_log: true,
)
end end
if data[:state] || data[:group] || data[:body] if data[:state] || data[:group] || data[:body]