0

I have the following code

require 'watir-wedriver'

browsers = ['chrome', 'safari']

browsers.each do |browserName|
    browser = Watir::Browser.new :browserName
    # more code here
end

browserName doesn’t work here since the command is interpreting it literally (i.e., it’s reading browser = Watir::Browser.new :browserName instead of browser = Watir::Browser.new :chrome followed by browser = Watir::Browser.new :safari.

How can I make that variable expand there?

1 Answer 1

1

Don't literally quote the variable

browsers.each do |browserName|
    browser = Watir::Browser.new browserName.to_sym # string to a symbol
    ...
 end

or just originally use symbols

 browsers = [:chrome, :safari]
 ...
     browser = Watir::Browser.new browserName
Sign up to request clarification or add additional context in comments.

1 Comment

notice that :browserName and browserName are different things! :browserName is a symbol, and browserName is a variable. If you want the value to change, it needs to be a variable!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.