# Finding an outputting a string of text

**URL:** <https://www.ruby-forum.com/t/finding-an-outputting-a-string-of-text/95064>\
**Category:** Ruby\
**Created:** [January 11, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/finding-an-outputting-a-string-of-text/95064 "2006-01-11T22:40:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/finding-an-outputting-a-string-of-text/95064/1 "2006-01-11T22:40:07Z")

</div>

Thanks in advance for any help you folks can provide.

Using Ruby + Watir, I’ve written a script that launches IE, goes to my  
company’s web site, and logs in, also recording the time for each  
transaction.

I cannot figure out how to do one last thing though, I need to capture  
a string of text that will always begin with “server” and output it to  
the csv I am outputting to .This string of text is always at the bottom  
our our web site. Below you’ll find my attempt at a script 🙂 , any  
ideas you may have are greatly appreciated.

-Jim

sciprt begins here.

=begin  
#############################################  
This script is intended to test logging in as an agent

1. Opens a browser window  
2.inserts a URL([unitrinspecialty.com](http://unitrinspecialty.com))  
3.Inserts a Username  
4.Inserts a Password
2. Clicks the login button
3. Verifies a text string on the page  
##############################################  
=end  
#includes  
require ‘watir’ # the watir controller  
require ‘time’ #time functionality

#variables  
testSite = ‘[http://www.unitrinspecialty.com](http://www.unitrinspecialty.com)’  
executionEnvironment = ‘Production’  
beginTime = 0  
endTime = 0  
d = Time.now.strftime(“%m/%d/%y%t,%I:%M:%S-%p,”)

#create a new log file  
scriptLog = File.new(“Agent-Login1.log”, “w”) # This file will be  
overwritten each time the script is run

#open spreadsheet  
timeSpreadsheet = File.new( “AgentLogin1#” +  
Time.now.strftime(“%d-%b-%y”) + “.csv”, “a”) #Note this will create a  
new file every day…

scriptLog.puts ‘## Beginning of test: Agent-Login1’  
scriptLog.puts ’ ’

#open the IE browser  
$ie = Watir::IE.new  
#action section  
scriptLog.puts ‘Step 1: go to the Unitrin Specialty website:  
[www.UnitrinSpecicialty.com](http://www.UnitrinSpecicialty.com)’  
beginTime = Time.now  
$ie.goto(testSite)  
endTime = Time.now  
timeSpreadsheet.puts executionEnvironment + “,[UnitrinSpecialty.com](http://UnitrinSpecialty.com),”

- (endTime - beginTime).to\_s + “,Time to load home page,” + d  
scriptLog.puts ’ Action: entered ’ + testSite + ’ in the address  
bar.’

- (endTime - beginTime).to\_s + “,Time to login,” + d  
#Results  
scriptLog.puts ‘Actual Result: Check that the page contains the text  
“Using Agent Access”’  
a = $ie.pageContainsText(“Using Agent Access”)  
if !a  
scriptLog.puts ‘Test Failed! Could not locate “Using Agent Access”  
in the page’  
else  
scriptLog.puts ‘Test Passed. Found “Using Agent Access” on the page  
after logging in’  
end

#cleanup  
scriptLog.puts ‘Close the browser’  
$ie.close()  
scriptLog.puts ’ ’  
scriptLog.puts ‘##End of test:Agent-Login1’  
scriptLog.close  
timeSpreadsheet.close
