Now I can state the general rule: to make software controllable, pass concrete parameters when tests don't need much flexibility and pass abstract parameters when they need more flexibility.- Kent Beck
A great read
Where you are is where you are at...
Now I can state the general rule: to make software controllable, pass concrete parameters when tests don't need much flexibility and pass abstract parameters when they need more flexibility.- Kent Beck
function watch_keys(evt) {
if ((evt.keyCode >= 32) && (evt.keyCode < 127)) {
//other work...
Event.stop(evt);
}
}
Event.observe(window, 'load', function() {
Event.observe($('some_input_id'), 'keypress', watch_keys);
}
def doKeyPress(value)
value = limit_to_maxlength(value)
for i in 0 .. value.length - 1
sleep @container.typingspeed
c = value[i,1]
@o.value = @o.value.to_s + c
@o.fireEvent("onKeyDown")
@o.fireEvent("onKeyPress")
@o.fireEvent("onKeyUp")
end
end
module Watir
class IE
def run_script(js)
ie.Document.parentWindow.execScript(js)
end
def send_some_keys(ele, text)
ele.focus
run_script("var wtr_evt=document.createEventObject();"+
"var wtr_ele=$('#ele.id}');");
text.scan(/./) do |char|
run_script("wtr_evt.keyCode='#{char}'.charCodeAt(0);"+
"wtr_ele.fireEvent('onkeypress', wtr_evt);");
end
end
end
^+e::
WinGetActiveTitle, Title
IfWinExist Console
{
WinActivate
SendInput {Up}
SendInput {Enter}
WinActivate, %Title%
}
irb(main):001:0> require 'Watir'
=> true
irb(main):002:0> include Watir
=> Object
irb(main):003:0> ie = IE::start_process('www.google.com')
=> #<Watir::IE:0x2c7d86c ....>
irb(main):006:0> ie.div(:id, 'gbar').id
=> "gbar"
irb(main):007:0> ie.div(:id=>'gbar').id
=> "gbar"
irb(main):008:0> ie.text_field(:name, 'q').id
=> ""
irb(main):009:0> ie.text_field(:name, 'q').name
=> "q"
irb(main):010:0> ie.text_field(:name=>'q').name
TypeError: {:name=>"q"} is not a symbol
irb(main):011:0>
require 'watir'
module Watir::Container
alias :old_locate_input_element :locate_input_element
#form elements do not allow the hash syntax for how/what.
#this change here allows it for single element hashes by
#just converting the hash into a distinct how and what and then
#passing it on
def locate_input_element(how, what, types, value=nil)
how, what = *how.to_a[0] if (how.kind_of? Hash) && (how.length == 1)
old_locate_input_element(how, what, types, value)
end
end
require 'watir'
require 'dynamic_finder.rb'
include Watir
ie = IE::start_process('www.google.com')
p ie.div_by_id(/gbar/).id # ie.div(:id => /gbar/)
p ie.span_by_class(/gb1/).text # ie.span(:class => /gb1/)
p ie.span_by_class_and_index(/gb1/, 2).text # ie.span(:class => /gb1/, :index=>2)
p ie.span_by_index(2).text # ie.span(:index => 2)
p ie.text_field_by_index(1).name # ie.text_field(:index,1)
ie.text_field_by_name("q").set('watir')
ie.button_by_value('Google Search').click
2.times do
ie.link_by_text(/Watir Tutorial/).click
end
ie.close