0

I have 66 watir scripts that I have been creating over the past week to automate testing on the clients website.

However I have recently found out about a test framework called MiniTest which I am trying to implement now.

The reason I have set the URL as a variable is because there are 5 different sites that these tests need to run on so when they want me to run my pack on a different website I just need to update that 1 variable and not in each individual test.

require 'minitest/autorun'
require "watir-webdriver"

class MPTEST < MiniTest::Unit::TestCase

def setup()
    url = "http://thewebsite.com/"
    $browser = Watir::Browser.new :chrome
    $browser.goto url
end

def test_myTestCase
    $browser.link(:text, "Submit your CV").click
    sleep(2)
    $browser.button(:value,"Submit").click
    assert($browser.label.text.includes?("This field is required"))

def teardown
    $browser.close
end

end

When running that I receive the following output:

NameError: undefined local variable or method 'browser' for #<MPTEST:0x4cc72f8>c:/directory stuff...

Any ideas?

EDIT I have browser working however now there is an issue with my assert:

New code:

require 'minitest/autorun'
require "watir-webdriver"

class MPTEST < MiniTest::Unit::TestCase

def setup()
    url ="http://thewebsite.com"
    $browser = Watir::Browser.new :chrome
    $browser.goto url
end

def test_myTestCase
    $browser.link(:text, "Submit your CV").click
    sleep(2)
    $browser.button(:value,"Submit").click
    assert($browser.label.text.includes?("This field is required"))
end

def teardown
    $browser.close
end

end

And the error is:

NoMEthodError: undefined method 'includes?' for "":String
CustomNet
  • 732
  • 3
  • 12
  • 31
  • Are you sure that the exception is coming from this part of the code? The exception suggests you have a `browser.something` somewhere instead of the `$browser.something` (ie missing the `$`). – Justin Ko Oct 31 '13 at 13:12
  • Well this is all of the code and I can't see any browser missing the $ – CustomNet Oct 31 '13 at 15:47

2 Answers2

1

it seems to me you can you use @browser instead of $browser (but the problem might be not in this code)

gotva
  • 5,919
  • 2
  • 25
  • 35
0

The exception

NoMEthodError: undefined method 'includes?' for "":String

Is due to strings, in this case the value returned by $browser.label.text do not have an includes? method.

The method you actually want is include? (no plural):

assert($browser.label.text.include?("This field is required"))
Justin Ko
  • 46,526
  • 5
  • 91
  • 101