如果是弹出窗口页的话需要先把焦点转到这个窗口。
###A helper method to wait the popup window to be closed
#
def wait_close_popup_window
i=0
while page.driver.browser.window_handles.size > 1
sleep 0.3
i = i+0.3
if i > 3
break
end
end
end
##
#A helper method to wait the popup window to be opened
#
def wait_open_popup_window
i=0
while page.driver.browser.window_handles.size < 2
sleep 0.3
i = i+0.3
if i > 3
break
end
end
end
##
#A helper method to simplify the operation of popup window
# AdminBase.popup_window{
# page.execute_script "window.close()"
# }
#
def popup_window
wait_open_popup_window
popup = page.driver.browser.window_handles.last
within_window(popup) do
yield
wait_close_popup_window
end
end
把你需要在弹窗也处理的代码块替换yield就行了。
system(“.ruby”)或者load 'another.rb'具体代码如下:
# 返回ls的输出
s=`ls`
cmd= "ls"
s= `#{cmd}`
# 返回true or false
s= system('ls')
cmd= 'ls'
s= system(cmd)
#返回输出
s= %x[uptime]
#用top进程替换当前ruby进程
exec "top"
cmd = 'top'
exec cmd