How to use GroovyAction class of com.consol.citrus.script package

Best Citrus code snippet using com.consol.citrus.script.GroovyAction

Source:GroovyTestRunnerTest.java Github

copy

Full Screen

...15 */16package com.consol.citrus.dsl.runner;17import com.consol.citrus.TestCase;18import com.consol.citrus.context.TestContext;19import com.consol.citrus.script.GroovyAction;20import com.consol.citrus.testng.AbstractTestNGUnitTest;21import org.mockito.Mockito;22import org.springframework.core.io.ClassPathResource;23import org.springframework.core.io.Resource;24import org.testng.Assert;25import org.testng.annotations.Test;26import java.io.*;27import static org.mockito.Mockito.reset;28import static org.mockito.Mockito.when;29public class GroovyTestRunnerTest extends AbstractTestNGUnitTest {30 private Resource scriptResource = Mockito.mock(Resource.class);31 private Resource scriptTemplate = Mockito.mock(Resource.class);32 private File file = Mockito.mock(File.class);33 34 @Test35 public void testGroovyBuilderWithResource() throws IOException {36 reset(scriptResource);37 when(scriptResource.getInputStream()).thenReturn(new ByteArrayInputStream("println 'Wow groovy!'".getBytes()));38 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {39 @Override40 public void execute() {41 groovy(builder -> builder.script(scriptResource)42 .skipTemplate());43 }44 };45 TestCase test = builder.getTestCase();46 Assert.assertEquals(test.getActionCount(), 1);47 Assert.assertEquals(test.getActions().get(0).getClass(), GroovyAction.class);48 Assert.assertEquals(test.getActions().get(0).getName(), "groovy");49 50 GroovyAction action = (GroovyAction)test.getActions().get(0);51 Assert.assertEquals(action.getScript(), "println 'Wow groovy!'");52 Assert.assertEquals(action.isUseScriptTemplate(), false);53 }54 55 @Test56 public void testGroovyBuilderWithScript() {57 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {58 @Override59 public void execute() {60 groovy(builder -> builder.script("println 'Groovy!'")61 .skipTemplate());62 }63 };64 TestCase test = builder.getTestCase();65 Assert.assertEquals(test.getActionCount(), 1);66 Assert.assertEquals(test.getActions().get(0).getClass(), GroovyAction.class);67 68 GroovyAction action = (GroovyAction)test.getActions().get(0);69 Assert.assertEquals(action.getScript(), "println 'Groovy!'");70 Assert.assertEquals(action.isUseScriptTemplate(), false);71 }72 73 @Test74 public void testGroovyBuilderWithTemplate() throws IOException {75 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {76 @Override77 public void execute() {78 groovy(builder -> builder.script("context.setVariable('message', 'Groovy!')")79 .template(new ClassPathResource("com/consol/citrus/script/script-template.groovy")));80 }81 };82 TestContext context = builder.getTestContext();83 Assert.assertNotNull(context.getVariable("message"));84 Assert.assertEquals(context.getVariable("message"), "Groovy!");85 TestCase test = builder.getTestCase();86 Assert.assertEquals(test.getActionCount(), 1);87 Assert.assertEquals(test.getActions().get(0).getClass(), GroovyAction.class);88 89 GroovyAction action = (GroovyAction)test.getActions().get(0);90 Assert.assertNotNull(action.getScriptTemplate());91 Assert.assertEquals(action.isUseScriptTemplate(), true);92 }93 94 @Test95 public void testGroovyBuilderWithTemplatePath() {96 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {97 @Override98 public void execute() {99 groovy(builder -> builder.script("context.setVariable('message', 'Groovy!')")100 .template("classpath:com/consol/citrus/script/script-template.groovy"));101 }102 };103 TestContext context = builder.getTestContext();104 Assert.assertNotNull(context.getVariable("message"));105 Assert.assertEquals(context.getVariable("message"), "Groovy!");106 TestCase test = builder.getTestCase();107 Assert.assertEquals(test.getActionCount(), 1);108 Assert.assertEquals(test.getActions().get(0).getClass(), GroovyAction.class);109 110 GroovyAction action = (GroovyAction)test.getActions().get(0);111 Assert.assertNotNull(action.getScriptTemplatePath());112 Assert.assertEquals(action.isUseScriptTemplate(), true);113 }114}...

Full Screen

Full Screen

Source:GroovyActionTest.java Github

copy

Full Screen

...20import com.consol.citrus.testng.AbstractTestNGUnitTest;21/**22 * @author Christoph Deppisch23 */24public class GroovyActionTest extends AbstractTestNGUnitTest {25 26 @Test27 public void testScript() {28 GroovyAction bean = new GroovyAction();29 bean.setScript("println 'Hello TestFramework!'");30 bean.execute(context);31 }32 33 @Test34 public void testScriptResource() {35 GroovyAction bean = new GroovyAction();36 bean.setScriptResourcePath("classpath:com/consol/citrus/script/example.groovy");37 bean.execute(context);38 }39 40 @Test(expectedExceptions = {CitrusRuntimeException.class})41 public void testScriptFailure() {42 GroovyAction bean = new GroovyAction();43 bean.setScript("Some wrong script");44 bean.execute(context);45 }46 47 @Test(expectedExceptions = {CitrusRuntimeException.class})48 public void testScriptResourceNotFound() {49 GroovyAction bean = new GroovyAction();50 bean.setScriptResourcePath("file:some/wrong/path/test.groovy");51 bean.execute(context);52 }53 54 @Test55 public void testCustomScriptExecutorImplementation() {56 GroovyAction bean = new GroovyAction();57 58 String script = "import com.consol.citrus.*\n" +59 "import com.consol.citrus.variable.*\n" +60 "import com.consol.citrus.context.TestContext\n" +61 "import com.consol.citrus.script.GroovyAction.ScriptExecutor\n\n" +62 "public class GScript implements ScriptExecutor {\n" +63 "public void execute(TestContext context) {\n" +64 "context.setVariable('text', 'Script with class definition test successful.')\n" +65 "println context.getVariable('text')\n" +66 "}}";67 68 bean.setScript(script);69 bean.execute(context);70 }71 72 @Test73 public void testCustomClassImplementation() {74 GroovyAction bean = new GroovyAction();75 76 String script = "public class CustomClass {\n" +77 "public void run() {\n" +78 "println 'Just executed custom class implementation'\n" +79 "}}";80 81 bean.setScript(script);82 bean.execute(context);83 }84 85 @Test86 public void testNoScriptTemplate() {87 GroovyAction bean = new GroovyAction();88 89 bean.setUseScriptTemplate(false);90 91 String script = "println 'Just executed pure groovy code'";92 93 bean.setScript(script);94 bean.execute(context);95 }96 97 @Test98 public void testAutomaticScriptExecutorWrapper() {99 GroovyAction bean = new GroovyAction();100 bean.setScript("context.setVariable('text', 'Automatic script wrapping works!')\n" +101 "println context.getVariable('text')");102 bean.execute(context);103 }104 105 @Test106 public void testCustomScriptTemplate() {107 GroovyAction bean = new GroovyAction();108 109 bean.setScriptTemplatePath("classpath:com/consol/citrus/script/custom-script-template.groovy");110 111 bean.setScript("Assert.assertEquals(context.getVariable('scriptTemplateVar'), 'It works!')");112 bean.execute(context);113 }114 115 @Test116 public void testInvalidScriptTemplate() {117 GroovyAction bean = new GroovyAction();118 119 bean.setScriptTemplatePath("classpath:com/consol/citrus/script/invalid-script-template.groovy");120 bean.setScript("println 'This should not work!'");121 122 try {123 bean.execute(context);124 Assert.fail("Missing exception because of invalid script template");125 } catch (CitrusRuntimeException e) {126 Assert.assertTrue(e.getMessage().startsWith("Invalid script template"));127 }128 }129}...

Full Screen

Full Screen

Source:GroovyActionParserTest.java Github

copy

Full Screen

...15 */16package com.consol.citrus.config.xml;17import org.testng.Assert;18import org.testng.annotations.Test;19import com.consol.citrus.script.GroovyAction;20import com.consol.citrus.testng.AbstractActionParserTest;21/**22 * @author Christoph Deppisch23 */24public class GroovyActionParserTest extends AbstractActionParserTest<GroovyAction> {25 @Test26 public void testActionParser() {27 assertActionCount(4);28 assertActionClassAndName(GroovyAction.class, "groovy");29 30 GroovyAction action = getNextTestActionFromTest();31 Assert.assertNull(action.getScriptResourcePath());32 Assert.assertEquals(action.getScriptTemplatePath(), "classpath:com/consol/citrus/script/script-template.groovy");33 Assert.assertEquals(action.getScript().trim(), "println 'Hello Citrus'");34 35 action = getNextTestActionFromTest();36 Assert.assertNull(action.getScriptResourcePath());37 Assert.assertNotNull(action.getScript());38 Assert.assertEquals(action.isUseScriptTemplate(), false);39 40 action = getNextTestActionFromTest();41 Assert.assertNull(action.getScriptResourcePath());42 Assert.assertEquals(action.getScriptTemplatePath(), "classpath:com/consol/citrus/script/custom-script-template.groovy");43 Assert.assertNotNull(action.getScript());44 ...

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.testng.TestNGCitrusTest;3import com.consol.citrus.script.GroovyAction;4import org.testng.annotations.Test;5public class GroovyActionJavaIT extends TestNGCitrusTest {6public void testGroovyAction() {7TestRunner runner = this.getTestRunner();8runner.groovy(new GroovyAction() {9public void execute() {10System.out.println("Hello World!");11}12});13}14}15import com.consol.citrus.dsl.builder.GroovyActionBuilder;16import com.consol.citrus.dsl.runner.TestRunner;17import com.consol.citrus.dsl.testng.TestNGCitrusTest;18import org.testng.annotations.Test;19public class GroovyActionBuilderJavaIT extends TestNGCitrusTest {20public void testGroovyActionBuilder() {21TestRunner runner = this.getTestRunner();22runner.groovy(new GroovyActionBuilder() {23public void configure() {24script("println 'Hello World!'");25}26});27}28}29import com.consol.citrus.dsl.builder.GroovyActionBuilder;30import com.consol.citrus.dsl.runner.TestRunner;31import com.consol.citrus.dsl.testng.TestNGCitrusTest;32import org.testng.annotations.Test;33public class GroovyActionBuilderJavaIT extends TestNGCitrusTest {34public void testGroovyActionBuilder() {35TestRunner runner = this.getTestRunner();36runner.groovy(new GroovyActionBuilder() {37public void configure() {38script("println 'Hello World!'");39}40});41}42}43import com.consol.citrus.dsl.builder.GroovyActionBuilder;44import com.consol.citrus.dsl.runner.TestRunner;45import com.consol.citrus.dsl.testng.TestNGCitrusTest;46import org.testng.annotations.Test;47public class GroovyActionBuilderJavaIT extends TestNGCitrusTest {48public void testGroovyActionBuilder() {49TestRunner runner = this.getTestRunner();

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;2import com.consol.citrus.script.GroovyAction;3import org.springframework.core.io.ClassPathResource;4import org.testng.annotations.Test;5public class 4 extends TestNGCitrusTestDesigner {6 public void 4() {7 variable("var1", "value1");8 variable("var2", "value2");9 GroovyAction groovyAction = new GroovyAction();10 groovyAction.setScript(new ClassPathResource("groovy-script.groovy"));11 groovyAction.setVariables("var1", "var2");12 groovyAction.setVariable("var3", "value3");13 run(groovyAction);14 }15}16import com.consol.citrus.context.TestContext17def execute(TestContext context) {18 println "Variables: " + context.getVariables()19}

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;3import com.consol.citrus.script.GroovyAction;4import org.testng.annotations.Test;5public class GroovyActionJavaITest extends TestNGCitrusTestRunner {6 public void groovyAction() {7 variable("var1", "Hello Citrus!");8 groovy(new GroovyAction() {9 public void execute() {10 println("Hello from Groovy!");11 println("var1 = " + variable("var1"));12 }13 });14 }15}

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTest;4import com.consol.citrus.script.GroovyAction;5import org.testng.annotations.Test;6public class GroovyActionJavaITest extends TestNGCitrusTest {7 public void groovyActionJavaITest() {8 variable("var1", "value1");9 variable("var2", "value2");10 description("Groovy action test");11 echo("Groovy action test");12 groovy(new GroovyAction() {13 public void execute(TestRunner runner) {14 runner.variable("var3", "value3");15 runner.echo("Groovy action test");16 }17 });18 }19}20package com.consol.citrus.dsl;21import com.consol.citrus.dsl.runner.TestRunner;22import com.consol.citrus.dsl.testng.TestNGCitrusTest;23import com.consol.citrus.script.JavaScriptAction;24import org.testng.annotations.Test;25public class JavaScriptActionJavaITest extends TestNGCitrusTest {26 public void javaScriptActionJavaITest() {27 variable("var1", "value1");28 variable("var2", "value2");29 description("JavaScript action test");30 echo("JavaScript action test");31 javascript(new JavaScriptAction() {32 public void execute(TestRunner runner) {33 runner.variable("var3", "value3");34 runner.echo("JavaScript action test");35 }36 });37 }38}39package com.consol.citrus.dsl;40import com.consol.citrus.dsl.runner.TestRunner;41import com.consol.citrus.dsl.testng.TestNGCitrusTest;42import com.consol.citrus.script.XQueryAction;43import org.testng.annotations.Test;44public class XQueryActionJavaITest extends TestNGCitrusTest {45 public void xQueryActionJavaITest() {46 variable("var1", "value1");47 variable("var2", "value2");48 description("XQuery action test");49 echo("X

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.script;2import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;3import org.testng.annotations.Test;4public class GroovyActionJavaITest extends TestNGCitrusTestRunner {5 public void groovyActionJavaITest() {6 variable("name", "Citrus");7 groovy(new GroovyAction()8 .script("println 'Hello ' + name"));9 }10}11package com.consol.citrus.dsl.builder;12import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;13import org.testng.annotations.Test;14public class GroovyActionBuilderJavaITest extends TestNGCitrusTestRunner {15 public void groovyActionBuilderJavaITest() {16 variable("name", "Citrus");17 groovy()18 .script("println 'Hello ' + name");19 }20}21package com.consol.citrus.dsl.builder;22import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;23import org.testng.annotations.Test;24public class GroovyActionBuilderJavaITest extends TestNGCitrusTestRunner {25 public void groovyActionBuilderJavaITest() {26 variable("name", "Citrus");27 groovy()28 .script("println 'Hello ' + name");29 }30}31package com.consol.citrus.dsl.builder;32import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;33import org.testng.annotations.Test;34public class GroovyActionBuilderJavaITest extends TestNGCitrusTestRunner {35 public void groovyActionBuilderJavaITest() {36 variable("name", "Citrus");37 groovy()38 .script("println 'Hello ' + name");39 }40}41package com.consol.citrus.dsl.builder;42import com.consol.citrus.dsl.testng.TestNG

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.GroovyActionBuilder;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.builder.GroovyActionBuilder.GroovyAction;4import com.consol.citrus.dsl.builder.GroovyActionBuilder.GroovyActionBuilderSupport;5public class 4 extends GroovyActionBuilderSupport<4> {6 public 4(TestRunner runner) {7 super(runner);8 }9 public void configure() {10 GroovyAction groovyAction = new GroovyAction();11 groovyAction.setScriptResourcePath("classpath:com/consol/citrus/script/sample.groovy");12 groovyAction.setScriptData("println 'Hello Citrus!'");13 groovyAction.setScriptEngine("groovy");14 groovyAction.setScriptVariable("myVar", "Hello Citrus!");15 groovyAction.setScriptVariable("myVar2", "Hello Citrus!");16 groovyAction.setScriptVariable("myVar3", "Hello Citrus!");17 groovyAction.setScriptVariable("myVar4", "Hello Citrus!");18 groovyAction.setScriptVariable("myVar5", "Hello Citrus!");19 groovyAction.setScriptVariable("myVar6", "Hello Citrus!");20 groovyAction.setScriptVariable("myVar7", "Hello Citrus!");21 groovyAction.setScriptVariable("myVar8", "Hello Citrus!");22 groovyAction.setScriptVariable("myVar9", "Hello Citrus!");23 groovyAction.setScriptVariable("myVar10", "Hello Citrus!");24 groovyAction.setScriptVariable("myVar11", "Hello Citrus!");25 groovyAction.setScriptVariable("myVar12", "Hello Citrus!");26 groovyAction.setScriptVariable("myVar13", "Hello Citrus!");27 groovyAction.setScriptVariable("myVar14", "Hello Citrus!");28 groovyAction.setScriptVariable("myVar15", "Hello Citrus!");29 groovyAction.setScriptVariable("myVar16", "Hello Citrus!");30 groovyAction.setScriptVariable("myVar17", "Hello Citrus!");31 groovyAction.setScriptVariable("myVar18", "Hello Citrus!");

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;3import org.testng.annotations.Test;4public class GroovyActionJavaITest extends TestNGCitrusTestBuilder {5 public void groovyActionJavaITest() {6 variable("name", "Citrus");7 groovy(new GroovyAction.Builder()8 .script("println 'Hello ' + name")9 .build());10 }11}12package com.consol.citrus.dsl.testng;13import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;14import org.testng.annotations.Test;15public class GroovyActionJavaITest extends TestNGCitrusTestBuilder {16 public void groovyActionJavaITest() {17 variable("name", "Citrus");18 groovy().script("println 'Hello ' + name");19 }20}21package com.consol.citrus.dsl.testng;22import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;23import org.testng.annotations.Test;24public class GroovyActionJavaITest extends TestNGCitrusTestBuilder {25 public void groovyActionJavaITest() {26 variable("name", "Citrus");27 groovy().script("println 'Hello ' + name").execute();28 }29}30package com.consol.citrus.dsl.testng;31import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;32import org.testng.annotations.Test;33public class GroovyActionJavaITest extends TestNGCitrusTestBuilder {34 public void groovyActionJavaITest() {35 variable("name", "Citrus");36 groovy().script("println 'Hello ' + name").execute(context);37 }38}39package com.consol.citrus.dsl.testng;40import com.consol.citrus.dsl.testng.TestNGCit

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.GroovyActionBuilder;2import com.consol.citrus.dsl.builder.GroovyActionBuilder.groovy;3public class 4 extends GroovyActionBuilder {4 public void configure() {5 groovy(new com.consol.citrus.script.GroovyAction() {6 public void execute(com.consol.citrus.context.TestContext context) {7 }8 });9 }10}11import com.consol.citrus.dsl.builder.GroovyActionBuilder;12import com.consol.citrus.dsl.builder.GroovyActionBuilder.groovy;13public class 5 extends GroovyActionBuilder {14 public void configure() {15 groovy(new com.consol.citrus.script.GroovyAction() {16 public void execute(com.consol.citrus.context.TestContext context) {17 }18 });19 }20}21import com.consol.citrus.dsl.builder.GroovyActionBuilder;22import com.consol.citrus.dsl.builder.GroovyActionBuilder.groovy;23public class 6 extends GroovyActionBuilder {24 public void configure() {25 groovy(new com.consol.citrus.script.GroovyAction() {26 public void execute(com.consol.citrus.context.TestContext context) {27 }28 });29 }30}31import com.consol.citrus.dsl.builder.GroovyActionBuilder;32import com.consol.citrus.dsl.builder.GroovyActionBuilder.groovy;33public class 7 extends GroovyActionBuilder {34 public void configure() {35 groovy(new com.consol.citrus.script.GroovyAction() {36 public void execute(com.consol.citrus.context.TestContext context) {37 }38 });39 }40}

Full Screen

Full Screen

GroovyAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.script;2import com.consol.citrus.dsl.junit.JUnit4CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.testng.annotations.Test;5public class GroovyActionJavaIT extends JUnit4CitrusTest {6 public void testGroovyAction() {7 run(new TestNGCitrusTestDesigner() {8 public void configure() {9 groovy(new GroovyAction() {10 public void execute(GroovyActionBuilder builder) {11 builder.script("src/test/resources/groovy/test.groovy");12 }13 });14 }15 });16 }17}18import com.consol.citrus.dsl.builder.GroovyActionBuilder;19import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;20import com.consol.citrus.dsl.builder.SendMessageActionBuilder;21public void execute(GroovyActionBuilder builder) {22 builder.send("helloEndpoint")23 .payload("Hello Citrus!");24 builder.receive("helloEndpoint")25 .payload("Hello Citrus!");26}27package com.consol.citrus.script;28import com.consol.citrus.dsl.junit.JUnit4CitrusTest;29import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;30import org.testng.annotations.Test;31public class GroovyScriptJavaIT extends JUnit4CitrusTest {32 public void testGroovyScript() {33 run(new TestNGCitrusTestDesigner() {34 public void configure() {35 groovy(new GroovyScript() {36 public void execute(GroovyScriptBuilder builder) {37 builder.script("src/test/resources/groovy/test.groovy");38 }39 });40 }41 });42 }43}44import com.consol.citrus.dsl.builder.GroovyScriptBuilder;45import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;46import com.consol.citrus.dsl.builder.SendMessage

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful