HI,

I have tried your code to capture text from popup window.
but i am getting a problem.
because of this line of ur code

assert_js_dialog do
 @ie.button(:value, "Alert test").click
end

it runs the script indefinately.

please solve my problem..

i tried this as...


##//////////////////////////////////////////////////////////////////////////////////////////////////
##
## Watir script
##
##//////////////////////////////////////////////////////////////////////////////////////////////////



####requires

require 'watir'
require 'test/unit'
require 'test/unit/ui/console/testrunner'
require 'test/unit/assertions'
#require 'watir/setFileDialog'
#require 'popups_test'
#require 'enabled_popup'


#logger requires
require 'example_logger1'
require 'workbookfunction'

#java_pophadler requires
require 'WindowHelper'
require 'win32ole'
require 'js_dialog'
#require 'winClickers'




####includes
include Watir

class TC_PSC_userlogin < Test::Unit::TestCase

  def start
  #open the IE browser
   $ie = IE.new

   #create a logger
   filePrefix = "logger"
   $logger = LoggerFactory.start_xml_logger(filePrefix)
   $ie.set_logger($logger)

   ##Excel file functions
   $lgn=Excel_file.new #making object of workbookfunction
   $wrk_sht=$lgn.ExcelOpen("c:\\PSC\\PSCuserlogin.xls")

   ##java popup hadling
   #$pop=Jave_PopUps.new ##making object of javapopup
 end


 #----- js_dialog.rb -----

#require 'win32ole'

#
# Use AutoIt to read and close Javascript dialog windows
#
module JavascriptDialog

   #
   # Target javascript dialogs with this window title
   #
   WINDOW_TITLE = "Microsoft Internet Explorer"

   class << self

       #
       # Return the text contained in a javascript dialog (e.g. an "alert()")
       # if such a dialog is present or appears within +wait_seconds+.
       #
       def text(wait_seconds = 1)
           # sleep 0.3
           autoit.WinWait(WINDOW_TITLE, nil, wait_seconds) if wait_seconds
           s = autoit.WinGetText(WINDOW_TITLE)
           s unless s == "1"
       end

       #
       # Close any active javascript dialog
       #
       def close
           autoit.WinClose WINDOW_TITLE
       end

       #
       # Press the "OK" button on a javascript dialog
       #
       def ok
           autoit.ControlClick(WINDOW_TITLE, "", "OK")
       end
       #
       # Press the "Cancel" button on a javascript dialog
       #
       def cancel
           autoit.ControlClick(WINDOW_TITLE, "", "Cancel")
       end
       #
       # Press the "Yes" button on a javascript dialog
       #
       def yes
           autoit.ControlClick(WINDOW_TITLE, "", "Yes")
       end
       #
       # Press the "No" button on a javascript dialog
       #
       def no
           autoit.ControlClick(WINDOW_TITLE, "", "No")
       end

       private

           #
           # Return an AutoIt COM object, creating it if it doesn't already
           # exist
           #
           def autoit
               unless defined? @@autoit
                   @@autoit = WIN32OLE.new("AutoItX3.Control")
               end
               @@autoit
           end
   end
end

module Test::Unit::Assertions
   #
   # Passes if a Javascript dialog appears within +wait_seconds+ and its
   # text matches the given (optional) pattern.
   #
   # Use like this:
   #  assert_js_dialog do
   #    watir_command_to_make_dialog_appear
   #  end
   # Or like this:
   #  assert_js_dialog /Text to find in the dialog/, "Cancel" do
   #    watir_command_to_make_dialog_appear
   #  end
   #
   def assert_js_dialog(pattern = //, action = "close", message = nil)
       _wrap_assertion do
           begin
               pipe = IO.popen("ruby exetry.rb #{action}")
               yield
               window_text = pipe.read rescue ""
               pipe.close
               unless window_text.empty?
                   assert_block(build_message(message,
                       "<?> not found in JavaScript dialog.", pattern)) do
                           window_text.match(pattern)
                   end
               else
                   raise Test::Unit::AssertionFailedError.new(
                       build_message(message, "No JavaScript window found."))
               end
           ensure
               pipe.close if pipe && !pipe.closed?
           end
       end
   end
end

# test - will close and print the text of an opened javascript dialog if
# run as "ruby js_dialog.rb"
if $0 == __FILE__
   action = ARGV.shift || "close"
   print JavascriptDialog.text || ""
   JavascriptDialog.send action
end






 def test_PSCLogin


 #call start method...
 start #fires up the IE browser and a logger object

 #variables-URL
  test_site = 'https://www.philipnow.com/envcss/'
 $logger.log("## PSCUser_Login_Logoff_4")
  $logger.log("")
  $logger.log("Description- Do not enter anything in the E-mail
Address and Password field and click Login button.") #logs only to
corelogger file
  $logger.log("Expected Output-The user should not be able to login.")
  $logger.log("")
  $logger.log("Step 1: Go to the Philipnow.com :-
'https://www.philipnow.com/envcss/'")
  $ie.goto(test_site)
  $logger.log(" Action-1: entered " + test_site + " in the address bar.")
  $logger.log(":Step 2: Do not enter any thing in user id")
  val_userid=$lgn.TakeData("a",1,$wrk_sht)
  $ie.text_field(:name, "username").set(val_userid.to_s)
  $logger.log("  Action-2: entered Nothing in in e-mail address")

  $logger.log(":Step-3: Do not enter any thing in password field")
  val_password=$lgn.TakeData("b",1,$wrk_sht)
  $ie.text_field(:name,"password").set(val_password.to_s)
  $logger.log(":Action-3: entered Nothing in password field")

  #$pop.startClicker("OK",3)

  assert_js_dialog do
   $ie.button(:name, "login").click
 end


  $logger.log(":Step-4: Click the Login button")

  $pop.text(1)
  $logger.log("Action-4: clicked the Login button.")


  begin
       assert($ie.contains_text("Welcome to Client Self-service
Portal, Alex Reyes!") )
       $logger.log("*FAILED*." + e.message + "\n" + e.backtrace.join("\n"))
       $logger.log("Test Failed:Expected result has not been
achieved:- User is able to login ")
       $logger.log_results( "PSCUser_Login_Logoff_4","Description-Do
not enter anything in the E-mail Address and Password field and click
Login button.","Expected Output-The user should not be able to
login.","TEST FAILED:") #logs to both the XML file and corelogger
  rescue => e
       $logger.log("Test Passed:Expected result has  been achieved:-
User is not able to login ")
       $logger.log_results( "PSCUser_Login_Logoff_4","Description-Do
not enter anything in the E-mail Address and Password field and click
Login button.","Expected Output-The user should not be able to
login.","TEST PASSED:") #logs to both the XML file and corelogger
     end

     $ie.close
     $logger.log("Close excel file")
  $lgn.excel_close
  $logger.log("Closed excel file")
  $logger.log "## End of test: PSC login\n"
end
end


please help!!!
Thanks in Advance

Regards and Thnaks
Shalini gupta
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to