question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I can not to use value of variable from the Endpointconfig.class and BeforeTest.class

See original GitHub issue

Hello all! Citrus Version 2.7.7

Expected behavior I expected that value of my variable will be known.

Actual behavior

14:28:42,199 ERROR port.LoggingReporter| TEST FAILED BookShelf.test_4 <com.temafon.x.x> Nested exception is: 
com.consol.citrus.exceptions.CitrusRuntimeException: Unknown variable 'randomstring'
	at com.consol.citrus.context.TestContext.getVariableObject(TestContext.java:158)
	at com.consol.citrus.context.TestContext.getVariable(TestContext.java:133)
	at com.consol.citrus.context.TestContext.getVariable(TestContext.java:122)
	at com.consol.citrus.variable.VariableUtils.replaceVariablesInString(VariableUtils.java:175)
	at com.consol.citrus.context.TestContext.replaceDynamicContentInString(TestContext.java:346)
	at com.consol.citrus.context.TestContext.replaceDynamicContentInString(TestContext.java:331)
	at com.consol.citrus.validation.builder.StaticMessageContentBuilder.buildMessagePayload(StaticMessageContentBuilder.java:48)
	at com.consol.citrus.validation.builder.AbstractMessageContentBuilder.buildMessageContent(AbstractMessageContentBuilder.java:83)
	at com.consol.citrus.http.message.HttpMessageContentBuilder.buildMessageContent(HttpMessageContentBuilder.java:57)
	at com.consol.citrus.actions.SendMessageAction.createMessage(SendMessageAction.java:163)
	at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:90)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:54)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.TestCase.executeAction(TestCase.java:234)
	at com.consol.citrus.TestCase.doExecute(TestCase.java:153)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.Citrus.run(Citrus.java:403)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.invokeTestMethod(TestNGCitrusTest.java:125)
	at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.invokeTestMethod(TestNGCitrusTestDesigner.java:73)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:110)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:56)
	at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:579)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.privateRun(TestRunner.java:648)
	at org.testng.TestRunner.run(TestRunner.java:505)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
	at org.testng.TestNG.runSuites(TestNG.java:1049)
	at org.testng.TestNG.run(TestNG.java:1017)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
14:28:42,201 INFO  port.LoggingReporter| ------------------------------------------------------------------------
14:28:42,201 INFO  port.LoggingReporter| 

com.consol.citrus.exceptions.TestCaseFailedException: Unknown variable 'randomstring'
14:28:42,199 ERROR port.LoggingReporter| TEST FAILED BookShelf.test_4 <com.temafon.x.x> Nested exception is: 
com.consol.citrus.exceptions.CitrusRuntimeException: Unknown variable 'randomstring'
	at com.consol.citrus.context.TestContext.getVariableObject(TestContext.java:158)
	at com.consol.citrus.context.TestContext.getVariable(TestContext.java:133)
	at com.consol.citrus.context.TestContext.getVariable(TestContext.java:122)
	at com.consol.citrus.variable.VariableUtils.replaceVariablesInString(VariableUtils.java:175)
	at com.consol.citrus.context.TestContext.replaceDynamicContentInString(TestContext.java:346)
	at com.consol.citrus.context.TestContext.replaceDynamicContentInString(TestContext.java:331)
	at com.consol.citrus.validation.builder.StaticMessageContentBuilder.buildMessagePayload(StaticMessageContentBuilder.java:48)
	at com.consol.citrus.validation.builder.AbstractMessageContentBuilder.buildMessageContent(AbstractMessageContentBuilder.java:83)
	at com.consol.citrus.http.message.HttpMessageContentBuilder.buildMessageContent(HttpMessageContentBuilder.java:57)
	at com.consol.citrus.actions.SendMessageAction.createMessage(SendMessageAction.java:163)
	at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:90)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:54)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.TestCase.executeAction(TestCase.java:234)
	at com.consol.citrus.TestCase.doExecute(TestCase.java:153)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
	at com.consol.citrus.Citrus.run(Citrus.java:403)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.invokeTestMethod(TestNGCitrusTest.java:125)
	at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.invokeTestMethod(TestNGCitrusTestDesigner.java:73)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:110)
	at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:56)
	at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:242)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:579)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.privateRun(TestRunner.java:648)
	at org.testng.TestRunner.run(TestRunner.java:505)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
	at org.testng.TestNG.runSuites(TestNG.java:1049)
	at org.testng.TestNG.run(TestNG.java:1017)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
14:28:42,201 INFO  port.LoggingReporter| ------------------------------------------------------------------------
14:28:42,201 INFO  port.LoggingReporter| 

com.consol.citrus.exceptions.TestCaseFailedException: Unknown variable 'randomstring'

Test case sample I use this test :

    @CitrusTest
    @Test(enabled = true)
    public void test_4(){
        description("GET /shelf/{shelf_id}");
        status(TestCaseMetaInfo.Status.DRAFT);

        http().client(todoclient).send().put("/shelf/${shelf_id}")
                .header("Content-type", "application/json")
                .header("X-User-Token","${token}").payload(new ClassPathResource("templates/put_shelf_shelfID.json"))
        ;
        http().client(todoclient).receive()
                .response(HttpStatus.OK).messageType(MessageType.JSON)
        ;
    }

This is my json file:

{
  "type" : "citrus:randomEnumValue('default', 'favorite', 'recommended')",
  "title" : "citrus:concat('title', citrus:randomNumber(10))",
  "notes" : "citrus:concat('notes is: ', ${randomstring})",
  "is_public" : citrus:randomEnumValue('true', 'false'),
  "books" : [ ${book_id},  2125749,  1876378,  1864993 ]
}

This is my variable in BeforeTest.class : disigner.variable("randomstring","citrus:randomString(10, MIXED)");

And this is my bean in the Endpointconfig.class

    @Bean
    public GlobalVariables globalVariables()
    {
        GlobalVariables variables = new GlobalVariables();
        // Vars for tests
        variables.getVariables().put("randomstring","citrus:randomString(10, MIXED)");

        return variables;
    }

I can not to use value of variable from the Endpointconfig.class and BeforeTest.class. I will see value of variable only like this :

    @CitrusTest
    @Test(enabled = true)
    public void test_4(){
        //Метод возвращает интернал еррор 500. Заведена ошибка. Можно добавить PRE шаг и проверку в бд.
        description("GET /shelf/{shelf_id}");
        variable("randomstring","citrus:randomString(10, MIXED)");
        status(TestCaseMetaInfo.Status.DRAFT);

        http().client(todoclient).send().put("/shelf/${shelf_id}")
                .header("Content-type", "application/json")
                .header("X-User-Token","${token}").payload(new ClassPathResource("templates/put_shelf_shelfID.json"))
        ;
        http().client(todoclient).receive()
                .response(HttpStatus.OK).messageType(MessageType.JSON)
        ;
    }
        ;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
svettwercommented, Oct 4, 2018

Ah, too slow. 👍 😉

0reactions
svettwercommented, Oct 8, 2018

Good to hear that you were able to fix the issue! 👍

BR, Sven

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access variable in @BeforeTest and @AfterClass (TestNG ...
I have a Base class that actually instantiates the driver, and then then I extend the Base class with the TestBase class containing...
Read more >
How to pass a variable from BeforeTest to Test annotation in ...
Since none of these methods support return type, the best way to pass a variable is using class /instance variable rather thanlocal variable....
Read more >
Index (citrus-core 2.5.2 API) - Javadoc.io
Abstract message endpoint handles send/receive timeout setting and test actors. AbstractEndpoint(EndpointConfiguration) - Constructor for class com.consol.
Read more >
Citrus Framework
This documentation provides a reference guide to all features of the Citrus test framework. It gives a detailed picture of effective integration ...
Read more >
Developer Guide - SwitchYard 1.1 - Red Hat on GitHub
Every bean service must have an @Service annotation with a value identifying ... There are no SwitchYard-specific classes or APIs used for Java...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found