我想多次將文本寫入文件(附加)。 目前我正在使用:在這種情況下,我在endtime和starttime中捕獲了系統時間。使用Ruby的Selenium Webdriver:將文本寫入文件
File.open("c:\\temp\\myfile.txt", "w").write("My first input: #{endtime-starttime} seconds \n")
我想在我的腳本的各個地方繼續多次,但它似乎沒有正常工作。該文本文件似乎在自己寫。腳本中有不同的行寫文本的方法嗎?
感謝, 斯科特
這裏有一個更好的例子
#------------------------------------------------------------------------------------------------ ---------------------
#Log into System
#---------------------------------------------------------------------------------------------------------------------
starttime=Time.new
LoginButton = driver.find_element(:xpath, "/html/body/div[3]/div/div[2]/ul/li[3]/a")
LoginButton.click
option = driver.find_element(:xpath, "/html/body/div/div[1]/div/div[3]/div[1]/form/div[3]/ul/li[1]/input")
option.send_keys"blah"
option = driver.find_element(:id, "password")
option.send_keys"blah"
option = driver.find_element(:xpath, "/html/body/div/div[1]/div/div[3]/div[1]/form/div[3]/ul/li[3]/input")
option.click
endtime=Time.new
puts"Login: #{endtime-starttime} seconds"
File.open("c:\\temp\\myfile.txt", "w").write("Login: #{endtime-starttime} seconds \n")
puts"Login Done"
#---------------------------------------------------------------------------------------------------------------------
#Performance Test Course
#---------------------------------------------------------------------------------------------------------------------
starttime=Time.new
driver.switch_to.frame "contentFrame" #Sets focus on the "UR Courses Online Module"
option = driver.find_element(:link_text, "Performance Test Course")
option.click
endtime=Time.new
puts"Performance Test Course Link: #{endtime-starttime} seconds"
File.open("c:\\temp\\myfile.txt", "w").write("Performance Test Course Link: #{endtime-starttime} seconds \n")
puts"Performance Test Course Done"
附加代碼示例: – user3531858 2014-11-03 14:45:16