How to use value method of org.testingisdocumenting.webtau.cache.Cache class

Best Webtau code snippet using org.testingisdocumenting.webtau.cache.Cache.value

Source:Cache.java Github

copy

Full Screen

...33 private final FileBasedCache fileBasedCache;34 private Cache() {35 fileBasedCache = new FileBasedCache(() -> WebTauConfig.getCfg().getCachePath());36 }37 public <E> CachedValue<E> value(String id) {38 return new CachedValue<>(cache, id);39 }40 public <E> E get(String key) {41 return getAsStep(key, Function.identity());42 }43 public <E> E get(String key, long expirationMs, Supplier<E> newValueSupplier) {44 WebTauStep step = WebTauStep.createStep(45 tokenizedMessage(action("getting cached or generating new value"), FROM, id(key)),46 (r) -> {47 @SuppressWarnings("unchecked")48 CachedValueAndMethod<E> cachedValueAndMethod = (CachedValueAndMethod<E>) r;49 MessageToken preposition = cachedValueAndMethod.method == ObtainMethod.CACHED ? FROM : AS;50 return tokenizedMessage(action(cachedValueAndMethod.method.message), preposition, id(key), COLON, stringValue(cachedValueAndMethod.value));51 },52 () -> getWithExpirationAndSupplierStep(key, expirationMs, newValueSupplier, Function.identity()));53 step.setInput(WebTauStepInputKeyValue.stepInput(Collections.singletonMap("expirationMs", expirationMs)));54 CachedValueAndMethod<E> executionResult = step.execute(StepReportOptions.REPORT_ALL);55 return executionResult.value;56 }57 public boolean exists(String key) {58 MessageToken valuePresenceMessage = action("cache value presence");59 WebTauStep step = WebTauStep.createStep(60 tokenizedMessage(action("check"), id(key), valuePresenceMessage),61 (result) -> tokenizedMessage(action("checked"), id(key), valuePresenceMessage, COLON,62 classifier((boolean)result ? "exists" : "absent")),63 () -> fileBasedCache.exists(key));64 return step.execute(StepReportOptions.SKIP_START);65 }66 public void remove(String key) {67 MessageToken valueMessage = action("cached value");68 WebTauStep step = WebTauStep.createStep(69 tokenizedMessage(action("remove"), id(key), valueMessage),70 () -> tokenizedMessage(action("removed"), id(key), valueMessage),71 () -> fileBasedCache.remove(key));72 step.execute(StepReportOptions.SKIP_START);73 }74 public boolean isExpired(String key, long expirationMs) {75 MessageToken valueExpirationMessage = action("cache value expiration");76 WebTauStep step = WebTauStep.createStep(77 tokenizedMessage(action("check"), id(key), valueExpirationMessage),78 (result) -> tokenizedMessage(action("checked"), id(key), valueExpirationMessage, COLON,79 classifier((boolean)result ? "expired" : "valid")),80 () -> fileBasedCache.isExpired(key, expirationMs));81 step.setInput(WebTauStepInputKeyValue.stepInput("expirationMs", expirationMs));82 return step.execute(StepReportOptions.SKIP_START);83 }84 public Path getAsPath(String key) {85 return getAsStep(key, (v) -> Paths.get(v.toString()));86 }87 public void put(String key, Object value) {88 WebTauStep step = WebTauStep.createStep(89 tokenizedMessage(action("caching value"), AS, id(key), COLON, stringValue(value)),90 () -> tokenizedMessage(action("cached value"), AS, id(key), COLON, stringValue(value)),91 () -> fileBasedCache.put(key, CacheValueConverter.convertToCached(value)));92 step.execute(StepReportOptions.SKIP_START);93 }94 private <E, R> R getAsStep(String key, Function<E, R> converter) {95 WebTauStep step = WebTauStep.createStep(96 tokenizedMessage(action("getting cached value"), FROM, id(key)),97 (r) -> tokenizedMessage(action("got cached value"), FROM, id(key), COLON, stringValue(r)),98 () -> {99 E value = fileBasedCache.get(key);100 if (value == null) {101 throw new AssertionError("can't find cached value by key: " + key);102 }103 return converter.apply(value);104 });105 return step.execute(StepReportOptions.SKIP_START);106 }107 private <E, R> CachedValueAndMethod<R> getWithExpirationAndSupplierStep(String key, long expirationMs, Supplier<E> newValueSupplier, Function<E, R> converter) {108 if (!exists(key)) {109 E newValue = newValueSupplier.get();110 put(key, newValue);111 return new CachedValueAndMethod<>(ObtainMethod.CREATE_NEW, converter.apply(newValue));112 } else if (isExpired(key, expirationMs)) {113 E newValue = newValueSupplier.get();114 put(key, newValue);115 return new CachedValueAndMethod<>(ObtainMethod.RE_CREATE, converter.apply(newValue));116 } else {117 E existingValue = get(key);118 return new CachedValueAndMethod<>(ObtainMethod.CACHED, converter.apply(existingValue));119 }120 }121 enum ObtainMethod {122 CREATE_NEW("created new value and cached"),123 RE_CREATE("re-created value and cached"),124 CACHED("got cached value");125 private final String message;126 ObtainMethod(String message) {127 this.message = message;128 }129 }130 static class CachedValueAndMethod<R> {131 private final ObtainMethod method;132 private final R value;133 public CachedValueAndMethod(ObtainMethod method, R value) {134 this.method = method;135 this.value = value;136 }137 }138}...

Full Screen

Full Screen

Source:Browser.java Github

copy

Full Screen

1/*2 * Copyright 2020 webtau maintainers3 * Copyright 2019 TWO SIGMA OPEN SOURCE, LLC4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.testingisdocumenting.webtau.browser;18import org.testingisdocumenting.webtau.browser.documentation.BrowserDocumentation;19import org.testingisdocumenting.webtau.browser.driver.CurrentWebDriver;20import org.testingisdocumenting.webtau.browser.driver.WebDriverCreator;21import org.testingisdocumenting.webtau.browser.navigation.BrowserPageNavigation;22import org.testingisdocumenting.webtau.browser.page.*;23import org.testingisdocumenting.webtau.browser.page.path.PageElementPath;24import org.testingisdocumenting.webtau.cache.Cache;25import org.testingisdocumenting.webtau.utils.UrlUtils;26import org.openqa.selenium.OutputType;27import static org.testingisdocumenting.webtau.cfg.WebTauConfig.getCfg;28import static org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder.*;29import static org.testingisdocumenting.webtau.reporter.WebTauStep.createAndExecuteStep;30import static org.testingisdocumenting.webtau.reporter.TokenizedMessage.tokenizedMessage;31public class Browser {32 private static final String DEFAULT_URL_CACHE_KEY = "current";33 private final AdditionalBrowserInteractions additionalBrowserInteractions;34 public static final Browser browser = new Browser();35 public final CurrentWebDriver driver = CurrentWebDriver.INSTANCE;36 public final BrowserCookies cookies = new BrowserCookies(driver);37 public final BrowserLocalStorage localStorage = new BrowserLocalStorage(driver);38 public final BrowserNavigation navigation = new BrowserNavigation(driver);39 public final BrowserDocumentation doc = new BrowserDocumentation(driver);40 public final PageUrl url = new PageUrl(driver::getCurrentUrl);41 public final BrowserKeys keys = new BrowserKeys();42 public final PageElementValue<String> title = new PageElementValue<>(BrowserContext.INSTANCE,43 "title", this::extractPageTitle);44 private Browser() {45 additionalBrowserInteractions = new BrowserInjectedJavaScript(driver);46 }47 public void open(String url) {48 String fullUrl = createFullUrl(url);49 String currentUrl = driver.getCurrentUrl();50 boolean sameUrl = fullUrl.equals(currentUrl);51 createAndExecuteStep(tokenizedMessage(action("opening"), urlValue(fullUrl)),52 () -> tokenizedMessage(action(sameUrl ? "staying at" : "opened"), urlValue(fullUrl)),53 () -> {54 if (!sameUrl) {55 BrowserPageNavigation.open(driver, url, fullUrl);56 }57 });58 }59 public void reopen(String url) {60 String fullUrl = createFullUrl(url);61 createAndExecuteStep(tokenizedMessage(action("re-opening"), urlValue(fullUrl)),62 () -> tokenizedMessage(action("opened"), urlValue(fullUrl)),63 () -> BrowserPageNavigation.open(driver, url, fullUrl));64 }65 public void refresh() {66 createAndExecuteStep(tokenizedMessage(action("refreshing current page")),67 () -> tokenizedMessage(action("refreshed current page")),68 () -> BrowserPageNavigation.refresh(driver));69 }70 public void close() {71 createAndExecuteStep(tokenizedMessage(action("closing browser")),72 () -> tokenizedMessage(action("browser is closed")),73 driver::quit);74 }75 public void back() {76 createAndExecuteStep(77 tokenizedMessage(action("browser going"), classifier("back")),78 () -> tokenizedMessage(action("browser went"), classifier("back")),79 () -> driver.navigate().back());80 }81 public void forward() {82 createAndExecuteStep(83 tokenizedMessage(action("browser going"), classifier("forward")),84 () -> tokenizedMessage(action("browser went"), classifier("forward")),85 () -> driver.navigate().forward());86 }87 public void restart() {88 String currentUrl = driver.getCurrentUrl();89 createAndExecuteStep(tokenizedMessage(action("restarting browser")),90 () -> tokenizedMessage(action("browser is restarted")),91 () -> {92 close();93 browser.open(currentUrl);94 });95 }96 public void saveCurrentUrl() {97 saveCurrentUrl(DEFAULT_URL_CACHE_KEY);98 }99 public void saveCurrentUrl(String key) {100 createAndExecuteStep(tokenizedMessage(action("saving current url as"), stringValue(key)),101 () -> tokenizedMessage(action("saved current url as"), stringValue(key)),102 () -> Cache.cache.put(makeCacheKey(key), driver.getCurrentUrl()));103 }104 public void openSavedUrl() {105 openSavedUrl(DEFAULT_URL_CACHE_KEY);106 }107 public void openSavedUrl(String key) {108 createAndExecuteStep(tokenizedMessage(action("opening url saved as"), stringValue(key)),109 () -> tokenizedMessage(action("opened url saved as"), stringValue(key)),110 () -> {111 Object url = Cache.cache.get(makeCacheKey(key));112 if (url == null) {113 throw new IllegalStateException("no previously saved url found");114 }115 reopen(url.toString());116 });117 }118 public PageElement $(String css) {119 return new GenericPageElement(driver, additionalBrowserInteractions, PageElementPath.css(css), false);120 }121 public boolean hasActiveBrowsers() {122 return WebDriverCreator.hasActiveBrowsers();123 }124 public String takeScreenshotAsBase64() {125 return driver.getScreenshotAs(OutputType.BASE64);126 }127 public String extractPageTitle() {128 return driver.getTitle();129 }130 private String createFullUrl(String url) {131 if (UrlUtils.isFull(url)) {132 return url;133 }134 if (!BrowserConfig.getBrowserUrl().isEmpty()) {135 return UrlUtils.concat(BrowserConfig.getBrowserUrl(), url);136 }137 return UrlUtils.concat(getCfg().getBaseUrl(), url);138 }139 private static String makeCacheKey(String givenKey) {140 return "url_" + givenKey;141 }142}...

Full Screen

Full Screen

Source:WebTauDsl.java Github

copy

Full Screen

...83 return browser.$(css);84 }85 /**86 * @deprecated use {@link #visible}87 * @return visible value matcher88 */89 @Deprecated90 public static ValueMatcher beVisible() {91 return visible;92 }93 /**94 * @deprecated use {@link #hidden}95 * @return hidden value matcher96 */97 @Deprecated98 public static ValueMatcher beHidden() {99 return hidden;100 }101 /**102 * @deprecated use {@link #enabled}103 * @return enabled value matcher104 */105 public static ValueMatcher beEnabled() {106 return enabled;107 }108 /**109 * @deprecated use {@link #disabled}110 * @return disabled value matcher111 */112 public static ValueMatcher beDisabled() {113 return disabled;114 }115 /**116 * @deprecated use {@link #visible}117 * @return visible value matcher118 */119 public static ValueMatcher getBeVisible() {120 return visible;121 }122 /**123 * check if DataNode complies with schema124 * @param schemaFileName schema file name125 * @return schema matcher126 */127 public static SchemaMatcher complyWithSchema(String schemaFileName) {128 return new SchemaMatcher(schemaFileName);129 }130 /**131 * @deprecated use {@link #complyWithSchema(String)} ()}...

Full Screen

Full Screen

value

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cache.Cache;2public class 2 {3 public static void main(String[] args) {4 Cache.value("key", () -> 1 + 2);5 }6}7import org.testingisdocumenting.webtau.cache.Cache;8public class 3 {9 public static void main(String[] args) {10 Cache.value("key", () -> 1 + 2);11 }12}13import org.testingisdocumenting.webtau.cache.Cache;14public class 4 {15 public static void main(String[] args) {16 Cache.value("key", () -> 1 + 2);17 }18}19import org.testingisdocumenting.webtau.cache.Cache;20public class 5 {21 public static void main(String[] args) {22 Cache.value("key", () -> 1 + 2);23 }24}25import org.testingisdocumenting.webtau.cache.Cache;26public class 6 {27 public static void main(String[] args) {28 Cache.value("key", () -> 1 + 2);29 }30}31import org.testingisdocumenting.webtau.cache.Cache;32public class 7 {33 public static void main(String[] args) {34 Cache.value("key", () -> 1 + 2);35 }36}37import org.testingisdocumenting.webtau.cache.Cache;38public class 8 {39 public static void main(String[] args) {40 Cache.value("key", () -> 1 + 2);41 }42}43import org.testingisdocumenting.webtau.cache.Cache;44public class 9 {45 public static void main(String

Full Screen

Full Screen

value

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cache.Cache;2import org.testingisdocumenting.webtau.cache.CacheKey;3import java.util.concurrent.TimeUnit;4public class 2 {5 public static void main(String[] args) {6 CacheKey<String> cacheKey = CacheKey.create();7 String value = Cache.value(cacheKey, () -> "my value");8 System.out.println(value);9 }10}11import org.testingisdocumenting.webtau.cache.Cache;12import org.testingisdocumenting.webtau.cache.CacheKey;13import java.util.concurrent.TimeUnit;14public class 3 {15 public static void main(String[] args) {16 CacheKey<String> cacheKey = CacheKey.create();17 String value = Cache.value(cacheKey, () -> "my value", 10, TimeUnit.SECONDS);18 System.out.println(value);19 }20}21import org.testingisdocumenting.webtau.cache.Cache;22import org.testingisdocumenting.webtau.cache.CacheKey;23import java.util.concurrent.TimeUnit;24public class 4 {25 public static void main(String[] args) {26 CacheKey<String> cacheKey = CacheKey.create();27 String value = Cache.value(cacheKey, () -> "my value", 10, TimeUnit.SECONDS, 10, TimeUnit.SECONDS);28 System.out.println(value);29 }30}

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

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful