使用Grinder时未定义名称'grinder'

时间:2013-02-11 23:23:57

标签: python jython 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

在我的localhost中。 开始测试后,此消息不断弹出:

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.logger.info”包含一些Grinder模块,但我不知道应该导入什么...... ...

任何提示?

提前致谢

2 个答案:

答案 0 :(得分:1)

您是从磨床中导入的物品,而不是磨床本身,请尝试

import grinder.logger.info
import grinder.statistics.forLastTest

如果是这种情况,也可能是net.grinder.logger.infonet.grinder.statistics.forLastTest,那么您的代码需要更改以适应从grinder到net.grinder的更改

答案 1 :(得分:0)

您还没有进口磨床。

from net.grinder.script.Grinder import grinder

现在再试一次。