Tuesday, 4 April 2017

How to use JSON file as Object Repository in Ruby ?

Text in Blue [#PYTHON], Red [#RUBY], and Orange [#JAVA] can be edited or mentioned important for the entire blog. All the posts are practically done by me.

JSON as Object Repository in Ruby

Create a JSON formatted object repository file; say, or.json

  "login_id": {
    "selector": ":css",
    "value": "#login"

Now, create a module; say, utilities.rb

module Modulename
def loc(element)
  file = File.read(File.dirname(__FILE__) + "/../helpers/or.json")
  @driver.find_element(eval(JSON.parse(file)["#{element}"]['selector']), JSON.parse(file)["#{element}"]['value'])

Add the path in your env.rb

require File.dirname(__FILE__) + "/../helpers/utilities"
include Modulename

Finally call the loc() method in a page file as shown below,



  1. nice blog. helped me a lot. share some more tutorials???????

  2. Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.
    When I started learning then I understood it has got really cool stuff.
    I can vouch webdriver has proved the best feature in Selenium framework.
    thanks a lot for taking a time to share a wonderful article.
    Best Selenium Training Institute in Chennai |
    Selenium Training in Velachery


  3. Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

    Installment loans
    Payday loans
    Title loans

  4. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me.Thanks for sharing.java training in chennai

  5. Awesome Tips here. This is really great and informative post. Best Online Website Development Courses

  6. Thanks for sharing your post. Apartments for sale in Anna nagar available at affordable prices with world class amenities and international standard clubhouse. Do check out!

  7. Thanks for The Post.Great Blog With unique Content And Nice Information.
    Thanks@Learn Selenium Webdriver

  8. This information you provided in the blog that is really unique I love it!! Thanks for sharing such a great blog. Keep posting..
    Selenium Training
    Selenium Training Institute
    Selenium Course