How to use addToAccountCache method of com.paypal.selion.utils.SauceLabsRestApi class

Best SeLion code snippet using com.paypal.selion.utils.SauceLabsRestApi.addToAccountCache

Source:SauceLabsRestApi.java Github

copy

Full Screen

...168 }169 LOGGER.exiting(maxTestCase);170 return maxTestCase;171 }172 private void addToAccountCache(String md5, boolean valid) {173 if (accountCache.size() >= MAX_CACHE) {174 // don't let the cache grow more than MAX_CACHE175 accountCache.clear();176 }177 accountCache.put(md5, valid);178 }179 private String md5(String value) {180 return DigestUtils.md5Hex(value);181 }182 /**183 * Determine if the account credentials specified are valid by calling the sauce rest api. Uses a local account184 * cache for credentials which have already been presented. Cached credentials expire when the cache reaches a size185 * of {@link SauceLabsRestApi#MAX_CACHE}186 * 187 * @param username188 * the user name189 * @param apiKey190 * the sauce labs api access key191 * @return <code>true</code> on success. <code>false</code> if unauthorized or unable to call sauce.192 */193 public synchronized boolean isAuthenticated(String username, String apiKey) {194 LOGGER.entering();195 final String key = username + ":" + apiKey;196 final String authKey = new String(Base64.encodeBase64(key.getBytes()));197 if (accountCache.containsKey(md5(authKey))) {198 final boolean authenticated = accountCache.get(md5(authKey));199 LOGGER.exiting(authenticated);200 return authenticated;201 }202 SauceLabsHttpResponse response;203 try {204 final URL url = new URL(SauceConfigReader.getInstance().getSauceURL() + "/users/" + username);205 response = doSauceRequest(url, authKey, sauceTimeout, 0);206 if (response.getStatus() == HttpStatus.SC_OK) {207 addToAccountCache(md5(authKey), true);208 LOGGER.exiting(true);209 return true;210 }211 } catch (IOException e) {212 LOGGER.log(Level.SEVERE, "Unable to communicate with sauce labs api.", e);213 }214 // TODO don't add to cache if sauce api is down215 addToAccountCache(md5(authKey), false);216 LOGGER.exiting(false);217 return false;218 }219}...

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 SeLion 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