WATIR : Errno::ECONNREFUSED: No connection could be made because the target machine actively refused

hi, I am trying to automate Chrome Browser, It throws the following
error only when I call by function like

Error which is thrown
“No connection could be made because the target machine actively
refused”

if I call as shown below,it throws the following error

def fun()
fun1()
end

def fun1()
code1
code2
code3
code4
end

But if I directly writes into the fun then it’s not coming like below
def fun()
code1
code2
code3
code4
end

Can anyone suggest me what kind of error is this? How would I able to
resolve this?

Show me the actual code, the error message, and the line of code it’s
pointing to.

hi Jeol,

I defined as given below,

login()

def login
$browser = Watir::Browser.new :chrome
$browser.goto($test_site)
end

class Raj
testName.each_index do |i|
define_method(testName[i]) do
$browser.input(:name,‘something’).exists? #Error happens here
$browser.input(:name,‘something’).set
$browser.a(:text,'Next").click
end
end
end

hi Jeol, Thank you, I resolved that problem by declaring the $browser
variable inside like below,

unless defined?($browser)
$browser=Watir::Browser.new :firefox
$browser.goto(site)
end

Your code is incomplete. I can’t diagnose anything without the relevant
code.

What? Is this related reply to my question in any way?