Best Citrus code snippet using com.consol.citrus.dsl.builder.SeleniumActionBuilder.FindElementActionBuilder
Source:SeleniumActionBuilder.java
...124 }125 /**126 * Finds element.127 */128 public FindElementActionBuilder find() {129 FindElementAction action = new FindElementAction();130 action(action);131 return new FindElementActionBuilder(action);132 }133 /**134 * Dropdown select single option action.135 */136 public ElementActionBuilder select(String option) {137 DropDownSelectAction action = new DropDownSelectAction();138 action.setOption(option);139 action(action);140 return new ElementActionBuilder(action);141 }142 /**143 * Dropdown select multiple options action.144 */145 public ElementActionBuilder select(String ... options) {146 DropDownSelectAction action = new DropDownSelectAction();147 action.setOptions(Arrays.asList(options));148 action(action);149 return new ElementActionBuilder(action);150 }151 /**152 * Set input action.153 */154 public ElementActionBuilder setInput(String value) {155 SetInputAction action = new SetInputAction();156 action.setValue(value);157 action(action);158 return new ElementActionBuilder(action);159 }160 /**161 * Check input action.162 */163 public ElementActionBuilder checkInput(boolean checked) {164 CheckInputAction action = new CheckInputAction();165 action.setChecked(checked);166 action(action);167 return new ElementActionBuilder(action);168 }169 /**170 * Clicks element.171 */172 public ElementActionBuilder click() {173 ClickAction action = new ClickAction();174 action(action);175 return new ElementActionBuilder(action);176 }177 /**178 * Hover element.179 */180 public ElementActionBuilder hover() {181 HoverAction action = new HoverAction();182 action(action);183 return new ElementActionBuilder(action);184 }185 /**186 * Clear browser cache.187 */188 public SeleniumActionBuilder clearCache() {189 action(new ClearBrowserCacheAction());190 return this;191 }192 /**193 * Make screenshot.194 */195 public SeleniumActionBuilder screenshot() {196 action(new MakeScreenshotAction());197 return this;198 }199 /**200 * Make screenshot with custom output directory.201 */202 public SeleniumActionBuilder screenshot(String outputDir) {203 MakeScreenshotAction action = new MakeScreenshotAction();204 action.setOutputDir(outputDir);205 action(action);206 return this;207 }208 /**209 * Store file.210 * @param filePath211 */212 public SeleniumActionBuilder store(String filePath) {213 StoreFileAction action = new StoreFileAction();214 action.setFilePath(filePath);215 action(action);216 return this;217 }218 /**219 * Get stored file.220 * @param fileName221 */222 public SeleniumActionBuilder getStored(String fileName) {223 GetStoredFileAction action = new GetStoredFileAction();224 action.setFileName(fileName);225 action(action);226 return this;227 }228 /**229 * Wait until element meets condition.230 */231 public WaitUntilActionBuilder waitUntil() {232 WaitUntilAction action = new WaitUntilAction();233 action(action);234 return new WaitUntilActionBuilder(action);235 }236 /**237 * Execute JavaScript.238 */239 public JavaScriptActionBuilder javascript(String script) {240 JavaScriptAction action = new JavaScriptAction();241 action.setScript(script);242 action(action);243 return new JavaScriptActionBuilder(action);244 }245 /**246 * Execute JavaScript.247 */248 public JavaScriptActionBuilder javascript(Resource script) {249 return javascript(script, FileUtils.getDefaultCharset());250 }251 /**252 * Execute JavaScript.253 */254 public JavaScriptActionBuilder javascript(Resource script, Charset charset) {255 JavaScriptAction action = new JavaScriptAction();256 try {257 action.setScript(FileUtils.readToString(script, charset));258 } catch (IOException e) {259 throw new CitrusRuntimeException("Failed to read script resource", e);260 }261 action(action);262 return new JavaScriptActionBuilder(action);263 }264 /**265 * Open window.266 */267 public WindowActionBuilder open() {268 OpenWindowAction action = new OpenWindowAction();269 action(action);270 return new WindowActionBuilder(action);271 }272 /**273 * Close window.274 */275 public WindowActionBuilder close() {276 CloseWindowAction action = new CloseWindowAction();277 action(action);278 return new WindowActionBuilder(action);279 }280 /**281 * Switch window.282 */283 public WindowActionBuilder focus() {284 SwitchWindowAction action = new SwitchWindowAction();285 action(action);286 return new WindowActionBuilder(action);287 }288 /**289 * Prepare selenium action.290 */291 private <T extends SeleniumAction> T action(T delegate) {292 if (seleniumBrowser != null) {293 delegate.setBrowser(seleniumBrowser);294 }295 action.setDelegate(delegate);296 return delegate;297 }298 /**299 * Customize alert action.300 */301 public class AlertActionBuilder implements TestActionBuilder {302 /** Alert action */303 private final AlertAction action;304 /**305 * Default constructor.306 * @param action307 */308 public AlertActionBuilder(AlertAction action) {309 this.action = action;310 }311 /**312 * Add alert text validation.313 * @param text314 * @return315 */316 public AlertActionBuilder text(String text) {317 action.setText(text);318 return this;319 }320 /**321 * Accept alert dialog.322 * @return323 */324 public AlertActionBuilder accept() {325 action.setAccept(true);326 return this;327 }328 /**329 * Dismiss alert dialog.330 * @return331 */332 public AlertActionBuilder dismiss() {333 action.setAccept(false);334 return this;335 }336 @Override337 public TestAction build() {338 return SeleniumActionBuilder.this.build();339 }340 }341 /**342 * Customize page action.343 */344 public class PageActionBuilder implements TestActionBuilder {345 /** Alert action */346 private final PageAction action;347 /**348 * Default constructor.349 * @param action350 */351 public PageActionBuilder(PageAction action) {352 this.action = action;353 }354 /**355 * Perform page validation.356 * @return357 */358 public PageActionBuilder validate() {359 action.setAction("validate");360 return this;361 }362 /**363 * Set page validator.364 * @param validator365 * @return366 */367 public PageActionBuilder validator(PageValidator validator) {368 action.setValidator(validator);369 return this;370 }371 /**372 * Set page action method to execute.373 * @param method374 * @return375 */376 public PageActionBuilder execute(String method) {377 action.setAction(method);378 return this;379 }380 /**381 * Set page action argument.382 * @param arg383 * @return384 */385 public PageActionBuilder argument(String arg) {386 action.getArguments().add(arg);387 return this;388 }389 /**390 * Set page action arguments.391 * @param args392 * @return393 */394 public PageActionBuilder arguments(String ... args) {395 action.setArguments(Arrays.asList(args));396 return this;397 }398 /**399 * Set page action arguments.400 * @param args401 * @return402 */403 public PageActionBuilder arguments(List<String> args) {404 action.setArguments(args);405 return this;406 }407 @Override408 public TestAction build() {409 return SeleniumActionBuilder.this.build();410 }411 }412 /**413 * Customize javascript action.414 */415 public class JavaScriptActionBuilder implements TestActionBuilder {416 /** JavaScript action */417 private final JavaScriptAction action;418 /**419 * Default constructor.420 * @param action421 */422 public JavaScriptActionBuilder(JavaScriptAction action) {423 this.action = action;424 }425 /**426 * Add script argument.427 * @param arg428 * @return429 */430 public JavaScriptActionBuilder argument(Object arg) {431 action.getArguments().add(arg);432 return this;433 }434 /**435 * Add expected error.436 * @param errors437 * @return438 */439 public JavaScriptActionBuilder errors(String ... errors) {440 action.setExpectedErrors(Arrays.asList(errors));441 return this;442 }443 @Override444 public TestAction build() {445 return SeleniumActionBuilder.this.build();446 }447 }448 /**449 * Customize wait until action.450 */451 public class WaitUntilActionBuilder extends ElementActionBuilder<WaitUntilAction> {452 /** WaitUntil action */453 private final WaitUntilAction action;454 /**455 * Default constructor.456 * @param action457 */458 public WaitUntilActionBuilder(WaitUntilAction action) {459 super(action);460 this.action = action;461 }462 /**463 * Add visible condition.464 * @return465 */466 public WaitUntilActionBuilder visible() {467 action.setCondition("visible");468 return this;469 }470 /**471 * Add hidden condition.472 * @return473 */474 public WaitUntilActionBuilder hidden() {475 action.setCondition("hidden");476 return this;477 }478 /**479 * Add timeout condition.480 * @return481 */482 public WaitUntilActionBuilder timeout(Long timeout) {483 action.setTimeout(timeout);484 return this;485 }486 @Override487 public WaitUntilActionBuilder element(By by) {488 super.element(by);489 return this;490 }491 @Override492 public WaitUntilActionBuilder element(String property, String propertyValue) {493 super.element(property, propertyValue);494 return this;495 }496 }497 /**498 * Window accessing action.499 */500 public class WindowActionBuilder implements TestActionBuilder {501 /** Window action */502 private final SeleniumWindowAction action;503 /**504 * Default constructor.505 * @param action506 */507 public WindowActionBuilder(SeleniumWindowAction action) {508 this.action = action;509 }510 /**511 * Set window name.512 * @param name513 * @return514 */515 public WindowActionBuilder window(String name) {516 action.setWindowName(name);517 return this;518 }519 @Override520 public TestAction build() {521 return SeleniumActionBuilder.this.build();522 }523 }524 /**525 * Customize element selecting action.526 */527 public class ElementActionBuilder<T extends FindElementAction> implements TestActionBuilder {528 /** Element action */529 private final T action;530 /**531 * Default constructor.532 * @param action533 */534 public ElementActionBuilder(T action) {535 this.action = action;536 }537 /**538 * Add element selector.539 * @param by540 * @return541 */542 public ElementActionBuilder element(By by) {543 action.setBy(by);544 return this;545 }546 /**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 /**567 * Default constructor.568 * @param action569 */570 public FindElementActionBuilder(FindElementAction action) {571 super(action);572 this.action = action;573 }574 /**575 * Add tag name validation.576 * @param tagName577 * @return578 */579 public FindElementActionBuilder tagName(String tagName) {580 action.setTagName(tagName);581 return this;582 }583 /**584 * Add text validation.585 * @param text586 * @return587 */588 public FindElementActionBuilder text(String text) {589 action.setText(text);590 return this;591 }592 /**593 * Add attribute validation.594 * @param name595 * @param value596 * @return597 */598 public FindElementActionBuilder attribute(String name, String value) {599 action.getAttributes().put(name, value);600 return this;601 }602 /**603 * Add css style validation.604 * @param name605 * @param value606 * @return607 */608 public FindElementActionBuilder style(String name, String value) {609 action.getStyles().put(name, value);610 return this;611 }612 /**613 * Add enabled validation.614 * @param enabled615 * @return616 */617 public FindElementActionBuilder enabled(boolean enabled) {618 action.setEnabled(enabled);619 return this;620 }621 /**622 * Add displayed validation.623 * @param displayed624 * @return625 */626 public FindElementActionBuilder displayed(boolean displayed) {627 action.setDisplayed(displayed);628 return this;629 }630 @Override631 public FindElementActionBuilder element(By by) {632 super.element(by);633 return this;634 }635 @Override636 public FindElementActionBuilder element(String property, String propertyValue) {637 super.element(property, propertyValue);638 return this;639 }640 }641}...
Source:SeleniumSteps.java
...134 @Then("^(?:page )?should (?:display|have) (?:element|button|link|input|textfield|form|heading) with (id|name|class-name|link-text|css-selector|tag-name|xpath)=\"([^\"]+)\" having$")135 public void should_display(String property, String value, DataTable dataTable) {136 Map<String, String> elementProperties = dataTable.asMap(String.class, String.class);137 runner.selenium(action -> {138 SeleniumActionBuilder.FindElementActionBuilder elementBuilder = action.browser(browser)139 .find()140 .element(property, value);141 for (Map.Entry<String, String> propertyEntry : elementProperties.entrySet()) {142 if (propertyEntry.getKey().equals("tag-name")) {143 elementBuilder.tagName(propertyEntry.getValue());144 }145 if (propertyEntry.getKey().equals("text")) {146 elementBuilder.text(propertyEntry.getValue());147 }148 if (propertyEntry.getKey().equals("enabled")) {149 elementBuilder.enabled(Boolean.valueOf(propertyEntry.getValue()));150 }151 if (propertyEntry.getKey().equals("displayed")) {152 elementBuilder.displayed(Boolean.valueOf(propertyEntry.getValue()));...
FindElementActionBuilder
Using AI Code Generation
1import com.consol.citrus.dsl.builder.SeleniumActionBuilder;2import com.consol.citrus.dsl.builder.SeleniumActionBuilder.FindElement;3import com.consol.citrus.dsl.builder.SeleniumActionBuilder.FindElementActionBuilder;4import com.consol.citrus.dsl.runner.TestRunner;5import com.consol.citrus.selenium.endpoint.SeleniumBrowser;6import com.consol.citrus.selenium.endpoint.SeleniumHeaders;7import com.consol.citrus.selenium.endpoint.SeleniumMessage;8import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;9import org.openqa.selenium.By;10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.chrome.ChromeDriver;13import org.openqa.selenium.chrome.ChromeOptions;14public class FindElementActionBuilderExample {15 public static void main(String[] args) {16 TestRunner runner = new TestRunner();17 SeleniumBrowser browser = new SeleniumBrowser();18 browser.setBrowserType("chrome");19 browser.setDriver(new ChromeDriver());20 runner.selenium().browser(browser);21 FindElementActionBuilder findElementActionBuilder = SeleniumActionBuilder.findElement();22 FindElement findElement = findElementActionBuilder.using(By.name("q"));23 findElementActionBuilder.with(findElement);24 findElementActionBuilder.perform(runner);25 }26}27import com.consol.citrus.dsl.builder.SeleniumActionBuilder;28import com.consol.citrus.dsl.builder.SeleniumActionBuilder.FindElement;29import com.consol.citrus.dsl.builder.SeleniumActionBuilder.FindElementActionBuilder;30import com.consol.citrus.dsl.runner.TestRunner;31import com.consol.citrus.selenium.endpoint.SeleniumBrowser;32import com.consol.citrus.selenium.endpoint.SeleniumHeaders;33import com.consol.citrus.selenium.endpoint.SeleniumMessage;34import com.consol.citrus.selenium.endpoint.SeleniumMessageHeaders;35import org.openqa.selenium.By;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.WebElement;38import org.openqa.selenium.chrome.ChromeDriver;39import org.openqa.selenium.chrome.ChromeOptions;40public class FindElementActionBuilderExample {41 public static void main(String[] args) {42 TestRunner runner = new TestRunner();43 SeleniumBrowser browser = new SeleniumBrowser();44 browser.setBrowserType("chrome");45 browser.setDriver(new ChromeDriver());46 runner.selenium().browser(browser);
FindElementActionBuilder
Using AI Code Generation
1public class FindElementActionBuilderTest {2 public static void main(String[] args) {3 Citrus citrus = Citrus.newInstance();4 SeleniumActionBuilder seleniumActionBuilder = new SeleniumActionBuilder();5 seleniumActionBuilder.findElement()6 .browser("chrome")7 .timeout(10000L)8 .build();9 }10}11public class FindElementsActionBuilderTest {12 public static void main(String[] args) {13 Citrus citrus = Citrus.newInstance();14 SeleniumActionBuilder seleniumActionBuilder = new SeleniumActionBuilder();15 seleniumActionBuilder.findElements()16 .browser("chrome")17 .timeout(10000L)18 .build();19 }20}21public class GetPageSourceActionBuilderTest {22 public static void main(String[] args) {23 Citrus citrus = Citrus.newInstance();24 SeleniumActionBuilder seleniumActionBuilder = new SeleniumActionBuilder();25 seleniumActionBuilder.getPageSource()26 .browser("chrome")27 .build();28 }29}30public class GetTitleActionBuilderTest {31 public static void main(String[] args) {32 Citrus citrus = Citrus.newInstance();33 SeleniumActionBuilder seleniumActionBuilder = new SeleniumActionBuilder();34 seleniumActionBuilder.getTitle()35 .browser("chrome")36 .build();37 }38}39public class GetUrlActionBuilderTest {40 public static void main(String[] args) {41 Citrus citrus = Citrus.newInstance();
FindElementActionBuilder
Using AI Code Generation
1public class 3 extends AbstractTestNGCitrusTest {2 public void 3() {3 selenium()4 .builder()5 .findElementActionBuilder()6 .element(By.name("q"))7 .action(FindElementActionBuilder.FindElementActionType.CLICK)8 .build()9 .sendKeys("Selenium")10 .findElementActionBuilder()11 .element(By.name("btnK"))12 .action(FindElementActionBuilder.FindElementActionType.CLICK)13 .build()14 .findElementActionBuilder()15 .element(By.name("btnK"))16 .action(FindElementActionBuilder.FindElementActionType.SUBMIT)17 .build()18 .close();19 }20}21public class 4 extends AbstractTestNGCitrusTest {22 public void 4() {23 selenium()24 .builder()25 .findElementActionBuilder()26 .element(By.name("q"))27 .action(FindElementActionBuilder.FindElementActionType.CLICK)28 .build()29 .sendKeys("Selenium")30 .findElementActionBuilder()31 .element(By.name("btnK"))32 .action(FindElementActionBuilder.FindElementActionType.CLICK)33 .build()34 .findElementActionBuilder()35 .element(By.name("btnK"))36 .action(FindElementActionBuilder.FindElementActionType.SUBMIT)37 .build()38 .close();39 }40}41public class 5 extends AbstractTestNGCitrusTest {42 public void 5() {43 selenium()44 .builder()45 .findElementActionBuilder()46 .element(By.name("q"))47 .action(FindElementActionBuilder.FindElementActionType.CLICK)48 .build()49 .sendKeys("Selenium")50 .findElementActionBuilder()51 .element(By.name("btnK"))52 .action(FindElementActionBuilder.FindElementActionType.CLICK)53 .build()54 .findElementActionBuilder()55 .element(By
FindElementActionBuilder
Using AI Code Generation
1public class 3 extends AbstractTestNGCitrusTest {2 public void 3() {3 variable("searchText", "Citrus");4 variable("searchButton", "btnK");5 selenium().browser().start();6 selenium().navigate().go("${googleUrl}");7 selenium().findElement().byId("lst-ib").element().sendKeys("${searchText}");8 selenium().findElement().byId("${searchButton}").element().click();9 selenium().browser().stop();10 }11}12public class 4 extends AbstractTestNGCitrusTest {13 public void 4() {14 variable("searchText", "Citrus");15 variable("searchButton", "btnK");16 selenium().browser().start();17 selenium().navigate().go("${googleUrl}");18 selenium().findElement().byName("q").element().sendKeys("${searchText}");19 selenium().findElement().byName("${searchButton}").element().click();20 selenium().browser().stop();21 }22}23public class 5 extends AbstractTestNGCitrusTest {24 public void 5() {25 variable("searchText", "Citrus");26 variable("searchButton", "btnK");27 selenium().browser().start();28 selenium().navigate().go("${googleUrl}");29 selenium().findElement().byTagName("input").element().sendKeys("${searchText}");30 selenium().findElement().byTagName("input").element().click();31 selenium().browser().stop();32 }33}34public class 6 extends AbstractTestNGCitrusTest {35 public void 6() {36 variable("searchText", "Citrus");
FindElementActionBuilder
Using AI Code Generation
1public class 3.java extends TestCase {2 public void 3() {3 variable("search", "Citrus");4 selenium().browser(browserBuilder -> browserBuilder5 .name("chrome")6 .start()7 );8 selenium().navigate(navigateBuilder -> navigateBuilder9 .webDriver("chrome")10 .browser(browserBuilder -> browserBuilder11 .name("chrome")12 .to("{{url}}")13 );14 selenium().findElement(findElementBuilder -> findElementBuilder15 .webDriver("chrome")16 .browser(browserBuilder -> browserBuilder17 .name("chrome")18 .element(elementBuilder -> elementBuilder19 .id("lst-ib")20 .sendKeys("{{search}}")21 );22 selenium().findElement(findElementBuilder -> findElementBuilder23 .webDriver("chrome")24 .browser(browserBuilder -> browserBuilder25 .name("chrome")26 .element(elementBuilder -> elementBuilder27 .name("btnK")28 .click()29 );30 selenium().findElement(findElementBuilder -> findElementBuilder31 .webDriver("chrome")32 .browser(browserBuilder -> browserBuilder33 .name("chrome")34 .element(elementBuilder -> elementBuilder35 .assertThat()36 .text("Citrus")37 );38 selenium().stop(stopBuilder -> stopBuilder39 .webDriver("chrome")40 .browser(browserBuilder -> browserBuilder41 .name("chrome")42 );43 }44}45public class 4.java extends TestCase {46 public void 4() {47 variable("search", "Citrus");48 selenium().browser(browserBuilder -> browserBuilder49 .name("chrome")50 .start()51 );52 selenium().navigate(navigateBuilder -> navigateBuilder53 .webDriver("chrome")54 .browser(browserBuilder -> browserBuilder55 .name("chrome")56 .to("{{url}}")57 );58 selenium().findElements(findElementsBuilder ->
FindElementActionBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.testng;2import org.testng.annotations.Test;3import com.consol.citrus.dsl.builder.SeleniumActionBuilder;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5public class FindElementActionBuilderTest extends TestNGCitrusTestDesigner {6public void findElement() {7variable("value", "Images");8$(new SeleniumActionBuilder()9.findElementAction()10.xpath("${xpath}")11.store("value")12);13}14}15package com.consol.citrus.dsl.testng;16import org.testng.annotations.Test;17import com.consol.citrus.dsl.builder.SeleniumActionBuilder;18import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;19public class FindElementActionBuilderTest extends TestNGCitrusTestDesigner {20public void findElement() {21variable("value", "Images");22$(new SeleniumActionBuilder()23.findElementAction()24.xpath("${xpath}")25.store("value")26);27}28}29package com.consol.citrus.dsl.testng;30import org.testng.annotations.Test;31import com.consol.citrus.dsl.builder.SeleniumActionBuilder;32import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
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!!