Re: [wtr-general] Re: Unable to call ruby script multiple times!!

2010-11-18 Thread chethan sarathy
Hi Chuck,

Thanks for your eye opening mail, I will change my scripting way. 
Once again Thanks for your valuable input about ruby scripting.

~Chethan

--- On Wed, 17/11/10, Chuck van der Linden  wrote:

From: Chuck van der Linden 
Subject: [wtr-general] Re: Unable to call ruby script multiple times!!
To: "Watir General" 
Date: Wednesday, 17 November, 2010, 10:39 AM

I think you are basically abusing a bit of a fluke in the way that
'require' works with an interpreted language like ruby.  By design
it's only going to 'execute' the 'require' step once, even if the flow
of the script causes it to be encoutered many times.  That's because
what 'require' is doing is pulling in the code in the specified file,
parsing it to define methods and such that it expects you to call from
your main script.  Because you have code not inside a method, it ends
up getting executed.

But Require is not intended as a way to execute code, but a way to
bring in methods (aka functions, code libraries etc) that you are
going to call from your script.  So seriously, STOP using require that
way or I'm going to get out the giant psycic 'STOP THAT!' cannon and
point it in your direction.  that's NOT how it's done, even if you
think it's working for you, STOP IT!..

If you want to do things this way you are going to have to define
almost the entire contents of those other files as a method by putting
a 'def  (parameters)' statement very near the top, and an
END down at the bottom.   Then you can call that method.  READ THIS:
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_methods.html

My example presumed that you were defining the other scripts as
methods.  it then CALLED those methods inside a loop to execute them
multiple times

If you have code you need to use in multiple places, or to call over
and over, this is generally how it's done.. define the code as a
method, require the file that has that method in it.  call the method
when/where needed.  Many times methods are associated with objects,
and are designed so the object can do appropriate things (a bit like
telling the dishwasher to start the wash cycle, or asking a dish 'are
you dirty?')  but I'm getting into the idea of object oriented
programming and that's a bit beyond the scope here.  For the moment
all that's important is to understand that making those other scripts
into methods, and then calling the methods is the way to go here.

 You can also try Load as Zeljko suggests

That might look something like:

10.times do
  load  'Ft_001'
end

Either way, It seems you need to learn a bit more about the Ruby
language.  I'd recommend reading the ebook that ruby installs as part
of it's help, or getting a copy of a good tutorial such as 'Everyday
scripting with Ruby'  I find the 'veryday scripting' book to be ideal
for testers, many of the examples are useful on your regular work.


On Nov 14, 6:29 am, chethan sarathy  wrote:
> Hi Thanks for Helping me on this,
>
> Sorry I couldn't give you full picture, I have made my test case in one 
> script .rb file & i will Call using require command
> Some thing like this
>
> require ' TestCase_001'
> require 'TestCase_002'
>
> These will be ran through one .rb file
>
> This will run perfectly but I got only one problem I am not able to run these 
> test cases multiple times. I tried your idea of (10.times do) still unlucky :(
>
> Thanks again,
> Chethan
>
> --- On Fri, 12/11/10, Chuck van der Linden  wrote:
>
> From: Chuck van der Linden 
> Subject: [wtr-general] Re: Unable to call ruby script multiple times!!
> To: "Watir General" 
> Date: Friday, 12 November, 2010, 1:49 PM
>
> In Ft_001 wrap all your code in a method definition
>
>  def  Ft_001
>    
>  end
>
> The for the other script do this
>
>  require 'Ft_001'
> 10.times do
>    Ft_001()
>  end
>
> If you need to sleep after the execution you can put that in.   If you
> need to use the value of 'i' inside your script then it changes only a
> little
>
> First, Your definition needs to contain i
>
> def Ft_001(i)
>
> Then the calling script then looks like this
>
>  require 'Ft_001'
> 10.times do |i|
>    Ft_001(i)
>  end
>
> On Nov 11, 11:35 pm, chethan sarathy  wrote:
>
>
>
>
>
> > here is my code
>
> > @i = 1
>
> > begin
>
> >   require 'Ft_001' # This is my script
> >   sleep(10)
> >   
> >   @i = @i+1
> >   
> >  end while @i < 10
>
> > Thanks,
> > Chethan
>
> > --- On Wed, 10/11/10, Željko Filipin  wrote:
>
> > From: Željko Filipin 
> > Subject: Re: [wtr-general] Unable to call ruby script multiple times!!
> > To: watir-general@googlegroups.com
> > Date: Wednesday, 10 November, 2010, 2:28 PM
>
> > On Wed, Nov 10, 2010 at 6:16 AM, Chethan  wrote:
> > > But I am unable to execute multiple times.
>
> > Show us the code.
>
> > Željko
> > --
> > watir.com - community manager
>
> > watirpodcast.com - host
> > testingpodcast.com - audio podcasts on software testing. all of them
>
> > --
>
> > Before posting, please readhttp://watir.com/support. In short: search 

Re: [wtr-general] Re: Unable to call ruby script multiple times!!

2010-11-14 Thread chethan sarathy
Hi Thanks for Helping me on this,

Sorry I couldn't give you full picture, I have made my test case in one script 
.rb file & i will Call using require command
Some thing like this

require ' TestCase_001'
require 'TestCase_002'

These will be ran through one .rb file

This will run perfectly but I got only one problem I am not able to run these 
test cases multiple times. I tried your idea of (10.times do) still unlucky :(

Thanks again,
Chethan


--- On Fri, 12/11/10, Chuck van der Linden  wrote:

From: Chuck van der Linden 
Subject: [wtr-general] Re: Unable to call ruby script multiple times!!
To: "Watir General" 
Date: Friday, 12 November, 2010, 1:49 PM

In Ft_001 wrap all your code in a method definition

 def  Ft_001
   
 end

The for the other script do this

 require 'Ft_001'
10.times do
   Ft_001()
 end

If you need to sleep after the execution you can put that in.   If you
need to use the value of 'i' inside your script then it changes only a
little

First, Your definition needs to contain i

def Ft_001(i)

Then the calling script then looks like this

 require 'Ft_001'
10.times do |i|
   Ft_001(i)
 end



On Nov 11, 11:35 pm, chethan sarathy  wrote:
> here is my code
>
> @i = 1
>
> begin
>
>   require 'Ft_001' # This is my script
>   sleep(10)
>   
>   @i = @i+1
>   
>  end while @i < 10
>
> Thanks,
> Chethan
>
> --- On Wed, 10/11/10, Željko Filipin  wrote:
>
> From: Željko Filipin 
> Subject: Re: [wtr-general] Unable to call ruby script multiple times!!
> To: watir-general@googlegroups.com
> Date: Wednesday, 10 November, 2010, 2:28 PM
>
> On Wed, Nov 10, 2010 at 6:16 AM, Chethan  wrote:
> > But I am unable to execute multiple times.
>
> Show us the code.
>
> Željko
> --
> watir.com - community manager
>
> watirpodcast.com - host
> testingpodcast.com - audio podcasts on software testing. all of them
>
> --
>
> Before posting, please readhttp://watir.com/support. In short: search before 
> you ask, be nice.
>
>  
>
> watir-general@googlegroups.com
>
> http://groups.google.com/group/watir-general
>
> watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com