Best Citrus code snippet using com.consol.citrus.selenium.actions.FindElementActionTest.validationErrorProvider
Source:FindElementActionTest.java
...111 action.setPropertyValue("clickMe");112 action.execute(context);113 Assert.assertEquals(context.getVariableObject("button"), element);114 }115 @Test(dataProvider = "validationErrorProvider")116 public void testExecuteFindByValidationFailed(String tagName, String text, String attribute, String cssStyle, boolean displayed, boolean enabled, String errorMsg) throws Exception {117 when(element.getTagName()).thenReturn("button");118 when(element.getText()).thenReturn("Click Me!");119 when(element.getAttribute("type")).thenReturn("submit");120 when(element.getCssValue("color")).thenReturn("red");121 when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {122 @Override123 public WebElement answer(InvocationOnMock invocation) throws Throwable {124 By select = (By) invocation.getArguments()[0];125 Assert.assertEquals(select.getClass(), By.ByName.class);126 Assert.assertEquals(select.toString(), By.name("clickMe").toString());127 return element;128 }129 });130 action.setTagName(tagName);131 action.setText(text);132 action.setAttributes(Collections.singletonMap("type", attribute));133 action.setStyles(Collections.singletonMap("color", cssStyle));134 action.setDisplayed(displayed);135 action.setEnabled(enabled);136 action.setProperty("name");137 action.setPropertyValue("clickMe");138 try {139 action.execute(context);140 Assert.fail("Missing exception to to validation error");141 } catch (Exception e) {142 Assert.assertTrue(e.getMessage().endsWith(errorMsg), e.getMessage());143 }144 }145 @DataProvider146 public Object[][] validationErrorProvider() {147 return new Object[][] {148 new Object[] { "input", "Click Me!", "submit", "red", true, true, "tag-name expected 'input', but was 'button'" },149 new Object[] { "button", "Click!", "submit", "red", true, true, "text expected 'Click!', but was 'Click Me!'" },150 new Object[] { "button", "Click Me!", "cancel", "red", true, true, "attribute 'type' expected 'cancel', but was 'submit'" },151 new Object[] { "button", "Click Me!", "submit", "red", false, true, "'displayed' expected 'false', but was 'true'" },152 new Object[] { "button", "Click Me!", "submit", "red", true, false, "'enabled' expected 'false', but was 'true'" },153 new Object[] { "button", "Click Me!", "submit", "blue", true, true, "css style 'color' expected 'blue', but was 'red'" }154 };155 }156 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Failed to find element 'id=myButton' on page")157 public void testElementNotFound() {158 when(webDriver.findElement(any(By.class))).thenReturn(null);159 action.setProperty("id");160 action.setPropertyValue("myButton");...
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!!