Script not working

P

Pranjal Jain

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.com/")
$ie.bring_to_front
$ie.maximize
$ie.text_field:)name, '{actionForm.username}').set($username.to_s)
$ie.text_field:)name, '{actionForm.password}').set($password.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 :)
 
B

Bira

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top