How to use checkState method of org.fluentlenium.utils.Preconditions class

Best FluentLenium code snippet using org.fluentlenium.utils.Preconditions.checkState

Source:FluentDriver.java Github

copy

Full Screen

...33import java.util.Date;34import java.util.Set;35import static org.fluentlenium.core.domain.ElementUtils.getWrappedElement;36import static org.fluentlenium.utils.Preconditions.checkArgument;37import static org.fluentlenium.utils.Preconditions.checkState;38/**39 * Wrapper class for a {@link WebDriver} instance which also offers shortcut and convenience methods,40 * as well as methods to work with mouse, keyboard and windows.41 */42@SuppressWarnings("PMD.GodClass")43public class FluentDriver extends AbstractFluentDriverSearchControl { // NOPMD GodClass44 private static final Logger LOGGER =45 LoggerFactory.getLogger(FluentDriver.class);46 private final Configuration configuration;47 private final ComponentsManager componentsManager;48 private final EventsRegistry events;49 private final ComponentsEventsRegistry componentsEventsRegistry;50 private final FluentInjector fluentInjector;51 private final CssControl cssControl; // NOPMD UnusedPrivateField52 private final Search search;53 private final WebDriver driver;54 private final MouseActions mouseActions;55 private final KeyboardActions keyboardActions;56 private final WindowAction windowAction;57 private final FluentDriverScreenshotPersister screenshotPersister;58 private final FluentDriverWrappedCapabilitiesProvider capabilitiesProvider;59 private final FluentDriverHtmlDumper htmlDumper;60 private final FluentDriverWait driverWait;61 private final PerformanceTiming performanceTiming;62 private final ChromiumControl chromiumControl;63 /**64 * Wrap the driver into a Fluent driver.65 *66 * @param driver underlying selenium driver67 * @param configuration configuration68 * @param adapter adapter fluent control interface69 */70 public FluentDriver(WebDriver driver, Configuration configuration, FluentControl adapter) {71 super(adapter);72 this.configuration = configuration;73 screenshotPersister = new FluentDriverScreenshotPersister(configuration, driver);74 capabilitiesProvider = new FluentDriverWrappedCapabilitiesProvider();75 htmlDumper = new FluentDriverHtmlDumper(configuration);76 componentsManager = new ComponentsManager(adapter);77 driverWait = new FluentDriverWait(configuration);78 this.driver = driver;79 search = new Search(driver, this, componentsManager, adapter);80 if (driver instanceof EventFiringWebDriver) {81 events = new EventsRegistry(this);82 componentsEventsRegistry = new ComponentsEventsRegistry(events, componentsManager);83 } else {84 events = null;85 componentsEventsRegistry = null;86 }87 mouseActions = new MouseActions(driver);88 keyboardActions = new KeyboardActions(driver);89 fluentInjector = new FluentInjector(adapter, events, componentsManager, new DefaultContainerInstantiator(this));90 cssControl = new CssControlImpl(adapter, adapter);91 windowAction = new WindowAction(adapter, componentsManager.getInstantiator(), driver);92 performanceTiming = new DefaultPerformanceTiming(driver);93 chromiumControl = new ChromiumControlImpl(driver);94 new FluentDriverTimeoutConfigurer(configuration, driver).configureDriver();95 }96 public Configuration getConfiguration() {97 return configuration;98 }99 @Override100 public void takeHtmlDump() {101 takeHtmlDump(new Date().getTime() + ".html");102 }103 @Override104 public void takeHtmlDump(String fileName) {105 htmlDumper.takeHtmlDump(fileName, () -> {106 synchronized (FluentDriver.class) {107 return $("html").first().html();108 }109 });110 }111 @Override112 public boolean canTakeScreenShot() {113 return getDriver() instanceof TakesScreenshot;114 }115 @Override116 public void takeScreenshot() {117 takeScreenshot(new Date().getTime() + ".png");118 }119 @Override120 public void takeScreenshot(String fileName) {121 if (!canTakeScreenShot()) {122 throw new WebDriverException("Current browser doesn't allow taking screenshot.");123 }124 screenshotPersister.persistScreenshot(fileName);125 }126 @Override127 public WebDriver getDriver() {128 if (driver instanceof AppiumDriver) {129 LOGGER.warn("You should use getAppiumDriver() method for mobile automation");130 }131 return driver;132 }133 @Override134 public AppiumDriver getAppiumDriver() {135 if (!(driver instanceof AppiumDriver)) {136 throw new WrongDriverException("Use getDriver() method for web automation");137 }138 return (AppiumDriver) driver;139 }140 @Override141 public EventsRegistry events() {142 return checkState(events, "An EventFiringWebDriver instance is required to use events. "143 + "You should set 'eventsEnabled' configuration property to 'true' "144 + "or override newWebDriver() to build an EventFiringWebDriver.");145 }146 @Override147 public MouseActions mouse() {148 return mouseActions;149 }150 @Override151 public KeyboardActions keyboard() {152 return keyboardActions;153 }154 @Override155 public WindowAction window() {156 return windowAction;...

Full Screen

Full Screen

Source:FluentPage.java Github

copy

Full Screen

...14import java.net.URISyntaxException;15import java.net.URL;16import java.util.Optional;17import static org.fluentlenium.utils.Preconditions.checkArgumentBlank;18import static org.fluentlenium.utils.Preconditions.checkState;19import static org.fluentlenium.utils.UrlUtils.getAbsoluteUrlFromFile;20/**21 * Use the Page Object Pattern to have more resilient tests.22 * <p>23 * Extend this class and use @{@link PageUrl} and @{@link org.openqa.selenium.support.FindBy} annotations to provide24 * injectable Page Objects to FluentLenium.25 * <p>26 * Your page object class has to extend this class only when you use the {@code @PageUrl} annotation as well.27 * <p>28 * A subclass of {@code FluentPage} may also be annotated with one of Selenium's {@code @Find...} annotation to give an29 * identifier for this page. See {@link #isAt()} and {@link #isAtUsingSelector(By)}.30 */31public class FluentPage extends DefaultFluentContainer implements FluentPageControl {32 private final ClassAnnotations classAnnotations = new ClassAnnotations(getClass());33 private final PageUrlCache pageUrlCache = new PageUrlCache();34 /**35 * Creates a new fluent page.36 */37 public FluentPage() {38 // Default constructor39 }40 /**41 * Creates a new fluent page, using given fluent control.42 *43 * @param control fluent control44 */45 public FluentPage(FluentControl control) {46 super(control);47 }48 public ClassAnnotations getClassAnnotations() {49 return classAnnotations;50 }51 @Override52 public String getUrl() {53 return Optional.ofNullable(getPageUrlAnnotation())54 .map(pageUrl -> getPageUrlValue(pageUrl))55 .filter(url -> !url.isEmpty())56 .orElse(null);57 }58 /**59 * Parses the current URL and returns the parameter value for the argument parameter name.60 * <p>61 * In case the parameter is not defined in the {@link PageUrl} annotation,62 * or the parameter (mandatory or optional) has no value in the actual URL, this method returns {@code null}.63 * <p>64 * There is also caching in place to improve performance.65 * It compares the current URL with the cached URL, and if they are the same,66 * the parameter is returned from the cached values, otherwise the URL is parsed again and the parameters67 * are returned from the new URL.68 * <p>69 * Examples (for template + URL + paramName combinations):70 * <pre>71 * "/abc/{param1}/def/{param2}" + "/abc/param1val/def/param2val" + "param1" -&gt; "param1val"72 * "/abc/{param1}/def/{param2}" + "/abc/param1val/def/param2val" + "param4" -&gt; null73 * "/abc{?/param1}/def/{param2}" + "/abc/param1val/def/param2val" + "param1" -&gt; "param1val"74 * "/abc{?/param1}/def/{param2}" + "/abc/def/param2val" + "param1" -&gt; ull75 * </pre>76 *77 * @param parameterName the parameter to get the value of78 * @return the desired parameter value or null if a value for the given parameter name is not present79 * @throws IllegalArgumentException when the argument param is null or empty80 */81 public String getParam(String parameterName) {82 checkArgumentBlank(parameterName, "The parameter name to query should not be blank.");83 String url = url();84 if (url.startsWith("file:///")) {85 try {86 url = new URL(url()).toURI().toString();87 } catch (URISyntaxException | MalformedURLException e) {88 e.printStackTrace();89 }90 }91 if (!url.equals(pageUrlCache.getUrl())) {92 pageUrlCache.cache(url, parseUrl(url).parameters());93 }94 return pageUrlCache.getParameter(parameterName);95 }96 @Override97 public String getUrl(Object... parameters) {98 return Optional.ofNullable(getUrl())99 .map(url -> toRenderedUrlTemplate(url, parameters))100 .orElse(null);101 }102 @Override103 public void isAt() {104 By by = classAnnotations.buildBy();105 if (by != null) {106 isAtUsingSelector(by);107 }108 isAtUrl(getUrl());109 }110 @Override111 public void isAt(Object... parameters) {112 isAtUrl(getUrl(parameters));113 }114 /**115 * URL-matching implementation for isAt().116 * Validates whether the page, determined by the argument URL template, is loaded.117 * <p>118 * If there is a {@link PageUrl} annotation applied on the class and it has the {@code file} attribute defined,119 * this method will skip the url parsing to skip URL check because it is not able to get local file path relatively.120 *121 * @param urlTemplate URL Template, must be non-null122 * @throws AssertionError when the current URL doesn't match the expected page URL123 */124 public void isAtUsingUrl(String urlTemplate) {125 if (!isLocalFile(getPageUrlAnnotation())) {126 UrlTemplate template = new UrlTemplate(urlTemplate);127 String url = url();128 ParsedUrlTemplate parse = template.parse(url);129 if (!parse.matches()) {130 throw new AssertionError(131 String.format("Current URL [%s] doesn't match expected Page URL [%s]", url, urlTemplate));132 }133 }134 }135 /**136 * Validates whether the page, determined by the argument {@link By} object, is loaded.137 *138 * @param by by selector, must be non-null139 * @throws AssertionError if the element using the argument By is not found for the current page140 */141 public void isAtUsingSelector(By by) {142 try {143 $(by).first().now();144 } catch (TimeoutException | NoSuchElementException | StaleElementReferenceException e) {145 throw new AssertionError("@FindBy element not found for page " + getClass().getName(), e);146 }147 }148 @Override149 public <P extends FluentPage> P go() {150 return navigateTo(getUrl());151 }152 @Override153 public <P extends FluentPage> P go(Object... params) {154 return navigateTo(getUrl(params));155 }156 @Override157 public ParsedUrlTemplate parseUrl() {158 return parseUrl(url());159 }160 /**161 * Verifies whether page is loaded. Overwrite if necessary.162 * E.g. wait for {@link org.openqa.selenium.support.FindBy @FindBy} annotated component to render using {@link AwaitControl#await() await()}. <br>163 * Warning: Do NOT wait for {@link org.fluentlenium.core.annotation.Unshadow @Unshadow} components!164 */165 public void verifyIsLoaded() {166 }167 public void unshadowAllFields() {168 if (getDriver() != null) {169 new Unshadower(getDriver(), this).unshadowAllAnnotatedFields();170 }171 }172 @Override173 public ParsedUrlTemplate parseUrl(String url) {174 return Optional.ofNullable(getUrl())175 .map(templateUrl -> new UrlTemplate(templateUrl).parse(url))176 .orElseThrow(() -> new IllegalStateException(177 "An URL should be defined on the page. Use @PageUrl annotation or override getUrl() method."));178 }179 private String toRenderedUrlTemplate(String url, Object[] parameters) {180 UrlTemplate template = new UrlTemplate(url);181 for (Object parameter : parameters) {182 template.add(parameter == null ? null : String.valueOf(parameter));183 }184 return template.render();185 }186 private void isAtUrl(String url) {187 if (url != null) {188 isAtUsingUrl(url);189 }190 }191 private String getPageUrlValue(PageUrl pageUrl) {192 return (isLocalFile(pageUrl) ? getAbsoluteUrlFromFile(pageUrl.file()) : StringUtils.EMPTY) + pageUrl.value();193 }194 private boolean isLocalFile(PageUrl pageUrl) {195 return pageUrl != null && !pageUrl.file().isEmpty();196 }197 private PageUrl getPageUrlAnnotation() {198 return getClass().isAnnotationPresent(PageUrl.class) ? getClass().getAnnotation(PageUrl.class) : null;199 }200 private <P extends FluentPage> P navigateTo(String url) {201 checkState(url, "An URL should be defined on the page. Use @PageUrl annotation or override getUrl() method.");202 goTo(url);203 return (P) this;204 }205}...

Full Screen

Full Screen

Source:AbstractReportExecutionListUiTest.java Github

copy

Full Screen

...52 protected JobExecutionModel jem3;53 protected JobApiController controller;54 protected List<JobExecutionModel> models;55 public void setUp() throws Exception {56 Preconditions.checkState(topPagination != bottomPagination, "topPagination and bottomPagination cannot have the same value");57 jobModel = jobModelWithoutDependents();58 jobDbSetUp(jobModel);59 jem0 = jobExecutionModel();60 jem0.setExecutionStart(toEpoch("Sat Jan 07 2017 05:10"));61 jem0.setExecutionEnd(toEpoch("Sat Jan 07 2017 05:20"));62 jem0.setStatus(SUCCESS);63 jem0.setJobModel(jobModel);64 jobExecutionDbSetUp(jem0);65 jem1 = jobExecutionModel();66 jem1.setExecutionStart(toEpoch("Sat Jan 07 2017 05:30"));67 jem1.setExecutionEnd(toEpoch("Sat Jan 07 2017 05:40"));68 jem1.setStatus(FAILURE);69 jem1.setJobModel(jobModel);70 jobExecutionDbSetUp(jem1);...

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package test;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.annotation.Page;4import org.fluentlenium.utils.Preconditions;5import org.junit.Test;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.htmlunit.HtmlUnitDriver;8public class TestClass {9 private PageObject page;10 public void test() {11 WebDriver driver = new HtmlUnitDriver();12 page.go();13 Preconditions.checkState(page.isAt(), "This is not the page you are looking for!");14 }15}16package test;17import org.fluentlenium.core.FluentPage;18import org.fluentlenium.core.annotation.Page;19import org.fluentlenium.utils.Preconditions;20import org.junit.Test;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.htmlunit.HtmlUnitDriver;23public class TestClass {24 private PageObject page;25 public void test() {26 WebDriver driver = new HtmlUnitDriver();27 page.go();28 Preconditions.checkState(page.isAt(), "This is not the page you are looking for!");29 }30}31package test;32import org.fluentlenium.core.FluentPage;33import org.fluentlenium.core.annotation.Page;34import org.fluentlenium.utils.Preconditions;35import org.junit.Test;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.htmlunit.HtmlUnitDriver;38public class TestClass {39 private PageObject page;40 public void test() {41 WebDriver driver = new HtmlUnitDriver();42 page.go();43 Preconditions.checkState(page.isAt(), "This is not the page you are looking for!");44 }45}46package test;47import org.fluentlenium.core.FluentPage;48import org.fluentlenium.core.annotation.Page;49import org.fluentlenium.utils.Preconditions;50import org.junit.Test;51import org.openqa.selenium.WebDriver;52import org.openqa.selenium.htmlunit.HtmlUnitDriver;53public class TestClass {54 private PageObject page;

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.FluentPage;2import org.fluentlenium.utils.Preconditions;3public class 4 extends FluentPage {4 public void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {5 Preconditions.checkState(expression, errorMessageTemplate, errorMessageArgs);6 }7}8 at org.fluentlenium.utils.Preconditions.checkState(Preconditions.java:56)9 at 4.checkState(4.java:7)10 at 4.main(4.java:11)

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.FluentPage;2import org.fluentlenium.core.annotation.PageUrl;3import org.openqa.selenium.WebDriver;4public class GooglePage extends FluentPage {5 public void isAt() {6 Preconditions.checkState("Google" == title());7 }8 public void isAt(WebDriver driver) {9 Preconditions.checkState("Google" == title(driver));10 }11}12import org.fluentlenium.core.FluentPage;13import org.fluentlenium.core.annotation.PageUrl;14import org.openqa.selenium.WebDriver;15public class GooglePage extends FluentPage {16 public void isAt() {17 Preconditions.checkState("Google" == title());18 }19 public void isAt(WebDriver driver) {20 Preconditions.checkState("Google" == title(driver));21 }22}23import org.fluentlenium.core.FluentPage;24import org.fluentlenium.core.annotation.PageUrl;25import org.openqa.selenium.WebDriver;26public class GooglePage extends FluentPage {27 public void isAt() {28 Preconditions.checkState("Google" == title());29 }30 public void isAt(WebDriver driver) {31 Preconditions.checkState("Google" == title(driver));32 }33}34import org.fluentlenium.core.FluentPage;35import org.fluentlenium.core.annotation.PageUrl;36import org.openqa.selenium.WebDriver;37public class GooglePage extends FluentPage {38 public void isAt() {39 Preconditions.checkState("Google" == title());40 }41 public void isAt(WebDriver driver) {42 Preconditions.checkState("Google" == title(driver));43 }44}45import org.fluentlenium.core.FluentPage;46import org.fluentlenium.core.annotation.PageUrl;47import org.openqa.selenium.WebDriver;48public class GooglePage extends FluentPage {

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.utils;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.domain.FluentWebElement;4import org.openqa.selenium.support.FindBy;5import org.testng.annotations.Test;6public class Preconditions extends FluentPage {7@FindBy(css = "button")8private FluentWebElement button;9public void checkState() {10button.click();11Preconditions.checkState(button.isDisplayed(), "Button is not displayed");12}13}14package org.fluentlenium.utils;15import org.fluentlenium.core.FluentPage;16import org.fluentlenium.core.domain.FluentWebElement;17import org.openqa.selenium.support.FindBy;18import org.testng.annotations.Test;19public class Preconditions extends FluentPage {20@FindBy(css = "button")21private FluentWebElement button;22public void checkState() {23button.click();24Preconditions.checkState(button.isDisplayed(), "Button is not displayed");25}26}27Selenium - FluentWait with Expected Condition | withTimeout()28Selenium - FluentWait with Expected Condition | pollingEvery()29Selenium - FluentWait with Expected Condition | ignoring()30Selenium - FluentWait with Expected Condition | ignoringException()31Selenium - FluentWait with Expected Condition | ignoringAll()32Selenium - FluentWait with Expected Condition | withMessage()33Selenium - FluentWait with Expected Condition | until()34Selenium - FluentWait with Expected Condition | untilFunction()35Selenium - FluentWait with Expected Condition | untilDriver()36Selenium - FluentWait with Expected Condition | untilElement()37Selenium - FluentWait with Expected Condition | untilList()38Selenium - FluentWait with Expected Condition | untilListEmpty()39Selenium - FluentWait with Expected Condition | untilListNotEmpty()40Selenium - FluentWait with Expected Condition | untilListSize()41Selenium - FluentWait with Expected Condition | untilListSizeLessThan()42Selenium - FluentWait with Expected Condition | untilListSizeLessThanOrEqual()

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.utils;2import java.util.Collection;3import java.util.Map;4import java.util.Optional;5import java.util.function.Supplier;6public class Preconditions {7 private Preconditions() {8 }9 public static void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {10 if (!expression) {11 throw new IllegalStateException(String.format(errorMessageTemplate, errorMessageArgs));12 }13 }14 public static void checkState(boolean expression, Supplier<String> errorMessageSupplier) {15 if (!expression) {16 throw new IllegalStateException(errorMessageSupplier.get());17 }18 }19 public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {20 if (!expression) {21 throw new IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));22 }23 }24 public static void checkArgument(boolean expression, Supplier<String> errorMessageSupplier) {25 if (!expression) {26 throw new IllegalArgumentException(errorMessageSupplier.get());27 }28 }29 public static <T> T checkNotNull(T reference, String errorMessageTemplate, Object... errorMessageArgs) {30 if (reference == null) {31 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));32 }33 return reference;34 }35 public static <T> T checkNotNull(T reference, Supplier<String> errorMessageSupplier) {36 if (reference == null) {37 throw new NullPointerException(errorMessageSupplier.get());38 }39 return reference;40 }41 public static <T> Optional<T> checkOptional(Optional<T> reference, String errorMessageTemplate, Object... errorMessageArgs) {42 if (!reference.isPresent()) {43 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));44 }45 return reference;46 }47 public static <T> Optional<T> checkOptional(Optional<T> reference, Supplier<String> errorMessageSupplier) {48 if (!reference.isPresent()) {49 throw new NullPointerException(errorMessageSupplier.get());50 }51 return reference;52 }53 public static <T> T[] checkArray(T[] reference, String errorMessageTemplate, Object... errorMessageArgs) {54 if (reference == null || reference.length == 0) {55 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));56 }57 return reference;58 }59 public static <T> T[] checkArray(T[] reference, Supplier<String> errorMessageSupplier) {60 if (reference == null || reference.length == 0) {61 throw new NullPointerException(errorMessageSupplier.get());62 }63 return reference;64 }

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.utils;2import org.junit.Test;3import static org.fluentlenium.utils.Preconditions.checkState;4public class PreconditionsTest {5public void checkStateTest() {6checkState(5 > 6, "This is a test message");7}8}9 at org.fluentlenium.utils.Preconditions.checkState(Preconditions.java:45)10 at org.fluentlenium.utils.PreconditionsTest.checkStateTest(PreconditionsTest.java:9)

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.utils;2import org.fluentlenium.utils.Preconditions;3public class PreconditionsExample {4 public static void main(String[] args) {5 Preconditions.checkState(true, "This is a message");6 }7}8 at org.fluentlenium.utils.Preconditions.checkState(Preconditions.java:55)9 at org.fluentlenium.utils.PreconditionsExample.main(PreconditionsExample.java:8)

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.FluentPage;2import org.fluentlenium.core.annotation.PageUrl;3import org.openqa.selenium.WebDriver;4public class GooglePage extends FluentPage {5 public void isAt() {6 Preconditions.checkState("Google" == title());7 }8 public void isAt(WebDriver driver) {9 Preconditions.checkState("Google" == title(driver));10 }11}12import org.fluentlenium.core.FluentPage;13import org.fluentlenium.core.annotation.PageUrl;14import org.openqa.selenium.WebDriver;15public class GooglePage extends FluentPage {16 public void isAt() {17 Preconditions.checkState("Google" == title());18 }19 public void isAt(WebDriver driver) {20 Preconditions.checkState("Google" == title(driver));21 }22}23import org.fluentlenium.core.FluentPage;24import org.fluentlenium.core.annotation.PageUrl;25import org.openqa.selenium.WebDriver;26public class GooglePage extends FluentPage {27 public void isAt() {28 Preconditions.checkState("Google" == title());29 }30 public void isAt(WebDriver driver) {31 Preconditions.checkState("Google" == title(driver));32 }33}34import org.fluentlenium.core.FluentPage;35import org.fluentlenium.core.annotation.PageUrl;36import org.openqa.selenium.WebDriver;37public class GooglePage extends FluentPage {38 public void isAt() {39 Preconditions.checkState("Google" == title());40 }41 public void isAt(WebDriver driver) {42 Preconditions.checkState("Google" == title(driver));43 }44}45import org.fluentlenium.core.FluentPage;46import org.fluentlenium.core.annotation.PageUrl;47import org.openqa.selenium.WebDriver;48public class GooglePage extends FluentPage {

Full Screen

Full Screen

checkState

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.utils;2import java.util.Collection;3import java.util.Map;4import java.util.Optional;5import java.util.function.Supplier;6public class Preconditions {7 private Preconditions() {8 }9 public static void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {10 if (!expression) {11 throw new IllegalStateException(String.format(errorMessageTemplate, errorMessageArgs));12 }13 }14 public static void checkState(boolean expression, Supplier<String> errorMessageSupplier) {15 if (!expression) {16 throw new IllegalStateException(errorMessageSupplier.get());17 }18 }19 public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {20 if (!expression) {21 throw new IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));22 }23 }24 public static void checkArgument(boolean expression, Supplier<String> errorMessageSupplier) {25 if (!expression) {26 throw new IllegalArgumentException(errorMessageSupplier.get());27 }28 }29 public static <T> T checkNotNull(T reference, String errorMessageTemplate, Object... errorMessageArgs) {30 if (reference == null) {31 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));32 }33 return reference;34 }35 public static <T> T checkNotNull(T reference, Supplier<String> errorMessageSupplier) {36 if (reference == null) {37 throw new NullPointerException(errorMessageSupplier.get());38 }39 return reference;40 }41 public static <T> Optional<T> checkOptional(Optional<T> reference, String errorMessageTemplate, Object... errorMessageArgs) {42 if (!reference.isPresent()) {43 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));44 }45 return reference;46 }47 public static <T> Optional<T> checkOptional(Optional<T> reference, Supplier<String> errorMessageSupplier) {48 if (!reference.isPresent()) {49 throw new NullPointerException(errorMessageSupplier.get());50 }51 return reference;52 }53 public static <T> T[] checkArray(T[] reference, String errorMessageTemplate, Object... errorMessageArgs) {54 if (reference == null || reference.length == 0) {55 throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));56 }57 return reference;58 }59 public static <T> T[] checkArray(T[] reference, Supplier<String> errorMessageSupplier) {60 if (reference == null || reference.length == 0) {61 throw new NullPointerException(errorMessageSupplier.get());62 }63 return reference;64 }

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 FluentLenium automation tests on LambdaTest cloud grid

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

Most used method in Preconditions

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful