Watir - How to call browser.goto from another file

Skip to first unread message


Mar 24, 2022, 11:22:33 AM3/24/22
to Watir General

I'm using watir ruby for my testing I have quite lot f script written for a website and sometimes I have test in different environment like UAT or DEV site. At the moment my 
setup method below are in the same file as my test scripts. 
@browser  = Waitr::Browser.new..... 
@browser.goto "https...."

I want to be able to change the goto website just one time instead going to each file to change it everytime. I have tried move the above code to a different file and use the require ''...." method in the test script file but it doesn't work. 

Any advice on how can to call the @browser.goto from another file? 



John Fitisoff

Mar 24, 2022, 11:47:34 PM3/24/22
to watir-...@googlegroups.com
Replace all hard-coded instance of the the URLs with a variable or a constant. Store that different URLs in a hash in a file. Something like this:

URLS = {
  dev: 'https://url1.com',
  prod: 'https://url2.com'

Then, in whatever you're using to run the script, add an option to specify the environment when running. one way to do it would be to use ARGV. Then run the script for the environment, let's say you want "dev":

myscript.rb dev

In the script, assuming that you have access to the URLS constant defined above, then you could then get the URL associated with the environment you specified at the command line by doing something like this:

TARGET_URL = URLS[ARGV[0].to_sym] 

And then use TARGET_URL wherever you need to call goto in place of the hard-coded URL.

There are better ways of doing this but it sounds like you're just looking for ideas to start organizing, HTH.


Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/watir-general/74dc7e5e-6138-47ca-9422-9e2ee41f1e10n%40googlegroups.com.
Reply all
Reply to author
0 new messages