调用模块的方法时遇到问题(具有类的对象,包含在另一个ruby文件中)
我是ruby的新手,正在使用“RubyJMeter”gem(由flood.io提供)制作性能自动化框架 我制作了以下文件结构 其中payload.rb和request.rb包含我的常用实用程序方法。我从test.rb给它打电话 (test.rb将由QA ppl编写) request.rb(位于“公共”文件夹下) test.rb(位于“testflow->simpleflow”文件夹下) 运行test.rb时,出现以下错误调用模块的方法时遇到问题(具有类的对象,包含在另一个ruby文件中),ruby,ruby-jmeter,Ruby,Ruby Jmeter,我是ruby的新手,正在使用“RubyJMeter”gem(由flood.io提供)制作性能自动化框架 我制作了以下文件结构 其中payload.rb和request.rb包含我的常用实用程序方法。我从test.rb给它打电话 (test.rb将由QA ppl编写) request.rb(位于“公共”文件夹下) test.rb(位于“testflow->simpleflow”文件夹下) 运行test.rb时,出现以下错误 `<top (required)>': uninitial
`<top (required)>': uninitialized constant PerformanceAutomation (NameError)
您当前的工作目录是什么?当前的工作目录是('simpleflow')。这是我的测试我正在从命令prompt执行此文件。这些代码片段有很多语法问题。你能纠正它们吗?我收到“语法错误,输入意外结束,需要关键字_end”消息,建议您正确关闭类、方法和块。(顺便说一句,Ruby的最佳实践是用两个空格缩进行。)test.rb的更正代码。有额外的“end”关键字。我编辑了一个代码,其中包含一个对我来说很好的解决方案:)
require 'rubygems'
require 'ruby-jmeter'
require 'require_all'
require_all './'
module PerformanceAutomation
def self.MyRequest
Request.new(self)
end
end
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")
`<top (required)>': uninitialized constant PerformanceAutomation (NameError)
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
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")