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.
www.wipro.com
on 2012-12-05 07:33
on 2012-12-05 08:19
On 12/05/2012 07:33 AM, sachin.s32@wipro.com 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
on 2012-12-05 08:29
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... 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 Mueller [mailto:ralf.mueller@zmaw.de] *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, sachin.s32@wipro.com 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
on 2012-12-05 10:45
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 Mueller [mailto:ralf.mueller@zmaw.de]
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,
sachin.s32@wipro.com<mailto:sachin.s32@wipro.com> 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 2012-12-05 10:46
Thanks Sagy for the info provided... From: Sagy Drucker [mailto:sagy.drucker@trusteer.com] 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... 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 Mueller [mailto:ralf.mueller@zmaw.de<mailto:ralf.mueller@zmaw.de>] 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, sachin.s32@wipro.com<mailto:sachin.s32@wipro.com> 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
on 2012-12-05 11:31
On 12/05/2012 10:44 AM, sachin.s32@wipro.com 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.