Best Citrus code snippet using com.consol.citrus.dsl.runner.ConditionalTestRunnerTest.testConditionalBuilder
Source:ConditionalTestRunnerTest.java
...23import static org.hamcrest.Matchers.is;24import static org.hamcrest.Matchers.lessThan;25public class ConditionalTestRunnerTest extends AbstractTestNGUnitTest {26 @Test27 public void testConditionalBuilder() {28 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {29 @Override30 public void execute() {31 variable("var", 5);32 conditional().when("${var} = 5")33 .actions(echo("${var}"), createVariable("execution", "true"));34 }35 };36 TestContext context = builder.getTestContext();37 Assert.assertNotNull(context.getVariable("execution"));38 Assert.assertEquals(context.getVariable("execution"), "true");39 TestCase test = builder.getTestCase();40 Assert.assertEquals(test.getActionCount(), 1);41 Assert.assertEquals(test.getActions().get(0).getClass(), Conditional.class);42 Assert.assertEquals(test.getActions().get(0).getName(), "conditional");43 Conditional container = (Conditional)test.getActions().get(0);44 Assert.assertEquals(container.getActionCount(), 2);45 Assert.assertEquals(container.getCondition(), "${var} = 5");46 }47 @Test48 public void testConditionalBuilderSkip() {49 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {50 @Override51 public void execute() {52 variable("var", 0);53 conditional().when("${var} = 5")54 .actions(echo("${var}"), createVariable("execution", "true"));55 }56 };57 TestContext context = builder.getTestContext();58 Assert.assertNull(context.getVariables().get("execution"));59 TestCase test = builder.getTestCase();60 Assert.assertEquals(test.getActionCount(), 1);61 Assert.assertEquals(test.getActions().get(0).getClass(), Conditional.class);62 Assert.assertEquals(test.getActions().get(0).getName(), "conditional");63 Conditional container = (Conditional)test.getActions().get(0);64 Assert.assertEquals(container.getActionCount(), 2);65 Assert.assertEquals(container.getCondition(), "${var} = 5");66 }67 @Test68 public void testConditionalBuilderConditionExpression() {69 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {70 @Override71 public void execute() {72 variable("var", 5);73 conditional().when(context -> context.getVariable("var").equals("5"))74 .actions(echo("${var}"), createVariable("execution", "true"));75 }76 };77 TestContext context = builder.getTestContext();78 Assert.assertNotNull(context.getVariable("execution"));79 Assert.assertEquals(context.getVariable("execution"), "true");80 TestCase test = builder.getTestCase();81 Assert.assertEquals(test.getActionCount(), 1);82 Assert.assertEquals(test.getActions().get(0).getClass(), Conditional.class);83 Assert.assertEquals(test.getActions().get(0).getName(), "conditional");84 Conditional container = (Conditional)test.getActions().get(0);85 Assert.assertEquals(container.getActionCount(), 2);86 Assert.assertNotNull(container.getConditionExpression());87 }88 @Test89 public void testConditionalBuilderHamcrestConditionExpression() {90 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {91 @Override92 public void execute() {93 variable("var", 5);94 variable("noExecution", "true");95 conditional().when("${var}", is("5"))96 .actions(echo("${var}"), createVariable("execution", "true"));97 conditional().when("${var}", lessThan("5"))98 .actions(echo("${var}"), createVariable("noExecution", "false"));99 }100 };101 TestContext context = builder.getTestContext();102 Assert.assertNotNull(context.getVariable("noExecution"));103 Assert.assertEquals(context.getVariable("noExecution"), "true");...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!