[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Script not working

Pranjal Jain

5/6/2008 12:55:00 PM

HI All
I am having a script which is not working when I am writing it inside a
method
def addcomment. But when I am writing it outside the method; it starts
working. Can somebody explain me why this is so?

the script is as follows :

b = 0
$ie = IE.new
$ie.goto("https://tms.corp.xyz....)
$ie.bring_to_front
$ie.maximize
$ie.text_field(:name, '{actionForm.username}').set($username[b].to_s)
$ie.text_field(:name, '{actionForm.password}').set($password[b].to_s)
$ie.button(:name, 'actionOverride:validateLogin.do').click

if($ie.link(:class,"linkTableBody").exists?)

begin
$ie.link(:class,"linkTableBody").click
sleep 3
cw = IE.attach( :title, /Timesheet - Add Comments/i )
a = "Watir Automation using Ruby "
cw.text_field(:name,"{actionForm.resComm}").set(a)
cw.button( "Save Comments" ).click

if a.length >1024
puts "Number of characters exceed the space specified"

#check_for_popups()

startClicker( "OK ", 7 , "User Input" )

#cw.text_field(:name,"{actionForm.resComm}").clear
else
puts "nthng"
end
#cw.link( "javascript:window.close()" ).click
end
else
puts "Sorry"
end

thanks inadvance :)
--
Posted via http://www.ruby-....

1 Answer

Bira

5/7/2008 4:38:00 PM

0

On Tue, May 6, 2008 at 9:54 AM, Pranjal Jain <pranjal.jain123@gmail.com> wrote:
> HI All
> I am having a script which is not working when I am writing it inside a
> method
> def addcomment. But when I am writing it outside the method; it starts
> working. Can somebody explain me why this is so?

When you define a method, it's not automatically executed by Ruby. So,
if you want that code to run when the script is executed, you have to
call the method in the main body of the script (or just put the code
directly into the main body of the script, as you have done).

Example:

def add_comment
# code goes here
end

if __FILE__ == $0
add_comment # calls the method if we're running the script.
end

--
Bira
http://compexplicita.wor...
http://compexplicita....