Tuesday, 4 April 2017

How to use JSON file as Object Repository in Ruby ?


Note| 
 
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'])
end
end

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,

loc("login_id").click

19 comments:

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

    ReplyDelete
  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

    ReplyDelete

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

    Installment loans
    Payday loans
    Title loans

    ReplyDelete
  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

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

    ReplyDelete
  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!

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

    ReplyDelete
  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

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. 6-week summer course in Noida - 6 weeks The summer course plays a crucial role in shaping the career of young aspiring / informatics students. This training has been specifically introduced so that students can become familiar with current industrial culture and industrial needs. Webtrackker technology offers a 6-month training program for students / graduates that includes small and large projects.
    6-week summer course in Noida

    ReplyDelete
  11. All the latest updates from the Python Automationminds team. Python Automationminds lets you program in Python, in your browser. No need to install any software, just start coding straight away. There's a fully-functional web-based console and a programmer's text-editor
    Phyton training in Chennai

    ReplyDelete
  12. Thanks for giving this article. It was very helpful and also very informative.Keep updating like this.
    Best Data Science Online Training Institute In Hyderabad

    ReplyDelete
  13. Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

    AutoCAD training in Noida

    AutoCAD training institute in Noida


    Best AutoCAD training institute in Noida

    ReplyDelete