Claire Nagle Claire Nagle - 1 year ago 80
Ruby Question

Using a var to complete watir agent

I am working on a way to share a Ruby program. This is my test code.

require 'rubygems'
require 'watir-webdriver'
require 'headless'
require 'google_drive'

@browsertype =""
@name =""
@champsname = ""
@date =

file = File.exists?("temp.txt")
if file == true
input ="temp.txt")
input_hash = Hash[*input.gsub(/"/,"").split(/\s*[\n=]\s*/)]
browsertype = input_hash.shift
name = input_hash.shift
champsname = input_hash.shift

@browsertype = browsertype[1]
@name = name[1]
@champ = champsname[1]

if file == false
f ="temp.txt", "w")

# processing
puts "What browser will you be using? "
browsertype = gets
f.write("browser = :")
puts "What is your name? "
name = gets
f.write("name = ")
puts "what is your champs name"
champsname = gets
f.write("champion = ")

@browsertype = browsertype
@name = name
@champ = champsname

puts @browsertype
puts @name
puts @champ
puts @date

#@b = " :"+@browsertype

agent =
@b = agent+@browsertype

#b = @b

#b.goto ''

I used this question as a reference for making var out of files, Variables magic and read from file. I want my friends to be able to use the finished product by using orca Building a Windows executable from my Ruby app?. The problem I have been encountering is Watir runs Firefox by default when you use

agent =

But not everyone uses Firefox, so this is why I created the browsertype in the file. But when I use

@b = " :"+@browsertype

I get an error saying that the
is invalid and I get the same for symbol. Does anyone have any suggestions on how I can have a user defined browser type?

Answer Source

You should pass the browser type to the initialization of the browser.:

@b = @browsertype

This assumes that @browsertype is something like 'firefox'.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download