hi,
this is simplest code that you can have:
start_jsalert_clicker
$ie.button(:name,[some_name]).click
read_js_popup_contents
# This only clicks ok button. Change teh path accordingly.
def start_jsalert_clicker
Thread.new{ system("rubyw
\"d:\\installations\\ruby\\lib\\ruby\\gems\\1.8\\gems\\watir-
1.5.1.1145\\unittests\\jscriptExtraAlert.rb\"") }
end
# read file contents
def read_js_popup_contents
file = File.open("c:\\popup.txt")
lines = file.readline
while lines == ""
lines = file.readline
end
lines = file.readlines
file.close
return lines
end
You need to modify WindowHelper.rb (in watir directory) class to enter text
into the file before clicking OK button.
def push_alert_button
@autoit.WinWait "Windows Internet Explorer", ""
text = @autoit.WinGetText "Windows Internet Explorer"
file = File.open("c:\\popup.txt", "w")
file.puts text
file.close
@autoit.Send "{ENTER}"
end
Hope this helps
- Angrez
On 4/26/07, SHALINI GUPTA <[EMAIL PROTECTED]> wrote:
hi,
please some one reply..
its urgent..
Regards
Shalini Gupta
On 4/26/07, SHALINI GUPTA < [EMAIL PROTECTED]> wrote:
>
> Hi,
>
> my code is as...
>
>
> ####requires
>
> require 'watir'
> #require 'autoit'
>
> 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 'javapopup'
> #require 'winClickers'
>
>
>
>
> ####includes
> include Watir
>
>
> class TC_PSC_userlogin < Test::Unit::TestCase
>
> def startClicker( button , waitTime = 3)
> w = WinClicker.new
> longName = $ie.dir.gsub("/" , "\\" )
> shortName = w.getShortFileName(longName)
>
> c = "start ruby #{shortName}\\watir\\clickJSDialog.rb #{button}
> #{waitTime} "
> puts "Starting #{c}"
> w.winsystem(c)
> w=nil
> ###end of function StartClicker
> end
>
> def text(wait_seconds = 2)
> sleep 0.3
> autoit = WIN32OLE.new("AutoItX3.Control ")
> autoit.WinWait("Microsoft Internet Explorer", nil,
> wait_seconds) if wait_seconds
> s = autoit.WinGetText("Microsoft Internet Explorer")
> file = File.open ("c:\\test.txt", "w") # DONT MAKE
> YOUR VARIABLES GLOBAL UNNECESSARILY
> file.puts(s.to_s)
> puts s
> file.close
> #s unless s == "1" # NOT SURE WHY YOU ARE DOING
> THIS
> end
>
> 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
> #$oPopup = Watir::autoit
> 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/'<https://www.philipnow.com/envcss/%27>
> ")
> $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")
>
>
> =begin oPopup = Watir::autoit
> # Change into the WinTitleMatchMode that supports classnames
> and handles
> oPopup.AutoItSetOption("WinTitleMatchMode", 4)
> 0.upto (timeout) { |i|}
> ret = oPopup.WinWait("Microsoft Internet Explorer","",1)
> win_text = oPopup.WinGetText("Microsoft Internet
> Explorer")
> if 1 == ret && !(win_text == '') then
> bPopupFound = true
> oPopup.WinActivate("Microsoft Internet Explorer",'')
> win_text = oPopup.ControlGetText(what, '',
> 'Static2').strip
> if '' == win_text then win_text =
> oPopup.ControlGetText(what, '', 'Static1').strip end
> break
> =end
>
> startClicker("OK",3)
>
> #require 'js_dialog'
> #assert_js_dialog do
>
> $ie.button(:name, "login").click
> text(2)
>
> #end
>
>
>
> $logger.log(":Step-4: Click the Login button")
>
>
> $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
> Regards
> shalini gupta
>
>
>
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general