You need to comment or remove the unittests/setup line and assign $ie
to a new instance of IE, something like this (this is a simple
example, you might or might not want to restart ie after every test,
but should at least give you some idea of setup/teardown methods):

 $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
 #require 'unittests/setup'
 require 'test/unit'
 require 'watir/WindowHelper'
 require 'watir'
 require 'mysql'

 class TC_MYBOX_Login < Test::Unit::TestCase
         include Watir

    def setup
         # set variables and open site, this will run before every test case
         $host = '192.168.0.1'    - this is a fake host I'm using
another in the true test
         $user_login = 'test_demo'
         $ie = Watir::IE.start(test_site = 'http://'+ $host)
    end

    # this will run after every test case.
    def teardown
      $ie.close
    end

    def test_login
      .....
    end
        more test methods, etc.........
end


-Charley

On 11/3/06, Ralica Nacheva <[EMAIL PROTECTED]> wrote:
> Hello, I am quite new to Ruby and Watir I started writing some test cases and 
> I wanted to try to tie them into a test suite but unfortunately the example 
> shown in http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/ doesn't work 
> for me.
> My test suite is very simple - just for trying out. It has to execute two 
> test cases - login and logout, but when I execute it I get the following 
> errors:
>
>
> C:\watir-v1_4\myTests>ruby mybox_suite.rb
> c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in 
> `gem_original_re
> quire': no such file to load -- unittests/setup (LoadError)
>         from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in 
> `re
> quire'
>         from ./mybox_login1.rb:15
>         from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in 
> `re
> quire'
>         from mybox_suite.rb:6
>
>
> I'd like to get some explanation about how to write test cases, which can be 
> run separately and tied into a test suite. I have been reading for couple of 
> days articles and posts from blogs, forums, documentatin , etc., but I 
> haven't found a solution.
>
> Here is the content of my test suite:
>
> require 'test/unit/testsuite'
>  require 'mybox_login1'
>  require 'mybox_logout1'
>
>
>  class TS_MyTests
>    def self.suite
>      suite = Test::Unit::TestSuite.new
>      suite << TC_MYBOX_Login.suite
>      suite << TC_MYBOX_Logout.suite
>
>      return suite
>    end
> end
>
> And here is for example the login test:
>
> $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
> require 'unittests/setup'
> require 'test/unit'
> require 'watir/WindowHelper'
> require 'watir'
> require "mysql"
>
> class TC_MYBOX_Login < Test::Unit::TestCase
>         include Watir
>
>
>    # set variables
>         $host = '192.168.0.1'    - this is a fake host I'm using another in 
> the true test
>         $user_login = 'test_demo'
>
>   def test_login()
>    # set variables
>                 user_pass = '123';
>                 test_site = 'http://'+ $host
>
>                 # print some comments
>                 puts "## Beginning of test: 'Mybox Login'"
>                 puts " "
>
>                 puts "Step 1: go to the test site: " + test_site
>                 $ie.goto(test_site)
>
>                 puts "Step 2: enter '"+$user_login+"' in login field"
>                 $ie.text_field(:name, "login").set($user_login)
>
>                 puts "Step 3: enter '"+user_pass+"' in password field"
>                 $ie.text_field(:name, "password").set(user_pass)
>
>                 sleep 1
>
>                 puts "Step 4: click the 'Login' button"
>                 $ie.button(:name, "login_button").click
>
>                 puts "Expected Result: "
>
>                 puts "Actual Result: Check that the 'Log Out' link appears on 
> the results page"
>                 assert($ie.contains_text("Log Out"))
>         end
>
>  end
>
> When I comment the "require unittests/setup". Then I get:
>
>   1) Error:
> test_login(TC_MYBOX_Login):
> NoMethodError: undefined method `goto' for nil:NilClass
>     ./mybox_login1.rb:39:in `test_login'
>
>   2) Error:
> test_logout(TC_MYBOX_Logout):
> NoMethodError: undefined method `goto' for nil:NilClass
>     ./mybox_logout1.rb:51:in `test_logout'
>
> Thanx in advance :)
> ---------------------------------------------------------------------
> Posted via Jive Forums
> http://forums.openqa.org/thread.jspa?threadID=5078&messageID=14122#14122
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to