0

I am trying to create performance automation framework for my company . Beinbg newbie to ruby field , I thought to keep it simple . Here is structure for performance framewrok

I do have multiple ruby files , as request.rb,payload.rb etc in 'common' folder(as these are containing some utilities) and then my test in test.rb (under one of 'TestFlows->SimpleFlow->test.rb) .
See above structure for more detail

Exact Code , which I am having right now under those files are

request.rb

require 'ruby-jmeter' #(Consider any 3rd party gem )
require 'rubygems'

module Company #Note that i am using same module name 'company'
  module Request 
     def self.send_request()
        visit '192.148.1.2'  #  this is function defined under ruby-jmeter
     end
   end
end

payload.rb

require 'ruby-jmeter' #(Consider any 3rd party gem )
require 'rubygems'

module Company   #Note that i am using same module 'company'
    module Payload
       def self.get_payload()
        ------- Again some 'ruby-jmeter' function calls
       end

     end
end

etc files as well

Test.rb

   require 'ruby-jmeter' #(Consider any 3rd party gem )
   require 'rubygems'
   require 'require_all'  #(gem to load all files from folder)
   require_all '../../common/'

   module Company   #Note that i am using same module 'company' 
     test name:'GooglePerformanceTest' do 
          defaults domain: 'http://google.com' ,protocol: http  
           threads name: 'NoOfUsers',scheduler: false,continue_forever:    
                 false, count: 2 do
                       Request.send_request()
                   end
       end   #end of testPlan
       view_results_tree
       puts "JMX FILE IS GONNA SAVED @          
                  "+Dir.pwd+"/CreatedJMeter_DB2Navigation.jmx"
    end.jmx(file: Dir.pwd+"/CreatedJMeter_DB2Navigation.jmx")
    end

When I run this programme , it goes to above , I am getting errors of those (3rd party ruby gem's function undefined).

Can anyone point me out my problem regarding above structure & suggest me proper way to do this ?

edit : I am getting below error

     Test.rb:3:in `send_request': undefined method `visit ' for 
     company::Request:Module (NoMethodError)

Edit Have defined my changes here & it is working fine Facing issues while calling method of module(having object of class , contained in another ruby file)

Community
  • 1
  • 1
sjethvani
  • 498
  • 1
  • 7
  • 17

1 Answers1

0

I'm assuming you're using the gem hosted at this repository: https://github.com/flood-io/ruby-jmeter, latest release version (2.13.8).

Looking through the source code and examples, there are a couple things to think about.

  1. The 'visit' method is an alias for a method called 'get' defined here .

That is an object method, for an object of class RubyJmeter::ExtendedDSL. You are using module methods, and should probably consider making an object and calling the method on that.

obj = RubyJmeter::ExtendedDSL.new
obj.visit '192.148.1.2' # 'visit' is a method alias for 'get'
  1. However, the examples listed by the gem developer follow a different pattern, calling 'visit' from within a closure (the do..end code block, known simply as a 'block' in Ruby). You could rewrite your code to build test plans and run them in this fashion.

It's not clear from what you post why you are using modules. Typically, you use 'include' within a Module or Class to mix in the gem's methods into your namespace. But since you're attempting to use module methods, I'm not sure mixing in object methods will be fruitful.

  1. Since I can't see how your Test.rb file is run, I can't say for sure that your test code is loading your own modules. Typically a 'load' or 'include' statement would be used to load the code you wrote in request.rb and payload.rb

Personally, I'd try to follow the pattern shown by the developer of RubyJmeter; as a second approach, I'd write a class that inherits from RubyJemeter's subclass and extend its behavior to suit. My test code would initialize an object and call its methods directly. (Your Mileage May Vary.)

Updated to add: if you want your module method to stand in place of the object method mentioned, you can simply call the latter inside your method:

def self.send_request()
  RubyJmeter::ExtendedDSL.new.visit '192.148.1.2'
end

Doing this essentially creates a disposable object, which is destroyed after the :visit method returns its data.

P.S. Always capitalize your class and module names. It's a Ruby best practice and your module name 'company' will raise warnings from the interpreter.

LazyMonkey
  • 517
  • 5
  • 8
  • Hey @LazyMonkey , I have edited my question with full details , what i want to do and why . Basically I am creating performance framework using 'ruby-jmeter' , where in I am trying to create conventional structure where in anybody can come and create his own testscripts by calling all those common functions/utilities(placed under 'common' folder in my structure). I have also attached image of my framework structure . I think this will help you to point me correct direction – sjethvani Nov 05 '15 at 05:59
  • And one more thing , I am newbie to ruby . I read lots of stuff about modules/mixins etc . So thought to give it a try . With that why I am not using class here is because , I don't want to create objects of those Payload and Request modules in test.rb. QA should be able to simply call utility methods by directly calling from their Module name (I mean in static way). I want your suggestion as in what I should use here & basic code will be highly appreciated – sjethvani Nov 05 '15 at 06:08
  • I have changed structure now after following your comments and going through some of advance examples of 'ruby-jmeter'. Here is another problem I am facing now regarding structure. http://stackoverflow.com/questions/33545197/facing-issues-while-calling-method-of-modulehaving-object-of-class-contained – sjethvani Nov 05 '15 at 13:01