# --------------------------------------------------------- # yahoologin.rb # Tester Name: Tobias Mayer # Project Name: TSRAPI Example # Create Date: 21 August 2005 # © Quality Forge, 2004-2005 # --------------------------------------------------------- require 'rubysmith' require 'win32ole' =begin ----------------------------------------------------------------------- Sample Ruby test-script demonstrating web page login. This script will login the user 'smith030615' to My Yahoo!, validate some text on the login page, attempt to validate some nonexistent text to show an error message example, logout the user and validate text on the logout page. ----------------------------------------------------------------------- =end class YahooLogin < RubySmith # TestSmith uses this variable name to display the report in the TestSmith report window @@REPORT_NAME = "reports\\rYahooLogin" # Run the YahooLogin test. # # Parameters # - data (no data required for this test) # # Return value # - a TestSmith exit code or -1 # def run(data = nil) # initialize the test begin initialized = initSession(@@REPORT_NAME) # to run without generating any TestSmith reports use: # int initialized = initSession() if (!initialized) # handle error... # use lastTSError() for errors generated by TSAPI # use lastRubyError() for errors generated by RubySmith return -1 end rescue InSessionException => ise # handle error, e.g. puts ise.to_s return -1 end # run the test begin lasterr = 0 # launch an IE Browser ie = WIN32OLE.new('InternetExplorer.Application') if (ie == nil) return -1 end ie.visible = true ie.navigate("http://my.yahoo.com/") # identify the IE browser window wtitle = "'My Yahoo! - Microsoft Internet Explorer'" lasterr = wndInit("id=1 wtitle=" + wtitle + " wclass=IEFrame wrect=MAXIMIZED zsync=s20 zinterval=s5") if (lasterr == noError) # id and wnum are the same for all calls window_id = " id=1 wnum={wnum} " # range and sync params are the same for most calls common_params = " hrange=-1 zsync=s10 zinterval=s2 " # Click sign-in link lasterr = htmlLink(window_id + " htag=A hidx=33 hhref~='login.yahoo.com/config/login','src=my' " + \ "hvistext='Sign In'" + common_params) # Enter name lasterr = htmlText(window_id + " htag=INPUT hidx=84 htype=text hname=login " + \ "hvalue=smith030615" + common_params) # Enter (obfuscated) password lasterr = htmlText(window_id + " htag=INPUT hidx=89 htype=password " + \ "hvalue=[!OBF!]/!*%2B&!#.%2B!#" + common_params) # click Submit button lasterr = htmlInput(window_id + " htag=INPUT hidx=93 htype=submit " + \ "hvalue='Sign In'" + common_params) # Validate the greeting/user name. lasterr = valHtmlText(window_id + " htag=P hidx=30 hoffset=0 " + \ " remark='Validate the greeting [Welcome, smith030615].'" + \ " hvistext='Welcome%cm smith030615'" + common_params) # This validation is intended to fail unknown = "non-existent text x!x!x!x!x!" lasterr = valHtmlText(window_id + " htag=B hidx=33 hoffset=0 " + \ " remark='validation for \"" + unknown + "\" is intended to fail.'" + \ " remark2='validation for \"" + unknown + "\" will have failed.'" + \ " hvistext='" + unknown + "' zsync=s5") # check for error (this can be done after any - or every - command) if (lasterr > noError) # handle error, e.g. end # Click the Sign Out link lasterr = htmlLink(window_id + " htag=A hidx=33 " + \ "hhref~='http://login.yahoo.com','logout=1' " + \ "hvistext='Sign Out'" + common_params) # Validate that sign out was successful. lasterr = valHtmlText(window_id + " htag=B hidx=49 hoffset=0 " + \ "hvistext='You have signed out of the Yahoo! network' " + common_params) # Close the IE Browser # lasterr = wndClose("id=1") end # end test exit_ok = exitSession() if (!exit_ok) # handle error, e.g. puts lastTSError() # for error generated by TSAPI end # full test ran without exceptions, so return self.exitCode rescue UninitializedException => ue # handle error, e.g. puts ue return -1 end end # run method end # class YahooLogin # ============================================================================= # TEST begin yahooLogin = YahooLogin.new() exitCode = yahooLogin.run() puts "exitCode: " + exitCode.to_s # uncomment next line to show the TestSmith report in a separate browser window # yahooLogin.displayReport() end # =============================================================================