使用Grinder时未定义'grinder
Grinder对我来说是个新东西,我正在努力弄明白怎么解决这个错误:
这是我的test.py脚本:
import string
import random
from java.lang import String
from java.net import URLEncoder
from net.grinder.plugin.http import HTTPRequest
from net.grinder.common import GrinderException
log = grinder.logger.info
stat = grinder.statistics.forLastTest
SERVER = "http://www.google.com"
URI = "/"
class TestRunner:
def __call__(self):
requestString = "%s%s" % (SERVER, URI)
request = HTTPRequest()
result = request.GET(requestString)
if string.find(result.getText(), "SUCCESS") < 1:
stat.setSuccess(0)
我在我的本地电脑上运行:
java net.grinder.Console
java net.grinder.Grinder
在启动测试后,这条信息一直弹出来:
aborting process - Jython exception, <type 'exceptions.NameError'>: name 'grinder' is not defined [initialising test script]
net.grinder.scriptengine.jython.JythonScriptExecutionException: <type 'exceptions.NameError'>: name 'grinder' is not defined
log = grinder.logger.info
File "./test.py", line 8, in <module>
看起来我需要包含一些Grinder模块来使用这个"grinder.logger.info",但我完全不知道该导入什么... ...
有没有什么提示?
提前谢谢你!
2 个回答
0
你还没有导入grinder这个东西。
from net.grinder.script.Grinder import grinder
现在再试一次吧。
1
你导入的是grinder里面的项目,而不是grinder本身,试试这个
import grinder.logger.info
import grinder.statistics.forLastTest
如果是这样的话,可能还需要用到 net.grinder.logger.info
和 net.grinder.statistics.forLastTest
,那么你的代码就需要做一些调整,以适应从grinder改成net.grinder的变化。