Friday, 15 March 2013

Selenium Webdriver using Ruby: write text to file -



Selenium Webdriver using Ruby: write text to file -

i write text file multiple times (appending). using: in scenario captured scheme time in endtime , starttime.

file.open("c:\\temp\\myfile.txt", "w").write("my first input: #{endtime-starttime} seconds \n")

i go on multiple times in various places in script not seem working correctly. text file seems writing on itself. there way in script write text in different rows?

thanks, scott

here's improve example

#------------------------------------------------------------------------------------------------ --------------------- #log scheme #--------------------------------------------------------------------------------------------------------------------- starttime=time.new loginbutton = driver.find_element(:xpath, "/html/body/div[3]/div/div[2]/ul/li[3]/a") loginbutton.click alternative = 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" alternative = driver.find_element(:id, "password") option.send_keys"blah" alternative = 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 of study #--------------------------------------------------------------------------------------------------------------------- starttime=time.new driver.switch_to.frame "contentframe" #sets focus on "ur courses online module" alternative = driver.find_element(:link_text, "performance test course") option.click endtime=time.new puts"performance test course of study link: #{endtime-starttime} seconds" file.open("c:\\temp\\myfile.txt", "w").write("performance test course of study link: #{endtime-starttime} seconds \n") puts"performance test course of study done"

you want store open file object in variable when write new line file written end. previous code open given file write line @ position 0 in file close file.

file = file.open("text.txt", "w")

file.write "hello world"

or can utilize "a" flag opens file write @ end of file.

file.open("c:\\temp\\myfile.txt", "a+").write("my first input: #{endtime-starttime} seconds \n")

ruby webdriver

No comments:

Post a Comment