Unable to open the script in anouther script

P

Pranjal Jain

Hi All
I ma trying to call the function written in one script in other script.
But it is giving me the error.

The called script is 2.rb

require 'watir'
def test_b

$ie1 = IE.new

$ie1.text_field:)name, "q").set "pickaxe"
$ie1.button:)name, "btnG").click
#ie.showAllObjects
end

the calling script is 1.rb

require 'watir'
require '2'

class TestCase

def test_a
$ie = IE.new
$ie.goto 'www.google.com'
end
test_b
end


The error popped is as follows:

/2.rb:4: in 'test_b': uninitialized constant IE(NameError)
from 1.rb:10

Please help.
Thanks in advance.
 
S

Stefan Lang

2008/4/9 said:
Hi All
I ma trying to call the function written in one script in other script.
But it is giving me the error.

The called script is 2.rb

require 'watir'
def test_b

$ie1 = IE.new

$ie1.text_field:)name, "q").set "pickaxe"
$ie1.button:)name, "btnG").click
#ie.showAllObjects
end

the calling script is 1.rb

require 'watir'
require '2'

class TestCase

def test_a
$ie = IE.new
$ie.goto 'www.google.com'
end
test_b
end


The error popped is as follows:

./2.rb:4: in 'test_b': uninitialized constant IE(NameError)
from 1.rb:10

I've never used Watir myself, but looking at the API docs it
looks like you should replace references to IE with
Watir::IE.

HTH,
Stefan
 
C

Chris Hulan

Hi All
I ma trying to call the function written in one script in other script.
But it is giving me the error.

The called script is 2.rb

require 'watir'
def test_b

$ie1 = IE.new

$ie1.text_field:)name, "q").set "pickaxe"
$ie1.button:)name, "btnG").click
#ie.showAllObjects
end

the calling script is 1.rb

require 'watir'
require '2'

class TestCase

def test_a
$ie = IE.new
$ie.goto 'www.google.com'
end
test_b
end

The error popped is as follows:

/2.rb:4: in 'test_b': uninitialized constant IE(NameError)
from 1.rb:10

Please help.
Thanks in advance.

Remember that ruby is interpreted, and code is evaluated line by line
class TestCase
def test_a
$ie = IE.new
$ie.goto 'www.google.com'
end
test_a is defined but has NOT been executed
test_ is invoked here, the code is executed
Since test_a has not been executed yet $ie has not been defined


I'd suggest:
class TestCase
def test_a
$ie = IE.new
$ie.goto 'www.google.com'
test_b
end
end
 
J

Julian Leviston

[Note: parts of this message were removed to make it a legal post.]

Ruby is complaining that there's an uninitialized constant called
IE... which means (funnily enough) that it doesn't know what IE means.

This is probably because you're trying to use a constant which is
namespaced without the namespace!

also, I think that you probably used to use php, given the
nomenclature you're using, and the fact that you're putting $ chars in
front of all your variable names.

Don't do this. $ in front of a variable name means it's a global, and
I'm fairly sure you don't want globals all through your code.

This is what you probably wanted: (from the watir example page)

ie = Watir::IE.new

Julian.



Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!
http://sensei.zenunit.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top