How to use updateBrowserCache method of com.paypal.selion.proxy.SeLionRemoteProxy class

Best SeLion code snippet using com.paypal.selion.proxy.SeLionRemoteProxy.updateBrowserCache

Source:SeLionRemoteProxy.java Github

copy

Full Screen

...151 // Enable the cache to store the browser information only when the152 // "com.paypal.selion.grid.servlets.GridStatistics" is enabled - results in153 // better memory management if the servlet is not loaded154 if (isSupportedOnHub(GridStatistics.class)) {155 updateBrowserCache(request);156 }157 // detect presence of SeLion servlet capabilities on proxy158 canForceShutdown = isSupportedOnNode(NodeForceRestartServlet.class);159 canAutoUpgrade = isSupportedOnNode(NodeAutoUpgradeServlet.class);160 canViewLogs = isSupportedOnNode(LogServlet.class);161 }162 /**163 * Determine if the hub supports the servlet in question by looking at the registry configuration.164 * @param servlet165 * the {@link HttpServlet} to ping166 * @return <code>true</code> or <code>false</code>167 */168 private boolean isSupportedOnHub(Class<? extends HttpServlet> servlet) {169 LOGGER.entering();170 final boolean response = getRegistry().getHub().getConfiguration().servlets.contains(servlet.getCanonicalName());171 LOGGER.exiting(response);172 return response;173 }174 /**175 * Determine if the remote proxy supports the servlet in question by sending a http request to the remote. The176 * proxy configuration could also be used to make a similar decision. This approach allows the remote to use a177 * servlet which implements the same functionality as the `servlet` expected but does not necessarily reside in the178 * same namespace. This method expects the `servlet` to return HTTP 200 OK as an indication that the remote proxy179 * supports the `servlet` in question.180 *181 * @param servlet182 * the {@link HttpServlet} to ping183 * @return <code>true</code> or <code>false</code>184 */185 private boolean isSupportedOnNode(Class<? extends HttpServlet> servlet) {186 LOGGER.entering();187 RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)188 .setSocketTimeout(CONNECTION_TIMEOUT).build();189 CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();190 String url = String.format("http://%s:%d/extra/%s", machine, getRemoteHost().getPort(),191 servlet.getSimpleName());192 try {193 HttpGet get = new HttpGet(url);194 final HttpResponse getResponse = client.execute(get);195 if (getResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {196 proxyLogger.warning("Node " + getId() + " does not have or support " + servlet.getSimpleName());197 LOGGER.exiting(false);198 return false;199 }200 } catch (IOException e) {201 LOGGER.log(Level.SEVERE, e.getMessage(), e);202 LOGGER.exiting(false);203 return false;204 } finally {205 try {206 client.close();207 } catch (IOException e) {208 LOGGER.log(Level.SEVERE, e.getMessage(), e);209 }210 }211 LOGGER.exiting(true);212 return true;213 }214 private HttpResponse sendToNodeServlet(Class<? extends HttpServlet> servlet, List<NameValuePair> nvps) {215 LOGGER.entering();216 RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)217 .setSocketTimeout(CONNECTION_TIMEOUT).build();218 CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();219 String url = String.format("http://%s:%d/extra/%s", machine, this.getRemoteHost().getPort(),220 servlet.getSimpleName());221 HttpResponse postResponse = null;222 try {223 HttpPost post = new HttpPost(url);224 post.setEntity(new UrlEncodedFormEntity(nvps));225 postResponse = client.execute(post);226 } catch (IOException e) {227 LOGGER.log(Level.SEVERE, e.getMessage(), e);228 } finally {229 try {230 client.close();231 } catch (IOException e) {232 LOGGER.log(Level.SEVERE, e.getMessage(), e);233 }234 }235 LOGGER.exiting(postResponse);236 return postResponse;237 }238 /**239 * Upgrades the node by calling {@link NodeAutoUpgradeServlet} and then {@link #requestNodeShutdown}240 *241 * @param downloadJSON242 * the download.json to install on node243 * @return <code>true</code> on success. <code>false</code> when an error occured.244 */245 public boolean upgradeNode(String downloadJSON) {246 LOGGER.entering(downloadJSON);247 // verify the servlet is supported on the node248 if (!supportsAutoUpgrade()) {249 LOGGER.exiting(false);250 return false;251 }252 // call the NodeAutoUpgradeServlet on the node253 proxyLogger.fine("Upgrading node " + getId());254 List<NameValuePair> nvps = new ArrayList<>();255 nvps.add(new BasicNameValuePair(NodeAutoUpgradeServlet.TOKEN_PARAMETER,256 NodeAutoUpgradeServlet.CONFIGURED_TOKEN_VALUE));257 NameValuePair jsonNVP = new BasicNameValuePair(GridAutoUpgradeDelegateServlet.PARAM_JSON, downloadJSON);258 nvps.add(jsonNVP);259 HttpResponse response = sendToNodeServlet(NodeAutoUpgradeServlet.class, nvps);260 if (response == null) {261 proxyLogger.warning("Node " + getId() + " failed to upgrade and returned a null response.");262 LOGGER.exiting(false);263 return false;264 }265 final int responseStatusCode = response.getStatusLine().getStatusCode();266 if (responseStatusCode != HttpStatus.SC_OK) {267 proxyLogger.warning("Node " + getId() + " failed to upgrade and returned HTTP " + responseStatusCode);268 LOGGER.exiting(false);269 return false;270 }271 requestNodeShutdown();272 LOGGER.exiting(true);273 return true;274 }275 /**276 * @return whether the proxy has reached the max unique sessions277 */278 private boolean isMaxUniqueSessionsReached() {279 if (!isEnabledMaxUniqueSessions()) {280 return false;281 }282 return totalSessionsStarted >= getMaxSessionsAllowed();283 }284 @Override285 public TestSession getNewSession(Map<String, Object> requestedCapability) {286 LOGGER.entering();287 // verification should be before lock to avoid unnecessarily acquiring lock288 if (isMaxUniqueSessionsReached() || scheduledShutdown) {289 LOGGER.exiting(null);290 return logSessionInfo();291 }292 try {293 accessLock.lock();294 // As per double-checked locking pattern need to have check once again295 // to avoid spawning additional session then maxSessionAllowed296 if (isMaxUniqueSessionsReached() || scheduledShutdown) {297 LOGGER.exiting(null);298 return logSessionInfo();299 }300 TestSession session = super.getNewSession(requestedCapability);301 if (session != null) {302 // count ONLY if the session was a valid one303 totalSessionsStarted++;304 if (isMaxUniqueSessionsReached()) {305 startNodeRecycleThread();306 }307 proxyLogger.fine("Beginning session #" + totalSessionsStarted + " (" + session.toString() + ")");308 }309 LOGGER.exiting((session != null) ? session.toString() : null);310 return session;311 } finally {312 accessLock.unlock();313 }314 }315 private TestSession logSessionInfo() {316 proxyLogger.fine("Was max sessions reached? " + (isMaxUniqueSessionsReached()) + " on node " + getId());317 proxyLogger.fine("Was this a scheduled shutdown? " + (scheduledShutdown) + " on node " + getId());318 return null;319 }320 private void startNodeRecycleThread() {321 if (!getNodeRecycleThread().isAlive()) {322 getNodeRecycleThread().start();323 }324 }325 private void stopNodeRecycleThread() {326 if (getNodeRecycleThread().isAlive()) {327 try {328 getNodeRecycleThread().shutdown();329 getNodeRecycleThread().join(2000); // Wait no longer than 2x the recycle thread's loop330 } catch (InterruptedException e) { // NOSONAR331 // ignore332 }333 }334 }335 private void updateBrowserCache(RegistrationRequest request) throws MalformedURLException {336 // Update the browser information cache. Used by GridStatics servlet337 for (MutableCapabilities desiredCapabilities : request.getConfiguration().capabilities) {338 Map<String, ?> capabilitiesMap = desiredCapabilities.asMap();339 String browserName = capabilitiesMap.get(CapabilityType.BROWSER_NAME).toString();340 String maxInstancesAsString = capabilitiesMap.get("maxInstances").toString();341 if (StringUtils.isNotBlank(browserName) && StringUtils.isNotBlank(maxInstancesAsString)) {342 int maxInstances = Integer.valueOf(maxInstancesAsString);343 BrowserInformationCache cache = BrowserInformationCache.getInstance();344 cache.updateBrowserInfo(getRemoteHost(), browserName, maxInstances);345 }346 }347 }348 @Override349 public void afterSession(TestSession session) {...

Full Screen

Full Screen

updateBrowserCache

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import com.paypal.selion.proxy.SeLionRemoteProxy;4import java.net.MalformedURLException;5import java.net.URL;6public class ProxyTest {7 public static void main(String[] args) throws MalformedURLException {8 DesiredCapabilities caps = new DesiredCapabilities();9 caps.setBrowserName("chrome");10 caps.setVersion("latest");11 caps.setCapability("enableVNC", true);12 caps.setCapability("enableVideo", false);13 caps.setCapability("name", "SeLion Proxy Test");14 SeLionRemoteProxy.updateBrowserCache(driver, 0);15 driver.quit();16 }17}

Full Screen

Full Screen

updateBrowserCache

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.proxy.SeLionRemoteProxy;2SeLionRemoteProxy proxy = new SeLionRemoteProxy();3proxy.updateBrowserCache();4import com.paypal.selion.proxy.SeLionRemoteProxy;5SeLionRemoteProxy proxy = new SeLionRemoteProxy();6proxy.getBrowserCache();7import com.paypal.selion.proxy.SeLionRemoteProxy;8SeLionRemoteProxy proxy = new SeLionRemoteProxy();9proxy.updateBrowserCache();10Map<String, String> browserCache = proxy.getBrowserCache();11import com.paypal.selion.proxy.SeLionRemoteProxy;12SeLionRemoteProxy proxy = new SeLionRemoteProxy();13proxy.updateBrowserCache();14Map<String, String> browserCache = proxy.getBrowserCache();

Full Screen

Full Screen

updateBrowserCache

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.platform.grid.Grid;2import com.paypal.selion.proxy.SeLionRemoteProxy;3public class UpdateBrowserCache {4 public static void main(String[] args) {5 SeLionRemoteProxy proxy = new SeLionRemoteProxy();6 proxy.updateBrowserCache();7 }8}

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