Finding an outputting a string of text

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 :slight_smile: , 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)
    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
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
beginTime = Time.now
$ie.goto(testSite)
endTime = Time.now
timeSpreadsheet.puts executionEnvironment + “,UnitrinSpecialty.com,”

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

    scriptLog.puts ‘Step 2: enter "######: in the username field’
    $ie.textField(:name, “username”).set(“######”)
    scriptLog.puts ’ Action: entered ###### in the username field’

    scriptLog.puts ‘Step 3: enter in “######” in the password field.’
    $ie.text_field(:name, “password”).set(“#######”)
    scriptLog.puts ’ Action: entered in password “######”.’

    beginTime = Time.now
    scriptLog.puts ‘Step 4: click on the sign in button’
    $ie.button(:name, “Sign”).click
    scriptLog.puts ‘Expected Result: ’
    scriptLog.puts ’ The Agent Access Page should appear.’
    endTime = Time.now
    timeSpreadsheet.puts executionEnvironment + “,UnitrinSpecialty.com,”

  • (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