index = 0
while index < value.length
len = value[index] > 128 ? 2 : 1
yield value[index, len]
index += len
end
end Step 2.同一個檔案修改Method doKeyPress 為 def doKeyPress(value)
value = limit_to_maxlength(value)
characters_in(value) { |c|
sleep @container.typingspeed
@o.value = @o.value.to_s + c
@o.fireEvent("onKeyDown")
@o.fireEvent("onKeyPress")
@o.fireEvent("onKeyUp")
}
end 原先的程式碼先Mark 或直接取代 接下來即可測試 # the Watir controller
require "watir"
# set a variable
test_site = "http://www.google.com" # open the IE browser
ie = Watir::IE.new # print some comments
puts "Beginning of test: Google search." puts " Step 1: go to the test site: " + test_site
ie.goto test_site puts " Step 2: enter '跳樓大拍賣' in the search text field."
ie.text_field(:name, 'q').set('跳樓大拍賣') # "q" is the name of the search field 不會又是只抓中文第一個字的前半個Byte啦
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/