简体   繁体   English

尝试添加xpath断言时,groovy脚本出错

[英]Error in groovy script while trying to add xpath assertion

I am getting below exception while trying to execute below code: 我在尝试执行以下代码时遇到异常:

missing property exception 缺少属性异常

Code in groovy script for adding xpath assertion into a test case. groovy脚本中的代码,用于将xpath断言添加到测试用例中。

Is there any possible solution to solve the error please? 请问有什么可能的方法来解决这个错误?

It has test suite name as "ManagePostpayInsurance_1_0" and test step name as "getInsuranceDetails_1_FTC_005". 它的测试套件名称为“ ManagePostpayInsurance_1_0”,测试步骤名称为“ getInsuranceDetails_1_FTC_005”。

log.info("Testing Start")
TSName = "ManagePostpayInsurance_1_0"
StepName = "getInsuranceDetails_1_FTC_005"
project.getTestSuiteList().each {
    if(it.name == TSName) {
        TS = it.name
        it.getTestCaseList().each {
            TC =it.name
            def asserting = project.getTestSuiteByName(TS).getTestCaseByName(TC).getTestStepByName(StepName).getAssertionByName("XPath Match")
            if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion) {
                project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName).removeAssertion(asserting)
            }
            def assertion = project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName).addAssertion("XPath Match")
            assertion.path = "declare namespace cor='http://soa.o2.co.uk/coredata_1';\ndeclare namespace man='http://soa.o2.co.uk/managepostpayinsurancedata_1';\ndeclare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';\n"
            assertion.expectedContent = "200"   
        }
    }

}
log.info("Testing Stop")

Thanks in advance 提前致谢

This is the error log which I am able to see: 这是我可以看到的错误日志:

Fri Nov 24 10:16:40 IST 2017:ERROR:groovy.lang.MissingPropertyException: No such property: project for class: Script13 groovy.lang.MissingPropertyException: No such property: project for class: Script13 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at Script13.run(Script13.groovy:7) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecut Fri Nov 24 10:16:40 IST 2017:ERROR:groovy.lang.MissingPropertyException:没有这样的属性:类为Script13的项目groovy.lang.MissingPropertyException:没有这样的属性:org.codehaus.groovy为类为Script13的项目。 org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)处的runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetite。 com.eviware.soapui.impl.wsdl.teststeps上Script13.run(Script13.groovy:7)处com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)处的Java:231) .com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel $ RunAction $ 1.run(GroovyScriptStepDesktopPanel.java:250)处的java.util.Exer.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)。未知来源),位于java.util.concurrent.ThreadPoolExecut or$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 或$ Worker.run(未知源),位于java.lang.Thread.run(未知源)

You can resolve below error 您可以解决以下错误

groovy.lang.MissingPropertyException: No such property: project for class: Script13 groovy.lang.MissingPropertyException:无此类属性:类的项目:Script13

by adding below statement at the top of your script 通过在脚本顶部添加以下语句

def project = context.testCase.testSuite.project

You are missing a . 您缺少一个. dot at getTestCaseByName(TC)getTestStepByName(StepName) . getTestCaseByName(TC)getTestStepByName(StepName)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM