How to use AvailableBrowserCheckExeption class of ru.qatools.gridrouter.sessions package

Best Gridrouter code snippet using ru.qatools.gridrouter.sessions.AvailableBrowserCheckExeption

Source:RouteServlet.java Github

copy

Full Screen

...19import ru.qatools.gridrouter.config.Version;20import ru.qatools.gridrouter.json.JsonCapabilities;21import ru.qatools.gridrouter.json.JsonMessage;22import ru.qatools.gridrouter.json.JsonMessageFactory;23import ru.qatools.gridrouter.sessions.AvailableBrowserCheckExeption;24import ru.qatools.gridrouter.sessions.AvailableBrowsersChecker;25import ru.qatools.gridrouter.sessions.StatsCounter;26import javax.servlet.ServletException;27import javax.servlet.annotation.HttpConstraint;28import javax.servlet.annotation.ServletSecurity;29import javax.servlet.annotation.WebServlet;30import javax.servlet.http.HttpServletRequest;31import javax.servlet.http.HttpServletResponse;32import java.io.IOException;33import java.io.OutputStream;34import java.time.Instant;35import java.util.ArrayList;36import java.util.List;37import java.util.concurrent.Callable;38import java.util.concurrent.Executors;39import java.util.concurrent.ScheduledExecutorService;40import java.util.concurrent.TimeUnit;41import java.util.concurrent.atomic.AtomicBoolean;42import java.util.concurrent.atomic.AtomicLong;43import static java.lang.String.format;44import static java.nio.charset.StandardCharsets.UTF_8;45import static java.util.stream.Collectors.toList;46import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;47import static javax.servlet.http.HttpServletResponse.SC_OK;48import static org.apache.http.HttpHeaders.ACCEPT;49import static org.apache.http.entity.ContentType.APPLICATION_JSON;50import static ru.qatools.gridrouter.RequestUtils.getRemoteHost;51/**52 * @author Alexander Andyashin aandryashin@yandex-team.ru53 * @author Dmitry Baev charlie@yandex-team.ru54 * @author Innokenty Shuvalov innokenty@yandex-team.ru55 * @author Artem Eroshenko eroshenkoam@yandex-team.ru56 */57@WebServlet(urlPatterns = {"/wd/hub/session"}, asyncSupported = true)58@ServletSecurity(value = @HttpConstraint(rolesAllowed = {"user"}))59public class RouteServlet extends SpringHttpServlet {60 private static final Logger LOGGER = LoggerFactory.getLogger(RouteServlet.class);61 private static final String ROUTE_TIMEOUT_CAPABILITY = "grid.router.route.timeout.seconds";62 private static final int MAX_ROUTE_TIMEOUT_SECONDS = 300;63 @Autowired64 private transient ConfigRepository config;65 @Autowired66 private transient HostSelectionStrategy hostSelectionStrategy;67 @Autowired68 private transient StatsCounter statsCounter;69 @Autowired70 private transient CapabilityProcessorFactory capabilityProcessorFactory;71 @Autowired72 private transient AvailableBrowsersChecker avblBrowsersChecker;73 @Value("${grid.router.route.timeout.seconds:120}")74 private int routeTimeout;75 private AtomicLong requestCounter = new AtomicLong();76 @Override77 protected void doPost(HttpServletRequest request, HttpServletResponse response)78 throws ServletException, IOException {79 ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);80 JsonMessage message = JsonMessageFactory.from(request.getInputStream());81 long requestId = requestCounter.getAndIncrement();82 int routeTimeout = getRouteTimeout(request.getRemoteUser(), message);83 AtomicBoolean terminated = new AtomicBoolean(false);84 executor.submit(getRouteCallable(request, message, response, requestId, routeTimeout, terminated));85 executor.shutdown();86 try {87 executor.awaitTermination(routeTimeout, TimeUnit.SECONDS);88 terminated.set(true);89 } catch (InterruptedException e) {90 executor.shutdownNow();91 }92 replyWithError("Timed out when searching for valid host", response);93 }94 private Callable<Object> getRouteCallable(HttpServletRequest request, JsonMessage message, HttpServletResponse response,95 long requestId, int routeTimeout, AtomicBoolean terminated) {96 return () -> {97 route(request, message, response, requestId, routeTimeout, terminated);98 return null;99 };100 }101 private int getRouteTimeout(String user, JsonMessage message) {102 JsonCapabilities caps = message.getDesiredCapabilities();103 try {104 if (caps.any().containsKey(ROUTE_TIMEOUT_CAPABILITY)) {105 Integer desiredRouteTimeout = Integer.valueOf(String.valueOf(caps.any().get(ROUTE_TIMEOUT_CAPABILITY)));106 routeTimeout = (desiredRouteTimeout < MAX_ROUTE_TIMEOUT_SECONDS) ?107 desiredRouteTimeout :108 MAX_ROUTE_TIMEOUT_SECONDS;109 LOGGER.warn("[{}] [INVALID_ROUTE_TIMEOUT] [{}]", user, desiredRouteTimeout);110 }111 } catch (NumberFormatException ignored) {112 }113 return routeTimeout;114 }115 private void route(HttpServletRequest request, JsonMessage message,116 HttpServletResponse response,117 long requestId, int routeTimeout, AtomicBoolean terminated) throws IOException {118 long initialSeconds = Instant.now().getEpochSecond();119 JsonCapabilities caps = message.getDesiredCapabilities();120 String user = request.getRemoteUser();121 String remoteHost = getRemoteHost(request);122 String browser = caps.describe();123 Version actualVersion = config.findVersion(user, caps);124 if (actualVersion == null) {125 LOGGER.warn("[{}] [UNSUPPORTED_BROWSER] [{}] [{}] [{}]", requestId, user, remoteHost, browser);126 replyWithError(format("Cannot find %s capabilities on any available node",127 caps.describe()), response);128 return;129 }130 caps.setVersion(actualVersion.getNumber());131 capabilityProcessorFactory.getProcessor(caps).process(caps);132 List<Region> allRegions = actualVersion.getRegions()133 .stream().map(Region::copy).collect(toList());134 List<Region> unvisitedRegions = new ArrayList<>(allRegions);135 int attempt = 0;136 JsonMessage hubMessage = null;137 try (CloseableHttpClient client = newHttpClient(routeTimeout * 1000)) {138 if (actualVersion.getPermittedCount() != null) {139 avblBrowsersChecker.ensureFreeBrowsersAvailable(user, remoteHost, browser, actualVersion);140 }141 while (!allRegions.isEmpty() && !terminated.get()) {142 attempt++;143 Region currentRegion = hostSelectionStrategy.selectRegion(allRegions, unvisitedRegions);144 Host host = hostSelectionStrategy.selectHost(currentRegion.getHosts());145 String route = host.getRoute();146 try {147 LOGGER.info("[{}] [SESSION_ATTEMPTED] [{}] [{}] [{}] [{}] [{}]", requestId, user, remoteHost, browser, route, attempt);148 String target = route + request.getRequestURI();149 HttpResponse hubResponse = client.execute(post(target, message));150 hubMessage = JsonMessageFactory.from(hubResponse.getEntity().getContent());151 if (hubResponse.getStatusLine().getStatusCode() == SC_OK) {152 String sessionId = hubMessage.getSessionId();153 hubMessage.setSessionId(host.getRouteId() + sessionId);154 replyWithOk(hubMessage, response);155 long createdDurationSeconds = Instant.now().getEpochSecond() - initialSeconds;156 LOGGER.info("[{}] [{}] [SESSION_CREATED] [{}] [{}] [{}] [{}] [{}] [{}]",157 requestId, createdDurationSeconds, user, remoteHost, browser, route, sessionId, attempt);158 statsCounter.startSession(hubMessage.getSessionId(), user, caps.getBrowserName(), actualVersion.getNumber(), route);159 return;160 }161 LOGGER.warn("[{}] [SESSION_FAILED] [{}] [{}] [{}] [{}] - {}",162 requestId, user, remoteHost, browser, route, hubMessage.getErrorMessage());163 } catch (JsonProcessingException exception) {164 LOGGER.error("[{}] [BAD_HUB_JSON] [{}] [{}] [{}] [{}] - {}", "",165 requestId, user, remoteHost, browser, route, exception.getMessage());166 } catch (IOException exception) {167 LOGGER.error("[{}] [HUB_COMMUNICATION_FAILURE] [{}] [{}] [{}] - {}",168 requestId, user, remoteHost, browser, route, exception.getMessage());169 }170 currentRegion.getHosts().remove(host);171 if (currentRegion.getHosts().isEmpty()) {172 allRegions.remove(currentRegion);173 }174 unvisitedRegions.remove(currentRegion);175 if (unvisitedRegions.isEmpty()) {176 unvisitedRegions = new ArrayList<>(allRegions);177 }178 }179 } catch (AvailableBrowserCheckExeption e) {180 LOGGER.error("[{}] [AVAILABLE_BROWSER_CHECK_ERROR] [{}] [{}] [{}] - {}",181 requestId, user, remoteHost, browser, e.getMessage());182 }183 LOGGER.error("[{}] [SESSION_NOT_CREATED] [{}] [{}] [{}]", requestId, user, remoteHost, browser);184 if (hubMessage == null) {185 replyWithError("Cannot create session on any available node", response);186 } else {187 replyWithError(hubMessage, response);188 }189 }190 protected void replyWithOk(JsonMessage message, HttpServletResponse response) throws IOException {191 reply(SC_OK, message, response);192 }193 protected void replyWithError(String errorMessage, HttpServletResponse response) throws IOException {...

Full Screen

Full Screen

Source:WaitAvailableBrowserTimeoutException.java Github

copy

Full Screen

1package ru.qatools.gridrouter.sessions;2/**3 * @author Ilya Sadykov4 */5public class WaitAvailableBrowserTimeoutException extends AvailableBrowserCheckExeption {6 public WaitAvailableBrowserTimeoutException(String message) {7 super(message);8 }9 public WaitAvailableBrowserTimeoutException(String message, Throwable cause) {10 super(message, cause);11 }12}...

Full Screen

Full Screen

Source:AvailableBrowserCheckExeption.java Github

copy

Full Screen

1package ru.qatools.gridrouter.sessions;2/**3 * @author Ilya Sadykov4 */5public class AvailableBrowserCheckExeption extends RuntimeException {6 public AvailableBrowserCheckExeption(String message) {7 super(message);8 }9 public AvailableBrowserCheckExeption(String message, Throwable cause) {10 super(message, cause);11 }12}...

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter;2import org.junit.Test;3import ru.qatools.gridrouter.sessions.AvailableBrowserCheckException;4import ru.qatools.gridrouter.sessions.AvailableBrowserChecker;5import java.net.MalformedURLException;6import java.net.URL;7import static org.hamcrest.MatcherAssert.assertThat;8import static org.hamcrest.core.Is.is;9import static org.hamcrest.core.IsEqual.equalTo;10public class AvailableBrowserCheckExceptionTest {11 public void testAvailableBrowserChecker() throws MalformedURLException {12 try {13 availableBrowserChecker.check();14 } catch (AvailableBrowserCheckException e) {15 assertThat(e.getMessage(), is(equalTo("No available browser found")));16 }17 }18}19It is important to note that if the test fails, the build will be marked as failed. And if we want to see the test results, we can use the following command:20[INFO] --- maven-surefire-report-plugin:2.18.1:report (default-cli) @ gridrouter ---

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1import ru.qatools.gridrouter.sessions.AvailableBrowserCheckException;2import ru.qatools.gridrouter.sessions.Browser;3import ru.qatools.gridrouter.sessions.BrowserCheck;4import ru.qatools.gridrouter.sessions.BrowserCheckFactory;5import ru.qatools.gridrouter.sessions.BrowserFactory;6import ru.qatools.gridrouter.sessions.BrowserFactoryImpl;7import ru.qatools.gridrouter.sessions.BrowserType;8import ru.qatools.gridrouter.sessions.BrowserVersion;9import ru.qatools.gridrouter.sessions.Session;10import ru.qatools.gridrouter.sessions.SessionFactory;11import ru.qatools.gridrouter.sessions.SessionFactoryImpl;12import ru.qatools.gridrouter.sessions.SessionId;13import ru.qatools.gridrouter.sessions.SessionRequest;14import ru.qatools.gridrouter.sessions.SessionRequestFactory;15import ru.qatools.gridrouter.sessions.SessionRequestFactoryImpl;16import ru.qatools.gridrouter.sessions.SessionRequestParameters;17import ru.qatools.gridrouter.sessions.SessionRequestParametersFactory;18import ru.qatools.gridrouter.sessions.SessionRequestParametersFactoryImpl;19import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl;20import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.BrowserParameters;21import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.BrowserParametersImpl;22import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.NodeParameters;23import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.NodeParametersImpl;24import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.PlatformParameters;25import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.PlatformParametersImpl;26import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.ProxyParameters;27import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.ProxyParametersImpl;28import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.SessionParameters;29import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.SessionParametersImpl;30import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.TimeoutParameters;31import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.TimeoutParametersImpl;32import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.VncParameters;33import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.VncParametersImpl;34import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.WdParameters;35import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.WdParametersImpl;36import ru.qatools.gridrouter.sessions.SessionRequestParametersImpl.W

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.sessions;2import org.junit.Assert;3import org.junit.Test;4public class AvailableBrowserCheckExceptionTest {5 public void testAvailableBrowserCheckException() {6 String message = "test message";7 AvailableBrowserCheckException availableBrowserCheckException = new AvailableBrowserCheckException(message);8 Assert.assertEquals(message, availableBrowserCheckException.getMessage());9 }10}11package ru.qatools.gridrouter.sessions;12import org.junit.Assert;13import org.junit.Test;14public class BrowserNotFoundExceptionTest {15 public void testBrowserNotFoundException() {16 String message = "test message";17 BrowserNotFoundException browserNotFoundException = new BrowserNotFoundException(message);18 Assert.assertEquals(message, browserNotFoundException.getMessage());19 }20}21package ru.qatools.gridrouter.sessions;22import org.junit.Assert;23import org.junit.Test;24public class BrowserNotRegisteredExceptionTest {25 public void testBrowserNotRegisteredException() {26 String message = "test message";27 BrowserNotRegisteredException browserNotRegisteredException = new BrowserNotRegisteredException(message);28 Assert.assertEquals(message, browserNotRegisteredException.getMessage());29 }30}31package ru.qatools.gridrouter.sessions;32import org.junit.Assert;33import org.junit.Test;34public class BrowserNotRegisteredInGridExceptionTest {35 public void testBrowserNotRegisteredInGridException() {36 String message = "test message";37 BrowserNotRegisteredInGridException browserNotRegisteredInGridException = new BrowserNotRegisteredInGridException(message);38 Assert.assertEquals(message, browserNotRegisteredInGridException.getMessage());39 }40}41package ru.qatools.gridrouter.sessions;42import org.junit.Assert;43import org.junit.Test;44public class ClientNotFoundExceptionTest {45 public void testClientNotFoundException() {46 String message = "test message";47 ClientNotFoundException clientNotFoundException = new ClientNotFoundException(message);48 Assert.assertEquals(message, clientNotFoundException.getMessage());49 }50}

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.sessions;2import java.util.LinkedList;3import java.util.List;4import org.openqa.grid.common.exception.GridException;5public class AvailableBrowserCheckException extends GridException {6 private List<String> availableBrowsers = new LinkedList<String>();7 public AvailableBrowserCheckException(String message, List<String> availableBrowsers) {8 super(message);9 this.availableBrowsers = availableBrowsers;10 }11 public List<String> getAvailableBrowsers() {12 return availableBrowsers;13 }14}15package ru.qatools.gridrouter.sessions;16import java.util.LinkedList;17import java.util.List;18import org.openqa.grid.internal.Registry;19import org.openqa.grid.internal.TestSession;20import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;21import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;22import org.openqa.grid.web.servlet.handler.RequestType;23import org.openqa.grid.web.servlet.handler.SeleniumBasedRequest;24import org.openqa.selenium.remote.CapabilityType;25import org.openqa.selenium.remote.DesiredCapabilities;26public class AvailableBrowserCheck {27 public static void check(SeleniumBasedRequest request, Registry registry) {28 RequestType requestType = request.getRequestType();29 if (requestType == RequestType.START_SESSION) {30 DesiredCapabilities requestedCapabilities = request.getDesiredCapabilities();31 GridHubConfiguration hubConfig = registry.getHub().getConfiguration();32 GridNodeConfiguration nodeConfig = registry.getNewSessionRequest(requestedCapabilities, hubConfig)33 .getConfiguration();34 if (nodeConfig == null) {35 throw new AvailableBrowserCheckException(36 getAvailableBrowsers(requestedCapabilities, registry));37 }38 }39 }40 private static List<String> getAvailableBrowsers(DesiredCapabilities requestedCapabilities, Registry registry) {41 List<String> availableBrowsers = new LinkedList<String>();42 for (TestSession session : registry.getAllTestSessions()) {43 if (session.getSlot().getCapabilities().get(CapabilityType.BROWSER_NAME)44 .equals(requestedCapabilities.get(CapabilityType.BROWSER_NAME))) {45 availableBrowsers.add(session.getSlot().getCapabilities().get(CapabilityType

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1import org.openqa.grid.web.servlet.handler.RequestHandler;2import org.openqa.grid.web.servlet.handler.SeleniumBasedRequest;3import org.openqa.selenium.remote.DesiredCapabilities;4import ru.qatools.gridrouter.sessions.AvailableBrowserCheckException;5import ru.qatools.gridrouter.sessions.AvailableBrowserChecker;6public class 3 {7 public static void checkBrowserAvailable(RequestHandler handler) throws AvailableBrowserCheckException {8 SeleniumBasedRequest request = (SeleniumBasedRequest) handler.getRequest();9 DesiredCapabilities capabilities = request.getDesiredCapabilities();10 AvailableBrowserChecker.checkBrowserAvailable(capabilities);11 }12}13import org.openqa.grid.web.servlet.handler.RequestHandler;14import org.openqa.grid.web.servlet.handler.SeleniumBasedRequest;15import org.openqa.selenium.remote.DesiredCapabilities;16import ru.qatools.gridrouter.sessions.AvailableBrowserCheckException;17import ru.qatools.gridrouter.sessions.AvailableBrowserChecker;18public class 4 {19 public static void checkBrowserVersionAvailable(RequestHandler handler) throws AvailableBrowserCheckException {20 SeleniumBasedRequest request = (SeleniumBasedRequest) handler.getRequest();21 DesiredCapabilities capabilities = request.getDesiredCapabilities();22 AvailableBrowserChecker.checkBrowserVersionAvailable(capabilities);23 }24}25import org.openqa.grid.web.servlet.handler.RequestHandler;26import org.openqa.grid.web.servlet.handler.SeleniumBasedRequest;27import org.openqa.selenium.remote.DesiredCapabilities;28import ru.qatools.gridrouter.sessions.AvailableBrowserCheckException;29import ru.qatools.gridrouter.sessions.AvailableBrowserChecker;30public class 5 {31 public static void checkBrowserVersionAvailable(RequestHandler handler) throws AvailableBrowserCheckException {32 SeleniumBasedRequest request = (SeleniumBasedRequest) handler.getRequest();33 DesiredCapabilities capabilities = request.getDesiredCapabilities();34 AvailableBrowserChecker.checkBrowserVersionAvailable(capabilities);35 }36}

Full Screen

Full Screen

AvailableBrowserCheckExeption

Using AI Code Generation

copy

Full Screen

1package ru.qatools.gridrouter.sessions;2import org.openqa.selenium.remote.BrowserType;3import org.testng.annotations.Test;4import ru.qatools.gridrouter.sessions.AvailableBrowserCheckExeption;5import ru.qatools.gridrouter.sessions.AvailableBrowserCheck;6public class AvailableBrowserCheckExeptionTest {7public void testCheckBrowserAvailability() throws Exception {8AvailableBrowserCheck check = new AvailableBrowserCheck();9}10}

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

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

Most used methods in AvailableBrowserCheckExeption

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful