0

I am newbie in ruby and working on making performance automation framework using using 'ruby-jmeter' gem (provided by flood.io)

I have made following files structure Where payload.rb and request.rb contains my common utility methods . Which I am calling from test.rb (test.rb would be going to be written by QA ppl)

Performance Automation Framework Structure

request.rb (lying under 'common' folder)

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

 module RubyJmeter
   class ExtendedDSL < DSL     #'ruby-jmeter' class extending
      def get_common_headers()   
         commonHeaderHashMap = {
        'tns' => 'urn:',
        'Content-Type' => 'text/xml; charset=utf-8',
        'Accept-Language' => 'en-US,en;q=0.5',
        'Accept-Encoding' => 'gzip, deflate'
      }
    return commonHeaderHashMap
    end
   end
 end

 class Request
  def initialize(dsl)
  @dsl = dsl
  end

   def soap_post_web_request(name,rawBody)
      endPoint = '/SoapEndPoint'

      post name: name, url: endPoint , raw_body: rawBody do
      tempHeaderHashMap = get_common_headers.merge( {'SOAPAction' =>    
                                'urn:'+name} )
      finalHeaderArray = []

      tempHeaderHashMap.each {|key, value|
      localHashMap = Hash.new
      localHashMap = {:name => key, :value => value}
      finalHeaderArray << localHashMap
    }

   header finalHeaderArray

    end # End of soapCall
  end  #end of soap_post_web_request

  # Passes method calls through to the underlying DSL (ruby-jmeter).
 def method_missing method, *args, &block
    @dsl.__send__ method, *args, &block
  end

end

wrappingclasses_under_single_module.rb (lying under 'common' folder)

  require 'rubygems'
  require 'ruby-jmeter'
  require 'require_all'

 require_all './'

 module PerformanceAutomation
    def self.MyRequest 
       Request.new(self) 
    end
 end

test.rb (lying under 'testflow->simpleflow' folder)

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

require_all '../../common/' 

include PerformanceAutomation
test name:'JiraAnalyticsPerformanceFlow' do
   threads name: 'NoOfUsers',scheduler: false,continue_forever: false,                
       count: 1 do
                PerformanceAutomation.MyRequest.soap_post_web_request('soapRequestmethodName',rawdata)# End of Soap request 'soapRequestmethodName'

 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")

When running test.rb , I am getting following error

 `<top (required)>': uninitialized constant PerformanceAutomation (NameError)

Edit (It is working fine now) Updated common utility files by using

request.rb

module RubyJmeter
class ExtendedDSL < DSL
    def get_admin_common_headers()
      commonHeaderHashMap = {
        'X-XSRF-TOKEN' => '${COOKIE_XSRF-TOKEN}',
        'Content-Type' => 'text/xml; charset=utf-8',
        'Accept-Language' => 'en-US,en;q=0.5',
        'Accept-Encoding' => 'gzip, deflate'
      }
      return commonHeaderHashMap
    end
  end
end

module API
  class AdminWebService
    def initialize(dsl)
      @dsl = dsl
    end

    ## Admin request for 'get_space_properties'
    def get_space_properties(rawBody)
      endPoint = "/AdminService.asmx"
      post name: "admin_GetSpaceProperties", url: endPoint ,     
            raw_body:rawBody do
    tempHeaderHashMap = get_admin_common_headers.merge( {'SOAPAction' =>  
    'http://example.com/GetSpaceProperties'} )
    finalHeaderArray = []

    tempHeaderHashMap.each {|key, value|
      localHashMap = Hash.new
      localHashMap = {:name => key, :value => value}
      finalHeaderArray << localHashMap
    }

    header finalHeaderArray

  end # End get_space_properties
end

test.rb

require 'rubygems'
require 'ruby-jmeter'
require 'require_all'

require_all '../../../common/'

  defaults domain: 'example.com', protocol: 'http', connect_timeout:   
                   '2000', response_timeout: '3000'
  cookies policy: 'compatibility', clear_each_iteration: true   
                   #'cookies' is method defined under 'ruby-jmeter'
  cache clear_each_iteration: true    # 'cache' is method defined under 
     'ruby-jmeter'

# starting testPlan 'JiraAnalyticsPerformanceFlow'
test name:"testFlowName" do
    adminwebservice = API::AdminWebService.new(self)  
adminwebservice.get_space_properties(Payload.get_local_payload("get_space_properties.xml")) 
       #Payload is another common utility class for fetching payload     stuff
 end
 puts "JMX FILE IS GONNA SAVED @       
        "+Dir.pwd+"/CreatedJMeter_DB2Navigation.jmx"
end.jmx(file: Dir.pwd+"/CreatedJMeter_DB2Navigation.jmx")
sjethvani
  • 498
  • 1
  • 7
  • 17
  • What is your current working directory? – Jörg W Mittag Nov 05 '15 at 13:10
  • current working directory is It is ('simpleflow'). here is my test.rb lies. & i am exeucting this file from command prompt – sjethvani Nov 05 '15 at 15:16
  • There are a lot of syntax problems with these code snippets. Can you correct them? I'm getting 'syntax error, unexpected end-of-input, expecting keyword_end' messages, suggesting you need to properly close your classes, methods and blocks. (Ruby best practice is to indent lines with two spaces, by the way.) – LazyMonkey Nov 05 '15 at 18:35
  • Corrected code of test.rb . Was having extra 'end' keyword. – sjethvani Nov 06 '15 at 06:04
  • I have edited a code with a solution which is working fine for me :) – sjethvani Dec 17 '15 at 06:59

0 Answers0