0

I have a .properties files as below:

user:abcd
pwd:xyz
system:test

Next, I have a ruby script with Watir for browser automation. In this script, I have statements like

browser.text_field(:id => 'identifierId').set "#{user}:variable to be replaced by its value from .properties file".

Similarly, other values need to be replaced for "pwd" and "system".

I tried the solution per below posts: Replace properties in one file from those in another in Ruby

However, "set" command is setting whatever has been paased as arguments to it instead of replacing the variable with its value.

Please help.

1
  • 1
    Not really clear on what you are trying to do. Can you give an example of what you want to happen? Is it just that you want to change some of the key vals in the file? Commented Feb 12, 2019 at 5:12

1 Answer 1

2

You have to read the information out of the file. Most Watir users leverage yaml files for this.

config/properties.yml:

user: abcd
pwd: xyz
system: test

Then read the yaml file & parse your data:

properties = YAML.safe_load(IO.read('config/properties.yml'))

text_field = browser.text_field(id: 'identifierId')
text_field.set properties['user']

Alternately you can take a look at Cheezy's Fig Newton gem, which is designed to work with his Page Object gem

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly, what I was looking for. Thank you.

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.