RadRails IDE에서 테스트 할 때 watir을 사용합니다. 삭제 버튼을 클릭하면 "웹 페이지 메시지"메시지가 나타나 실제로 레코드 삭제를 확인합니다. 확인을 클릭하면 어떻게 시뮬레이션 할 수 있습니까? 다음 방법은 내가 시도 할 수 있습니다 : 1) ie=Watir::IE.new ie.execute_script("window.alert = function() {}") - have no effect
"웹 페이지에서 마사지"창에서 "확인"을 클릭하십시오.
2) ie1.button(:name, "delete_action").click ie4.execute_script("window.confirm = function() {return true}")
가져 오기 오류 - Task.rb:140:in '<main>: undefined local variable or method 'ie4' for main:Object (NameError)
3) ie1.button(:name, "delete_action").click ie1.execute_script("window.confirm = function() {return true}")
아무런 영향
4 유무)`데프 startClicker (버튼, 대기 시간 = 3)
w = WinClicker.new
longName = ie.dir.gsub("/" , "\\")
shortName = w.getShortFileName(longName)
c = "start rubyw #{shortName }\\watir\\clickJSDialog.rb #{button }
#{ waitTime} "
puts "Starting #{c}"
w.winsystem(c)
w=nil
end`
그리고 웹 페이지가 나타납니다에서 메시지 후
`ie1.button(:name, "delete_action").click
startClicker("OK" , 3)
ie.button("Submit").click`
을 넣어. 가져 오기 오류 : 시험의 시작에서
E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/modal_dialog.rb:3:in 'initialize': Watir no longer supports WinClicker. Please use click_no_wait and the javascript_dialog method. (NotImplementedError) from Task.rb:12:in 'new' from Task.rb:12:in 'startClicker' from Task.rb:162:in '<main>'
5) 코드
`데프 check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
loop do
ret = autoit.WinWait('Message from webpage', '', 1)
if (ret==1) then autoit.Send('{enter}') end
sleep(3)
end end`
Code after message from webpage appears
`ie1.button(:name, "delete_action").click
$popup = Thread.new { check_for_popups }
at_exit { Thread.kill($popup) } `
없음 반응.
6) ')
DEF startClicker (버튼있는 waittime = 9 USER_INPUT = 닐)
HWND = $ ie.enabled_popup (있는 waittime'Watir과 고전 \에있는 contrib의 \의 enabled_popup을 '필요
경우 (HWND)에서 메시지 후
w = WinClicker.new
if (user_input)
w.setTextValueForFileNameField(hwnd, "#{user_input}")
end
sleep 3
w.clickWindowsButton_hwnd(hwnd, "#{button}")
w=nil
end
end`
코드 웹 페이지가 나타납니다
`ie1.button (이름, "delete_action")는
startClicker을 click_no_wait ("OK", 7)`
가져 오기 메시지 - Task.rb:14:in
startClicker. '정의되지 않은 메서드 enabled_popup' for nil:NilClass (NoMethodError) from Task.rb:157:in
`
7) 웹 페이지에서 메시지 후 require 'watir/contrib/enabled_popup'
코드가 나타납니다 -
,691,363,210`HWND = browser.enabled_popup (5)
경우 (HWND)
팝업 = WinClicker.new
팝업.makeWindowActive (HWND)
popup.clickWindowsButton ("웹 페이지에서 메시지", "OK", "30")
end`
가져 오기 오류 - '에 E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/win32.rb:19:in
블록 : 1.9의 DL API를하지 1.8과 호환, http://www.ruby-forum.com/topic/138277 (NotImplementedError) E : /Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contrib/enabled_popup.rb에서 참조하십시오. 11 : in call' from E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contrib/enabled_popup.rb:11:in
enabled_popup의 블록 ' E : /Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/wait.rb : 18 : until' from E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contrib/enabled_popup.rb:10:in
enabled_popup' fr 톰 Task.rb : 145 :` 'Watir과 클래식 \에있는 contrib의 \의 enabled_popup'을 필요로)
8 <main>'
에서
데프 popupChecker (텍스트)
Timeout::timeout(2)do
begin
if $ie.enabled_popup
hwnd = ie.enabled_popup(5)
w = WinClicker.new
w.makeWindowActive(hwnd)
w.clickWindowsButton_hWnd(hwnd,text)
end
rescue Timeout::Error
puts 'No popup existed'
end
end
end`
코드 후 웹 페이지의 메시지가 나타납니다. -
ie1.button (: name, "delete_action"). 클릭 _no_wait
백45경1천5백15조5백36억9천1백36만3천2백10popupChecker ('OK')
ie1.wait`
얻기 메시지 : popupChecker에 Task.rb:13:in
블록 '미정 방법 enabled_popup' for nil:NilClass (NoMethodError) from E:/Ruby193/lib/ruby/1.9.1/timeout.rb:68:in
초과'Task.rb에서 : 11 : popupChecker' from Task.rb:158:in
에`
= "웹 페이지로부터의 메시지"9) 'DEF check_for_popups (제목, 버튼 = "OK")
popup=Thread.new {
autoit=WIN32OLE.new('AutoItX3.Control')
ret=autoit.WinWait(title,"",60)
if (ret==1)
puts "There is popup."
autoit.WinActivate(title)
button.downcase!
if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
autoit.Send("{Enter}")
else
autoit.Send("{tab}")
autoit.Send("{Enter}")
end
elsif (ret==0)
puts "No popup, please check your code."
end
}
at_exit { Thread.kill(popup) }
end`
,536,913,632 웹 페이지에서 메시지 후 10코드가 나타납니다 -
check_for_popups("Message from webpage", "OK")
어떤 반응
http://watir.github.io/docs/javascript-dialogs/ 감사합니다, browser.alert.ok을 작동하지 않습니다 (나는 경고 메시지가 메서드를 정의하지 않습니다)하지만 코드 browser.execute_script ("window.confirm = function() {true true} ")는 우수합니다 – khris