How to use setProperty method of com.consol.citrus.selenium.actions.FindElementAction class

Best Citrus code snippet using com.consol.citrus.selenium.actions.FindElementAction.setProperty

Source:SeleniumActionBuilder.java Github

copy

Full Screen

...547 * Add element property and value selector.548 * @return549 */550 public ElementActionBuilder element(String property, String propertyValue) {551 action.setProperty(property);552 action.setPropertyValue(propertyValue);553 return this;554 }555 @Override556 public TestAction build() {557 return SeleniumActionBuilder.this.build();558 }559 }560 /**561 * Customize element selecting action.562 */563 public class FindElementActionBuilder extends ElementActionBuilder<FindElementAction> {564 /** Find element action */565 private final FindElementAction action;566 /**...

Full Screen

Full Screen

Source:FindElementAction.java Github

copy

Full Screen

...152 * Sets the property.153 *154 * @param property155 */156 public void setProperty(String property) {157 this.property = property;158 }159 /**160 * Gets the propertyValue.161 *162 * @return163 */164 public String getPropertyValue() {165 return propertyValue;166 }167 /**168 * Sets the propertyValue.169 *170 * @param propertyValue171 */172 public void setPropertyValue(String propertyValue) {173 this.propertyValue = propertyValue;174 }175 /**176 * Gets the tagName.177 *178 * @return179 */180 public String getTagName() {181 return tagName;182 }183 /**184 * Sets the tagName.185 *186 * @param tagName...

Full Screen

Full Screen

Source:FindElementActionTest.java Github

copy

Full Screen

...54 Assert.assertEquals(select.toString(), by.toString());55 return element;56 }57 });58 action.setProperty(property);59 action.setPropertyValue(value);60 action.execute(context);61 Assert.assertEquals(context.getVariableObject("button"), element);62 }63 @DataProvider64 public Object[][] findByProvider() {65 return new Object[][] {66 new Object[] { "id", "myId", By.id("myId") },67 new Object[] { "name", "myName", By.name("myName") },68 new Object[] { "tag-name", "button", By.tagName("button") },69 new Object[] { "class-name", "myClass", By.className("myClass") },70 new Object[] { "link-text", "myLinkText", By.linkText("myLinkText") },71 new Object[] { "css-selector", "myCss", By.cssSelector("myCss") },72 new Object[] { "xpath", "myXpath", By.xpath("myXpath") }73 };74 }75 @Test76 public void testExecuteFindByVariableSupport() throws Exception {77 when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {78 @Override79 public WebElement answer(InvocationOnMock invocation) throws Throwable {80 By select = (By) invocation.getArguments()[0];81 Assert.assertEquals(select.getClass(), By.ById.class);82 Assert.assertEquals(select.toString(), By.id("clickMe").toString());83 return element;84 }85 });86 context.setVariable("myId", "clickMe");87 action.setProperty("id");88 action.setPropertyValue("${myId}");89 action.execute(context);90 Assert.assertEquals(context.getVariableObject("button"), element);91 }92 @Test93 public void testExecuteFindByValidation() throws Exception {94 when(element.getText()).thenReturn("Click Me!");95 when(element.getAttribute("type")).thenReturn("submit");96 when(element.getCssValue("color")).thenReturn("red");97 when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {98 @Override99 public WebElement answer(InvocationOnMock invocation) throws Throwable {100 By select = (By) invocation.getArguments()[0];101 Assert.assertEquals(select.getClass(), By.ByName.class);102 Assert.assertEquals(select.toString(), By.name("clickMe").toString());103 return element;104 }105 });106 action.setTagName("button");107 action.setText("Click Me!");108 action.setAttributes(Collections.singletonMap("type", "submit"));109 action.setStyles(Collections.singletonMap("color", "red"));110 action.setProperty("name");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");161 action.execute(context);162 }163 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Unknown selector type: unsupported")164 public void testElementUnsupportedProperty() {165 action.setProperty("unsupported");166 action.setPropertyValue("wrong");167 action.execute(context);168 }169}...

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import org.mockito.Mockito;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.testng.annotations.Test;8import static org.mockito.Mockito.*;9public class FindElementActionTest extends AbstractTestNGUnitTest {10 private SeleniumBrowser browser = Mockito.mock(SeleniumBrowser.class);11 private WebElement webElement = Mockito.mock(WebElement.class);12 public void testFindElement() {13 FindElementAction action = new FindElementAction.Builder()14 .browser(browser)15 .locator(By.id("test"))16 .build();17 reset(browser);18 when(browser.findElement(By.id("test"))).thenReturn(webElement);19 action.execute(context);20 verify(browser).findElement(By.id("test"));21 verify(webElement).isDisplayed();22 }23 public void testFindElementWithWait() {24 FindElementAction action = new FindElementAction.Builder()25 .browser(browser)26 .locator(By.id("test"))27 .waitFor("1000")28 .build();29 reset(browser);30 when(browser.findElement(By.id("test"))).thenReturn(webElement);31 action.execute(context);32 verify(browser).findElement(By.id("test"));33 verify(webElement).isDisplayed();34 }35}36package com.consol.citrus.selenium.actions;37import com.consol.citrus.selenium.endpoint.SeleniumBrowser;38import com.consol.citrus.testng.AbstractTestNGUnitTest;39import org.mockito.Mockito;40import org.openqa.selenium.By;41import org.openqa.selenium.WebElement;42import org.testng.annotations.Test;43import java.util.ArrayList;44import java.util.List;45import static org.mockito.Mockito.*;46public class FindElementsActionTest extends AbstractTestNGUnitTest {47 private SeleniumBrowser browser = Mockito.mock(SeleniumBrowser.class);48 private WebElement webElement = Mockito.mock(WebElement.class);49 public void testFindElements() {50 FindElementsAction action = new FindElementsAction.Builder()51 .browser(browser)52 .locator(By.id("test"))53 .build();54 reset(browser);55 List<WebElement> elements = new ArrayList<>();56 elements.add(webElement);57 when(browser.findElements(By.id("test"))).thenReturn(elements);58 action.execute(context

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.springframework.util.StringUtils;6public class FindElementAction extends AbstractSeleniumAction {7 private final By by;8 private String variable;9 public FindElementAction(Builder builder) {10 super("find-element", builder);11 this.by = builder.by;12 this.variable = builder.variable;13 }14 public void doExecute(SeleniumBrowser browser) {15 WebElement element = browser.getWebDriver().findElement(by);16 if (StringUtils.hasText(variable)) {17 getVariableUtils().setVariable(variable, element);18 }19 }20 public By getBy() {21 return by;22 }23 public String getVariable() {24 return variable;25 }26 public static class Builder extends AbstractSeleniumAction.Builder<FindElementAction, Builder> {27 private By by;28 private String variable;29 public Builder by(By by) {30 this.by = by;31 return this;32 }33 public Builder variable(String variable) {34 this.variable = variable;35 return this;36 }37 public FindElementAction build() {38 return new FindElementAction(this);39 }40 }41}42package com.consol.citrus.selenium.actions;43import com.consol.citrus.selenium.endpoint.SeleniumBrowser;44import org.openqa.selenium.By;45import org.openqa.selenium.WebElement;46import org.springframework.util.StringUtils;47import java.util.List;48public class FindElementsAction extends AbstractSeleniumAction {49 private final By by;50 private String variable;51 public FindElementsAction(Builder builder) {52 super("find-elements", builder);53 this.by = builder.by;54 this.variable = builder.variable;55 }56 public void doExecute(SeleniumBrowser browser)

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package org.example;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.selenium.endpoint.SeleniumBrowser;5import com.consol.citrus.selenium.endpoint.SeleniumHeaders;6import org.openqa.selenium.By;7import org.openqa.selenium.WebElement;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.core.io.ClassPathResource;10import org.testng.annotations.Test;11public class 3 extends TestNGCitrusTestRunner {12 private SeleniumBrowser seleniumBrowser;13 public void 3() {14 variable("element", "css=div");15 variable("attribute", "class");16 selenium(action -> action17 .browser(seleniumBrowser)18 .setVariable("element", "css=div")19 .setVariable("attribute", "class")20 .findElement((By) variable("element"))21 .setProperty((String) variable("attribute"), "test")22 );23 }24}25package org.example;26import com.consol.citrus.annotations.CitrusTest;27import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;28import com.consol.citrus.selenium.endpoint.SeleniumBrowser;29import com.consol.citrus.selenium.endpoint.SeleniumHeaders;30import org.openqa.selenium.By;31import org.openqa.selenium.WebElement;32import org.springframework.beans.factory.annotation.Autowired;33import org.springframework.core.io.ClassPathResource;34import org.testng.annotations.Test;35public class 4 extends TestNGCitrusTestRunner {36 private SeleniumBrowser seleniumBrowser;37 public void 4() {38 selenium(action -> action39 .browser(seleniumBrowser)40 .findElement(By.cssSelector("div"))41 .setProperty("class", "test")42 );43 }44}45package org.example;46import com.consol.citrus.annotations.CitrusTest;47import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;48import com.consol.citrus.selenium.endpoint.SeleniumBrowser;49import com.consol.citrus.selenium.endpoint.SeleniumHeaders;50import org.openqa.selenium.By;51import org

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.springframework.util.Assert;6public class FindElementAction extends AbstractSeleniumAction {7 private final By locator;8 private String variable;9 public FindElementAction(Builder builder) {10 super("find-element", builder);11 this.locator = builder.locator;12 this.variable = builder.variable;13 }14 public void doExecute(SeleniumBrowser browser) {15 WebElement element = browser.getWebDriver().findElement(locator);16 if (variable != null) {17 getTestContext().setProperty(variable, element);18 }19 }20 public By getLocator() {21 return locator;22 }23 public String getVariable() {24 return variable;25 }26 public static final class Builder extends AbstractSeleniumAction.Builder<FindElementAction, Builder> {27 private By locator;28 private String variable;29 public static Builder findElement() {30 return new Builder();31 }32 public Builder locator(By locator) {33 this.locator = locator;34 return this;35 }36 public Builder variable(String variable) {37 this.variable = variable;38 return this;39 }40 public FindElementAction build() {41 Assert.notNull(locator, "Locator is missing");42 return new FindElementAction(this);43 }44 }45}46package com.consol.citrus.selenium.actions;47import com.consol.citrus.selenium.endpoint.SeleniumBrowser;48import org.openqa.selenium.By;49import org.openqa.selenium.WebElement;50import org.springframework.util.Assert;51import java.util.List;52public class FindElementsAction extends AbstractSeleniumAction {53 private final By locator;54 private String variable;

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import java.util.Properties;3import org.openqa.selenium.By;4import com.consol.citrus.context.TestContext;5public class FindElementAction extends AbstractSeleniumAction {6 private By locator;7 private String element;8 private String property;9 public FindElementAction(Builder builder) {10 super("find-element", builder);11 this.locator = builder.locator;12 this.element = builder.element;13 this.property = builder.property;14 }15 public void doExecute(TestContext context) {16 if (element != null) {17 context.setVariable(element, getWebDriver(context).findElement(locator));18 } else if (property != null) {19 context.setProperty(property, getWebDriver(context).findElement(locator));20 }21 }22 public By getLocator() {23 return locator;24 }25 public String getElement() {26 return element;27 }28 public String getProperty() {29 return property;30 }31 public static final class Builder extends AbstractSeleniumAction.Builder<FindElementAction, Builder> {32 private By locator;33 private String element;34 private String property;35 public Builder locator(By locator) {36 this.locator = locator;37 return this;38 }39 public Builder element(String element) {40 this.element = element;41 return this;42 }43 public Builder property(String property) {44 this.property = property;45 return this;46 }47 public FindElementAction build() {48 return new FindElementAction(this);49 }50 }51}52package com.consol.citrus.selenium.actions;53import java.util.Properties;54import org.openqa.selenium.By;55import com.consol.citrus.context.TestContext;56public class FindElementAction extends AbstractSeleniumAction {57 private By locator;58 private String element;59 private String property;60 public FindElementAction(Builder builder) {61 super("find-element", builder);62 this.locator = builder.locator;

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.springframework.util.StringUtils;6public class FindElementAction extends AbstractSeleniumAction {7 private final By locator;8 private final String variable;9 public FindElementAction(Builder builder) {10 super("find-element", builder);11 this.locator = builder.locator;12 this.variable = builder.variable;13 }14 public void doExecute(SeleniumBrowser browser) {15 WebElement element = browser.getWebDriver().findElement(locator);16 if (StringUtils.hasText(variable)) {17 browser.setProperty(variable, element);18 }19 }20 public By getLocator() {21 return locator;22 }23 public String getVariable() {24 return variable;25 }26 public static class Builder extends AbstractSeleniumAction.Builder<FindElementAction, Builder> {27 private By locator;28 private String variable;29 public static Builder findElement() {30 return new Builder();31 }32 public Builder locator(By locator) {33 this.locator = locator;34 return this;35 }36 public Builder variable(String variable) {37 this.variable = variable;38 return this;39 }40 public FindElementAction build() {41 return new FindElementAction(this);42 }43 }44}45package com.consol.citrus.selenium.actions;46import com.consol.citrus.selenium.endpoint.SeleniumBrowser;47import org.openqa

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import com.consol.citrus.selenium.endpoint.SeleniumHeaders;4import com.consol.citrus.selenium.endpoint.SeleniumMessage;5import com.consol.citrus.selenium.endpoint.SeleniumMessageConverter;6import com.consol.citrus.selenium.endpoint.SeleniumMessageHandler;7import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;8import com.consol.citrus.selenium.endpoint.SeleniumMessageUtils;9import com.consol.citrus.selenium.endpoint.SeleniumEndpoints;10import com.consol.citrus.selenium.endpoint.SeleniumMessage;11import com.consol.citrus.exceptions.CitrusRuntimeException;12import com.consol.citrus.selenium.endpoint.SeleniumEndpoints;13import com.consol.citrus.selenium.endpoint.SeleniumMessage;14import com.consol.citrus.selenium.endpoint.SeleniumMessageConverter;15import com.consol.citrus.selenium.endpoint.SeleniumMessageHandler;16import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;17import com.consol.citrus.selenium.endpoint.SeleniumMessageUtils;18import com.consol.citrus.selenium.endpoint.SeleniumHeaders;19import com.consol.citrus.selenium.endpoint.SeleniumBrowser;20import com.consol.citrus.selenium.endpoint.SeleniumEndpoints;21import com.consol.citrus.selenium.endpoint.SeleniumMessage;22import com.consol.citrus.selenium.endpoint.SeleniumMessageConverter;23import com.consol.citrus.selenium.endpoint.SeleniumMessageHandler;24import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;25import com.consol.citrus.selenium.endpoint.SeleniumMessageUtils;26import com.consol.citrus.selenium.endpoint.SeleniumHeaders;27import com.consol.citrus.selenium.endpoint.SeleniumBrowser;28import com.consol.citrus.selenium.endpoint.SeleniumEndpoints;29import com.consol.citrus.selenium.endpoint.SeleniumMessage;30import com.consol.citrus.selenium.endpoint.SeleniumMessageConverter;31import com.consol.citrus.selenium.endpoint.SeleniumMessageHandler;32import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;33import com.consol.citrus.selenium.endpoint.SeleniumMessageUtils;34import com.consol.citrus.selenium.endpoint.SeleniumHeaders;35import com.consol.citrus.selenium.endpoint.SeleniumBrowser;36import com.consol.citrus.selenium.endpoint.SeleniumEndpoints;37import com.consol.citrus.selenium.endpoint.SeleniumMessage;38import

Full Screen

Full Screen

setProperty

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) {3 SeleniumBrowser browser = new SeleniumBrowser();4 FindElementAction findElementAction = new FindElementAction();5 findElementAction.setBrowser(browser);6 findElementAction.setLocator("id=company");7 findElementAction.setProperty("value");8 findElementAction.execute();9 }10}11public class 4 {12 public static void main(String[] args) {13 SeleniumBrowser browser = new SeleniumBrowser();14 FindElementAction findElementAction = new FindElementAction();15 findElementAction.setBrowser(browser);16 findElementAction.setLocator("id=company");17 findElementAction.setProperty("value");18 findElementAction.execute();19 }20}21public class 5 {22 public static void main(String[] args) {23 SeleniumBrowser browser = new SeleniumBrowser();24 FindElementAction findElementAction = new FindElementAction();25 findElementAction.setBrowser(browser);26 findElementAction.setLocator("id=company");27 findElementAction.setProperty("value");28 findElementAction.execute();29 }30}31public class 6 {32 public static void main(String[] args) {33 SeleniumBrowser browser = new SeleniumBrowser();34 FindElementAction findElementAction = new FindElementAction();35 findElementAction.setBrowser(browser);36 findElementAction.setLocator("id=company");37 findElementAction.setProperty("value");38 findElementAction.execute();39 }40}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful