Unable to run the program

Hey all,

I am novice into the world of ruby and trying to do a simple search with
the below program, but I am unable to run and no error is thrown. Can
somebody help me where I am going wrong?

require ‘watir’
include Watir

require ‘test/unit’

class Test_google_Search < Test::Unit::TestCase

def search

test_site = 'http://www.google.com'

            $ie = IE.new

            $ie.goto(test_site)

            $ie.text_field(:name, "q").set("pickaxe")
            $ie.button(:name, "btnG").click

            assert($ie.contains_text("Programming Ruby") )

end

end

-Sachin S. Uplaonkar

Please do not print this email unless it is absolutely necessary.

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

On 12/05/2012 07:33 AM, [email protected] wrote:

require ‘test/unit’

            $ie.text_field(:name, "q").set("pickaxe")

            $ie.button(:name, "btnG").click

assert($ie.contains_text(“Programming Ruby”) )

end

end

you just defined a class, no operation is performed here.
In this special case, it’s a child of Test::Unit, so you could run it
with

ruby this_file.rb
or
ruby this_file.rb --name=test_search

if you rename search to test_search

regards
ralf

There is no need to use both require and include for the class Watir.

http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.htm

Also,

Why do you define ie as Global Variable? (using $)

Seems to me its not necessary and you can omit the $.

Last thing,

It would be better practice to use:

assert_equal(Programming Ruby , $ie.text)

rather than

assert($ie.contains_text(“Programming Ruby”) )

Sagy

From: Ralf M. [mailto:[email protected]]
Sent: Wednesday, December 05, 2012 9:19 AM
To: ruby-talk ML
Subject: Re: Unable to run the program.

On 12/05/2012 07:33 AM, [email protected] wrote:

Hey all,

I am novice into the world of ruby and trying to do a simple search with
the below program, but I am unable to run and no error is thrown. Can
somebody help me where I am going wrong?

require ‘watir’

include Watir

require ‘test/unit’

class Test_google_Search < Test::Unit::TestCase

def search

test_site = 'http://www.google.com'



            $ie = IE.new



            $ie.goto(test_site)



            $ie.text_field(:name, "q").set("pickaxe")

            $ie.button(:name, "btnG").click



            assert($ie.contains_text("Programming Ruby") )

end

end

you just defined a class, no operation is performed here.
In this special case, it’s a child of Test::Unit, so you could run it
with

ruby this_file.rb
or
ruby this_file.rb --name=test_search

if you rename search to test_search

regards
ralf

Thanks Ralf… Its working now after changing the name of “def search to
def test_search”.

But want to know why def search didn’t work previously.

From: Ralf M. [mailto:[email protected]]
Sent: Wednesday, December 05, 2012 12:49 PM
To: ruby-talk ML
Subject: Re: Unable to run the program.

On 12/05/2012 07:33 AM,
[email protected]mailto:[email protected] wrote:
Hey all,

I am novice into the world of ruby and trying to do a simple search with
the below program, but I am unable to run and no error is thrown. Can
somebody help me where I am going wrong?

require ‘watir’
include Watir

require ‘test/unit’

class Test_google_Search < Test::Unit::TestCase

def search

test_site = 'http://www.google.com'

            $ie = IE.new

            $ie.goto(test_site)

            $ie.text_field(:name, "q").set("pickaxe")
            $ie.button(:name, "btnG").click

            assert($ie.contains_text("Programming Ruby") )

end

end

you just defined a class, no operation is performed here.
In this special case, it’s a child of Test::Unit, so you could run it
with

ruby this_file.rb
or
ruby this_file.rb --name=test_search

if you rename search to test_search

regards
ralf

Please do not print this email unless it is absolutely necessary.

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com

On 12/05/2012 10:44 AM, [email protected] wrote:

Thanks Ralf… Its working now after changing the name of “def search to def
test_search”.

But want to know why def search didn’t work previously.

In general a file with a class definition only does not perform
anything. It’s just a definition. Your class
defines a special unit test case and such classes are handled in a
special way by ruby. If you run such a
definition, all methods starting with ‘test_’ are started. This eases
the work with unit tests, because the
developer does NOT have to write the definitions AND the execution of
the test methods, but the definitions
only. To keep it flexible, a naming conventions has to exist to
destinguish between test methods (which should
be executed) and helper methods. There are other special methods like
“setup” and “teardown”, Have a look a
http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing to take the
first steps.

hth
ralf

Thanks Sagy for the info provided…

From: Sagy Drucker [mailto:[email protected]]
Sent: Wednesday, December 05, 2012 12:58 PM
To: ruby-talk ML
Subject: Re: Unable to run the program.

There is no need to use both “require” and “include” for the class
Watir.
http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.htm

Also,
Why do you define “ie” as Global Variable? (using $)
Seems to me it’s not necessary and you can omit the ‘$’.

Last thing,
It would be better practice to use:
assert_equal(“Programming Ruby” , $ie.text)
rather than
assert($ie.contains_text(“Programming Ruby”) )

Sagy

From: Ralf M.
[mailto:[email protected]mailto:[email protected]]
Sent: Wednesday, December 05, 2012 9:19 AM
To: ruby-talk ML
Subject: Re: Unable to run the program.

On 12/05/2012 07:33 AM,
[email protected]mailto:[email protected] wrote:
Hey all,

I am novice into the world of ruby and trying to do a simple search with
the below program, but I am unable to run and no error is thrown. Can
somebody help me where I am going wrong?

require ‘watir’
include Watir

require ‘test/unit’

class Test_google_Search < Test::Unit::TestCase

def search

test_site = 'http://www.google.com'

            $ie = IE.new

            $ie.goto(test_site)

            $ie.text_field(:name, "q").set("pickaxe")
            $ie.button(:name, "btnG").click

            assert($ie.contains_text("Programming Ruby") )

end

end

you just defined a class, no operation is performed here.
In this special case, it’s a child of Test::Unit, so you could run it
with

ruby this_file.rb
or
ruby this_file.rb --name=test_search

if you rename search to test_search

regards
ralf

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs