Question on watir

If you want to just double click the file and run it then you can
associate ".rb" files with the Ruby interpreter.

If you want an executable, look up http://rubyforge.org/projects/ocra/

···

--
Posted via http://www.ruby-forum.com/.

Ok thank you.

···

--
Posted via http://www.ruby-forum.com/.

Hi,

I am running the 500 test cases. In this, if server has been down for
sometime,we couldn't access the web page,So watir fails to access the
web page, and it stops it's running. and then again i need to start the
process manually as soon as server has been up,Is there any way we can
avoid this manual interference,what i meant to say,Can we make our
program for continual checking until server has been up and then it has
to start the program automatically?

Raj

···

--
Posted via http://www.ruby-forum.com/.

Rather than tell you how to fix your specific problem, I'll give you a
link on how to handle Exceptions; so you can broaden your knowledge and
apply it appropriately.
http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/

···

--
Posted via http://www.ruby-forum.com/.

Ok Thank you.

···

--
Posted via http://www.ruby-forum.com/.

hi,

They have explained how can we handle the exception. Now, my question
is, I am working in a big project, there are many screens, we have
written unique script for each and every screen. So the server may fails
to respond at any time or at any script while execution. So how can i
write the exception common for all screen? My ultimate goal is, i need
to inform the user that server has been down at this test case. how
would i do this?

Raj.

···

--
Posted via http://www.ruby-forum.com/.

It depends what you mean by "screens". If you're referring to the
different pages your script is accessing and the scripts are all running
on the same machine, you can join your tests into a single environment
so that the error handler can encapsulate all of them. Look into using a
Class or Module.

If you mean you're running individual scripts on different machines,
then you have the option of placing a log file in a shared location
which any failing routine can append to, so that you can trace errors
after the tests have been run, or check the file before running the
tests to see whether this iteration has already failed and can be
skipped.

···

--
Posted via http://www.ruby-forum.com/.

hi Joel Pearson

Thank you, I am running in a single machine, For each screen I have
defined corresponding function,when one particular screen has to be
automated, corresponding function will be invoked. Basically, from one
function all other function are getting called. And I haven't thought
class usage anyway. I will try put it in class as packed one. Thank you
for you suggestions.

Raj

···

--
Posted via http://www.ruby-forum.com/.

Hi ,

could you please write the small code about how to write the exception
handling inside the class common to all function.?

Raj

···

--
Posted via http://www.ruby-forum.com/.

You basically have 2 options...

You can handle the exception only at parent level and not bother with
local error trapping:

···

______________________
begin

  def method1
    #Content
  end

  def method2
    #Content
  end

  method1
  method2

rescue
  #Handle exception
end
______________________

Or you could handle each exception at a local level and then hand it up
to the next handler:
______________________
begin

  def method1
    #Content
  rescue
    #Do something here
    raise #Pass the error up to the next level
  end

  def method2
    #Content
  rescue
    #Do something here
    raise #Pass the error up to the next level
  end

  method1
  method2

rescue
  #Handle exception
end
______________________

You don't strictly need a class, a parent method would do but building a
class system allows you to avoid rewriting the same code repeatedly by
dealing with variables as arguments and leaving the surrounding
structure as part of your methods. For more info on this, look up DRY
(Don't Repeat Yourself).

--
Posted via http://www.ruby-forum.com/.

Hi Thank you so much, what do you mean by "don't repeat yourself"?

···

--
Posted via http://www.ruby-forum.com/.

Regarding DRY,
I know that when running Watir tests from different scripts you'll be
rewriting a lot of the same code, like starting and closing the browser,
for example. By using a single running environment (or requiring tools),
you can set up the repetitive tasks into methods, meaning you need only
write the code once.
Unless of course you're ahead of the game and you're only writing the
unique steps into each of your scripts while requiring the common
methods from elsewhere, in which case you can ignore me :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

OK Thank you.

···

--
Posted via http://www.ruby-forum.com/.

hi,

please consider this code below

these three function has been written in separate page.
def fun2
end

def fun3
end

def fun4
end

···

________________________________
def fun1(argument)
        begin
          if(argument == this)
               fun2
          end
        end
        begin
          if(argument == some)
                fun3
          end
        end
        begin
         if(argument == something)
          fun4
         end
        end
rescue
#some statement
end
____________________________________
class fun
    for loop
       fun1(argument)
    end
end

I hope you can understand above simple structure of my program.when the
first time "fun1" called,assume inside the fun1, fun3 is getting called,
and now if server has been down, execution should not continue, but it
has to be terminated. But regardless of server state, program continues
to execute.could you give me suggestion where to put this exception to
avoid this execution?

Another problem is, if server has not been down, and there is some error
in function, it has to terminate the funtion, but next execution has to
continue. So how could I handle this situation?

Raj

--
Posted via http://www.ruby-forum.com/.

class MyTestClass

  method1
    #Do stuff
  end

  method2
    #Do stuff
  end

rescue
  #Do stuff here
end

you gave this example for writing exception inside the class, but it is
not working for me, consider the program below,

class Raj
  def hello
    puts 'hello'
    1/0
        end
        def hi
    puts 'hi'
  end

rescue Exception => e
    puts 'the exception has been raised'
end

a=Raj.new
a.hello
a.hi

Here exception error of division by 0 is not caught by exception, why it
is so?

Raj

···

--
Posted via http://www.ruby-forum.com/.

You're rescuing the exceptions inside fun1, but your loop inside class
fun will continue because you're not passing the exception any higher.

Catch specific types of exceptions.
http://wtr.rubyforge.org/rdoc/1.6.5/classes/Watir/Exception.html
This one should cover server outages: Watir::Exception::TimeOutException

You're kind of missing the point with the class, it's intended to
encapsulate your methods.

Also this:

···

_____________________

def fun1(argument)
        begin
          if(argument == this)
               fun2
          end
        end
        begin
          if(argument == some)
                fun3
          end
        end
        begin
         if(argument == something)
          fun4
         end
        end
rescue
#some statement
end
_____________________

is equivalent to this:

_____________________

def fun1(argument)

  if argument == this
    fun2
  elsif argument == some
    fun3
  elsif argument == something
    fun4
  end

rescue
  #some statement
end
_____________________

--
Posted via http://www.ruby-forum.com/.

irb(main):013:0> begin
irb(main):014:1* Raj.new.hello
irb(main):015:1> rescue
irb(main):016:1> puts 'the exception has been raised'
irb(main):017:1> end

Yes I understood now.

I have another here,

please have a look at this code

···

------------------------------------------
class Raj
  def hi
  raja
  gopal
  hello
  end
def raja
  puts 'raja'
end
def gopal
        begin
  puts 'gopal'
  1/0
  rescue Exception =>e
  puts e
        end
end
def hello
  puts 'hello'
end
end

begin
Raj.new.hi
rescue Exception => e
puts e
end
-------------------------------------------

here, the exception has been caught at the gopal function,So the
exception which I have written for entire class hasn't been invoked. So
next hello also was called. But hello should not be invoked in my case,
meanwhile I couldn't take exception handling which is within gopal
function because it has some other need. what can I do to solve this
problem?

--
Posted via http://www.ruby-forum.com/.

If you want the Exception to be passed up to the next level...
Instead of this:

  1/0
rescue Exception =>e
  puts e

do this:

  1/0
rescue Exception =>e
  puts e
  raise

A local rescue would be used if you wanted to do something specific to
that method, otherwise just don't rescue it there, it'll be picked up by
the error handler you're using at the top level.

···

--
Posted via http://www.ruby-forum.com/.

Ok thank you ,it's very helpful.

Raj

···

--
Posted via http://www.ruby-forum.com/.

Yep, thank you very much, I exactly understood.

Raj

···

--
Posted via http://www.ruby-forum.com/.