Best Gridrouter code snippet using ru.qatools.gridrouter.sessions.BrowserVersion
Source:SelenographDB.java
1package ru.qatools.selenograph.ext;2import com.mongodb.MongoClient;3import com.mongodb.bulk.BulkWriteResult;4import com.mongodb.client.MongoCollection;5import com.mongodb.client.MongoDatabase;6import com.mongodb.client.model.DeleteOneModel;7import com.mongodb.client.model.UpdateOneModel;8import com.mongodb.client.model.UpdateOptions;9import org.apache.commons.lang3.tuple.Pair;10import org.bson.Document;11import org.slf4j.Logger;12import org.slf4j.LoggerFactory;13import ru.qatools.gridrouter.ConfigRepository;14import ru.qatools.gridrouter.config.Browsers;15import ru.qatools.selenograph.gridrouter.*;16import javax.inject.Inject;17import java.util.*;18import java.util.function.Consumer;19import static com.mongodb.client.model.Filters.*;20import static java.lang.System.currentTimeMillis;21import static java.util.Arrays.asList;22import static java.util.Collections.emptyMap;23import static java.util.Collections.sort;24import static java.util.stream.Collectors.*;25import static org.apache.commons.lang3.tuple.Pair.of;26import static ru.qatools.selenograph.ext.SelenographMongoSerializer.OBJECT_FIELD;27import static ru.qatools.selenograph.gridrouter.Key.browserName;28import static ru.qatools.selenograph.gridrouter.Key.browserVersion;29import static ru.yandex.qatools.camelot.util.MapUtil.map;30/**31 * @author Ilya Sadykov32 * WARN: MongoDB extension direct dependency!33 */34@SuppressWarnings("unchecked")35public class SelenographDB {36 public static final String ALL = "all";37 private static final Logger LOGGER = LoggerFactory.getLogger(SelenographDB.class);38 private static final String SESSIONS_COL_NAME = "sessions";39 private final MongoClient mongo;40 private final String dbName;41 private final SelenographMongoSerializer serializer;42 @Inject43 private ConfigRepository config;44 public SelenographDB(MongoClient mongo, String dbName,45 SelenographMongoSerializer serializer) {46 this.mongo = mongo;47 this.dbName = dbName;48 this.serializer = serializer;49 }50 private static Map<String, Map<BrowserContext, Integer>> quotaCounts(Map<String, Browsers> quotaMap) {51 Map<String, Map<BrowserContext, Integer>> res = new LinkedHashMap<>();52 Map<Pair<BrowserContext, String>, Integer> hubMax = new HashMap<>();53 quotaMap.entrySet().forEach(e -> {54 final String quota = e.getKey();55 res.putIfAbsent(quota, new LinkedHashMap<>());56 e.getValue().getBrowsers().forEach(b ->57 b.getVersions().forEach(v -> {58 final BrowserContext key = new UserBrowser().withBrowser(browserName(b.getName()))59 .withVersion(browserVersion(v.getNumber()))60 .withTimestamp(0);61 v.getRegions().stream()62 .flatMap(r -> r.getHosts().stream())63 .forEach(h -> {64 final Pair<BrowserContext, String> pair = of(key, h.getAddress());65 if (!hubMax.containsKey(pair) || hubMax.get(pair) < h.getCount()) {66 hubMax.put(pair, h.getCount());67 }68 });69 res.get(quota).putIfAbsent(key, 0);70 res.get(quota).put(key, res.get(quota).get(key) + v.getCount());71 }));72 });73 res.put(ALL, new HashMap<>());74 hubMax.entrySet().stream().collect(groupingBy(e -> e.getKey().getKey(), summingInt(Map.Entry::getValue)))75 .entrySet().forEach(e -> res.get(ALL).putIfAbsent(e.getKey(), e.getValue()));76 return res;77 }78 private static Map<String, Map<BrowserContext, Integer>> runningCounts(Map<BrowserContext, Integer> counts) {79 Map<String, Map<BrowserContext, Integer>> res = new LinkedHashMap<>();80 counts.entrySet().forEach(e -> {81 final BrowserContext context = e.getKey();82 final String quota = context.getUser();83 final BrowserContext key = new UserBrowser()84 .withBrowser(browserName(context.getBrowser()))85 .withVersion(browserVersion(context.getVersion()))86 .withTimestamp(0);87 res.putIfAbsent(ALL, new HashMap<>());88 res.putIfAbsent(quota, new HashMap<>());89 res.get(ALL).putIfAbsent(key, 0);90 res.get(quota).putIfAbsent(key, 0);91 res.get(ALL).put(key, res.get(ALL).get(key) + e.getValue());92 res.get(quota).put(key, res.get(quota).get(key) + e.getValue());93 });94 return res;95 }96 public void init() {97 sessions().createIndex(new Document(map(98 "object.user", 1,99 "object.browser", 1,100 "object.version", 1101 )));102 sessions().createIndex(new Document(map(103 "object.user", 1104 )));105 sessions().createIndex(new Document(map(106 "object.timestamp", 1107 )));108 }109 public Map<String, BrowserSummaries> getQuotasSummary() {110 final Map<String, Map<BrowserContext, Integer>> running = runningCounts(sessionsByUserCount());111 final Map<String, Browsers> quotaMap = config.getQuotaMap();112 final List<String> quotas = new ArrayList<>();113 quotas.add(ALL);114 quotas.addAll(quotaMap.keySet());115 sort(quotas);116 final Map<String, Map<BrowserContext, Integer>> available = quotaCounts(quotaMap);117 final Map<String, BrowserSummaries> state = new LinkedHashMap<>();118 quotas.forEach(quota -> {119 state.putIfAbsent(quota, new BrowserSummaries());120 state.get(quota).addOrIncrement(121 available.getOrDefault(quota, emptyMap()),122 running.getOrDefault(quota, emptyMap())123 );124 });125 state.values().forEach(BrowserSummaries::sort);126 return state;127 }128 public Map<BrowserContext, Integer> sessionsByUserCount() {129 Map<BrowserContext, Integer> results = new HashMap<>();130 sessions().aggregate(asList(131 new Document("$unwind", new Document(map(132 "path", "$object",133 "includeArrayIndex", "index"134 ))),135 new Document("$match", new Document("index", 1)),136 new Document("$project", new Document("object", 1)),137 new Document("$project", new Document(map(138 "user", "$object.user",139 "browser", "$object.browser",140 "version", "$object.version"141 ))),142 new Document("$group", new Document(map(143 "_id", new Document(map(144 "user", "$user",145 "browser", "$browser",146 "version", "$version"147 )),148 "user", new Document("$first", "$user"),149 "browser", new Document("$first", "$browser"),150 "version", new Document("$first", "$version"),151 "count", new Document("$sum", 1)152 )))153 )).forEach((Consumer<Document>) d -> results.put(154 new UserBrowser()155 .withUser(d.getString("user"))156 .withBrowser(d.getString("browser"))157 .withVersion(d.getString("version")),158 d.getInteger("count")159 ));160 return results;161 }162 public long countSessionsByUser(String user) {163 return sessions().count(eq("object.user", user));164 }165 public long countSessionsByUserAndBrowser(String user, String browser, String version) {166 return sessions().count(and(167 eq("object.user", user),168 eq("object.browser", browser),169 eq("object.version", version)170 ));171 }172 public Set<SessionEvent> sessionsByUser(String user) {173 final Set<SessionEvent> result = new LinkedHashSet<>();174 sessions().find(eq("object.user", user)).forEach((Consumer<Document>) document ->175 result.add(convertDocument(document, SessionEvent.class)));176 return result;177 }178 public void deleteSessionsOlderThan(long timeout) {179 sessions().deleteMany(lt("object.timestamp", currentTimeMillis() - timeout));180 }181 public Set<String> getActiveSessions() {182 final Set<String> result = new LinkedHashSet<>();183 sessions().find().projection(new Document("_id", 1))184 .map(d -> d.getString("_id"))185 .forEach((Consumer<String>) result::add);186 return result;187 }188 public SessionEvent findSessionById(String sessionId) {189 return convertDocument(190 sessions().find(eq("_id", sessionId)).first(), SessionEvent.class191 );192 }193 public <T extends Document> void bulkUpsertSessions(Collection<SessionEvent> events) {194 final BulkWriteResult res = sessions().bulkWrite(events.stream().map(event -> {195 if (event instanceof DeleteSessionEvent) {196 return new DeleteOneModel<T>(new Document("_id", event.getSessionId()));197 } else if (event instanceof UpdateSessionEvent) {198 return new UpdateOneModel<T>(199 new Document("_id", event.getSessionId()).append("object.sessionId", event.getSessionId()),200 new Document("$set", new Document("object.$.timestamp", event.getTimestamp()))201 );202 } else {203 return new UpdateOneModel<T>(204 new Document("_id", event.getSessionId()),205 new Document("$set", new Document("object", serializer.toDBObject(event).get(OBJECT_FIELD))),206 new UpdateOptions().upsert(true)207 );208 }209 }).collect(toList()));210 LOGGER.info("Sessions update in bulk results: {} created, {} updated, {} deleted, {} upserted",211 res.getInsertedCount(), res.getModifiedCount(), res.getDeletedCount(), res.getUpserts().size());212 }213 private <T> T convertDocument(Document document, Class<T> clazz) {214 try {215 return (T) serializer.fromDBObject(document, clazz);216 } catch (Exception e) {217 LOGGER.error("Failed to conert mongo document", e);218 return null;219 }220 }221 private MongoCollection<Document> sessions() {222 return mongo.getDatabase(dbName).getCollection(SESSIONS_COL_NAME);223 }224 public void clear() {225 MongoDatabase db = mongo.getDatabase(dbName);226 for (String colName : db.listCollectionNames()) {227 db.getCollection(colName).drop();228 }229 }230}...
Source:SessionsAggregator.java
1package ru.qatools.selenograph.gridrouter;2import org.slf4j.Logger;3import org.slf4j.LoggerFactory;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.beans.factory.annotation.Value;6import ru.qatools.gridrouter.sessions.StatsCounter;7import ru.qatools.selenograph.ext.SelenographDB;8import ru.yandex.qatools.camelot.common.ProcessingEngine;9import javax.inject.Inject;10import java.time.Duration;11import java.util.*;12import java.util.concurrent.ConcurrentLinkedDeque;13import static java.lang.System.currentTimeMillis;14import static ru.qatools.selenograph.gridrouter.Key.browserName;15import static ru.qatools.selenograph.gridrouter.Key.browserVersion;16import static ru.yandex.qatools.camelot.api.Constants.Keys.ALL;17/**18 * @author Ilya Sadykov19 */20public class SessionsAggregator implements StatsCounter {21 static final String ROUTE_REGEX = "http://([^:]+):(\\d+)";22 private static final Logger LOGGER = LoggerFactory.getLogger(SessionsAggregator.class);23 private static final Queue<SessionEvent> bulkUpsertQueue = new ConcurrentLinkedDeque<>();24 @Inject25 SelenographDB database;26 @Inject27 ProcessingEngine procEngine;28 @Autowired29 public SessionsAggregator(@Value("${selenograph.sessions.bulk.flush.interval.ms}")30 long bulkFlushIntervalMs) {31 final Timer bulkTimer = new Timer();32 LOGGER.info("Initializing bulk flush timer...");33 bulkTimer.schedule(new TimerTask() {34 @Override35 public void run() {36 flushBulkUpsertBuffer();37 }38 }, new Random().nextInt(100), bulkFlushIntervalMs);39 }40 @Override41 public void startSession(String sessionId, String user, String browser, String version, String route) {42 final String name = browserName(browser);43 final String ver = browserVersion(version);44 LOGGER.info("Starting session {} for {}:{}:{} ({})", sessionId, user, name, ver, route);45 final StartSessionEvent startEvent = (StartSessionEvent) new StartSessionEvent()46 .withSessionId(sessionId)47 .withRoute(route)48 .withUser(user)49 .withBrowser(name)50 .withVersion(ver)51 .withTimestamp(currentTimeMillis());52 bulkUpsertQueue.offer(startEvent);53 }54 @Override55 public void deleteSession(String sessionId, String route) {56 LOGGER.info("Removing session {} ({})", sessionId, route);57 bulkUpsertQueue.offer(new DeleteSessionEvent().withSessionId(sessionId).withRoute(route));58 }59 @Override60 public void updateSession(String sessionId, String route) {61 LOGGER.info("Updating session {} ({})", sessionId, route);62 bulkUpsertQueue.offer((SessionEvent) new UpdateSessionEvent()63 .withSessionId(sessionId).withRoute(route).withTimestamp(currentTimeMillis()));64 }65 @Override66 public void expireSessionsOlderThan(Duration duration) {67 database.deleteSessionsOlderThan(duration.toMillis());68 }69 @Override70 public Set<String> getActiveSessions() {71 return database.getActiveSessions();72 }73 @Override74 public SessionsCountsPerUser getStats(String user) {75 final SessionsCountsPerUser stats = (SessionsCountsPerUser) procEngine.getInterop()76 .repo(QuotaStatsAggregator.class).get(ALL);77 return stats != null ? stats : new SessionsCountsPerUser();78 }79 @Override80 public int getSessionsCountForUser(String user) {81 return (int) database.countSessionsByUser(user);82 }83 @Override84 public int getSessionsCountForUserAndBrowser(String user, String browser, String version) {85 return (int) database.countSessionsByUserAndBrowser(user, browser, version);86 }87 Set<SessionEvent> sessionsByUser(String user) {88 return database.sessionsByUser(user);89 }90 public void flushBulkUpsertBuffer() {91 try {92 LOGGER.info("Flushing upsert buffer. Queue size is {}", bulkUpsertQueue.size());93 SessionEvent event;94 final List<SessionEvent> events = new ArrayList<>();95 while ((event = bulkUpsertQueue.poll()) != null) {96 events.add(event);97 }98 if (!events.isEmpty()) {99 database.bulkUpsertSessions(events);100 }101 } catch (Exception e) {102 LOGGER.error("Failed to perform bulk update of sessions", e);103 bulkUpsertQueue.clear();104 }105 }106 public SessionEvent findSessionById(String sessionId) {107 return database.findSessionById(sessionId);108 }109}...
Source:BrowserVersion.java
1package ru.qatools.gridrouter.sessions;2/**3 * @author Innokenty Shuvalov innokenty@yandex-team.ru4 */5public class BrowserVersion {6 private final String browser;7 private final String version;8 public BrowserVersion(String browser, String version) {9 this.browser = browser;10 this.version = version;11 }12 public String getBrowser() {13 return browser;14 }15 public String getVersion() {16 return version;17 }18}...
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import org.openqa.grid.common.RegistrationRequest;3import org.openqa.grid.common.SeleniumProtocol;4import org.openqa.grid.common.exception.GridException;5import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;6import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;7import org.openqa.grid.internal.utils.configuration.StandaloneConfiguration;8import org.openqa.grid.selenium.GridLauncherV3;9import org.openqa.grid.web.Hub;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.server.DefaultDriverProvider;12import org.openqa.selenium.remote.server.DefaultDriverFactory;13import org.openqa.selenium.remote.server.DriverProvider;14import org.openqa.selenium.remote.server.SeleniumServer;15import org.openqa.selenium.remote.server.log.LoggingManager;16import org.openqa.selenium.remote.server.log.TerseFormatter;17import org.openqa.selenium.remote.server.log.TerseHandler;18import org.openqa.selenium.remote.server.log.TerseServerFormatter;19import org.openqa.selenium.remote.server.log.TerseServletFormatter;20import org.openqa.selenium.remote.server.log.TerseTestSessionFormatter;21import org.openqa.selenium.remote.server.renderer.JsonErrorResult;22import org.openqa.selenium.remote.server.renderer.JsonResult;23import org.openqa.selenium.remote.server.renderer.StaticResult;24import org.openqa.selenium.remote.server.rest.RestishHandler;25import org.openqa.selenium.remote.server.rest.ResultConfig;26import org.openqa.selenium.remote.server.rest.ResultType;27import org.openqa.selenium.remote.server.rest.handler.ExceptionHandler;28import org.openqa.selenium.remote.server.rest.handler.HttpMethod;29import org.openqa.selenium.remote.server.rest.handler.Render;30import org.openqa.selenium.remote.server.rest.handler.RequestHandler;31import org.openqa.selenium.remote.server.rest.handler.ResponseConfig;32import org.openqa.selenium.remote.server.rest.handler.ResponseType;33import org.openqa.selenium.remote.server.rest.handler.Route;34import org.openqa.selenium.remote.server.rest.handler.StatusCodes;35import org.openqa.selenium.remote.server.rest.handler.WebDriverLikeRequest;36import org.openqa.selenium.remote.server.rest.handler.WebDriverLikeResponse;37import org.openqa.selenium.remote.server.rest.handler.WebDriverSpecBindings;38import org.openqa.selenium.remote.server.rest.handler.html.StaticHtmlHandler;39import org.openqa.selenium.remote.server.rest.handler.internal.ActiveSessions;40import org.openqa.selenium.remote.server.rest.handler.internal.DeleteSession;41import org.openqa.selenium.remote.server.rest.handler.internal.GetSession;42import org.openqa.selenium.remote.server.rest.handler.internal.GetSessions;43import org.openqa.selenium.remote.server.rest.handler.internal.NewSession;44import org.openqa.selenium.remote.server.rest.handler.internal.Status;45import org.openqa.selenium.remote.server.rest.handler.internal.WebDriverSpecHandler;46import org.openqa.selenium.remote.server.rest.handler.internal.WebElement
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import org.openqa.selenium.remote.SessionId;5import org.openqa.selenium.remote.http.HttpClient;6import org.openqa.selenium.remote.http.HttpRequest;7import org.openqa.selenium.remote.http.HttpResponse;8import org.openqa.selenium.remote.internal.ApacheHttpClient;9import org.openqa.selenium.remote.internal.HttpClientFactory;10import org.openqa.selenium.remote.internal.JsonToBeanConverter;11import org.openqa.selenium.remote.service.DriverService;12import org.openqa.selenium.remote.service.DriverCommandExecutor;13import java.io.IOException;14import java.net.URL;15import java.util.Map;16import java.util.concurrent.TimeUnit;17public class BrowserVersion {18 private static final JsonToBeanConverter CONVERTER = new JsonToBeanConverter();19 private static final HttpClientFactory CLIENT_FACTORY = new HttpClientFactory();20 public static void main(String[] args) throws IOException {21 DesiredCapabilities caps = DesiredCapabilities.chrome();22 caps.setCapability("browserVersion", "61.0");23 caps.setCapability("platformName", "WIN10");24 caps.setCapability("enableVNC", true);25 caps.setCapability("enableVideo", true);26 caps.setCapability("videoScreenSize", "1920x1080");27 caps.setCapability("videoFrameRate", 24);28 caps.setCapability("timeZone", "Europe/Moscow");29 caps.setCapability("screenResolution", "1920x1080x24");30 caps.setCapability("enableLog", true);31 caps.setCapability("sessionTimeout", "30m");32 caps.setCapability("enableRealMobile", true);33 caps.setCapability("realMobile", "true");34 caps.setCapability("deviceName", "Apple iPhone 6");35 caps.setCapability("deviceOrientation", "portrait");36 caps.setCapability("platformVersion", "9.3");37 caps.setCapability("platformName", "iOS");38 caps.setCapability("browserName", "Safari");39 caps.setCapability("browserVersion", "9.0");40 caps.setCapability("enableVNC", true);41 caps.setCapability("enableVideo", true);42 caps.setCapability("videoScreenSize", "1920x1080");43 caps.setCapability("videoFrameRate", 24);44 caps.setCapability("timeZone", "Europe/Moscow");
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import org.junit.Test;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.SessionId;7import java.net.MalformedURLException;8import java.net.URL;9public class BrowserVersionTest {10 public void testBrowserVersion() throws MalformedURLException {11 DesiredCapabilities capabilities = DesiredCapabilities.chrome();12 capabilities.setBrowserName("chrome");13 capabilities.setVersion("45.0");14 WebDriver driver = new RemoteWebDriver(url, capabilities);15 SessionId sessionId = driver.getSessionId();16 BrowserVersion browserVersion = BrowserVersion.get(sessionId);17 System.out.println(browserVersion);18 driver.quit();19 }20}21package ru.qatools.gridrouter.sessions;22import org.openqa.selenium.remote.SessionId;23import java.util.HashMap;24import java.util.Map;25public class BrowserVersion {26 private static Map<SessionId, String> browserVersionMap = new HashMap<SessionId, String>();27 public static void set(SessionId sessionId, String version) {28 browserVersionMap.put(sessionId, version);29 }30 public static String get(SessionId sessionId) {31 return browserVersionMap.get(sessionId);32 }33}34package ru.qatools.gridrouter.sessions;35import org.openqa.selenium.remote.SessionId;36import java.util.HashMap;37import java.util.Map;38public class BrowserVersion {39 private static Map<SessionId, String> browserVersionMap = new HashMap<SessionId, String>();40 public static void set(SessionId sessionId, String version) {41 browserVersionMap.put(sessionId, version);42 }43 public static String get(SessionId sessionId) {44 return browserVersionMap.get(sessionId);45 }46}47package ru.qatools.gridrouter.sessions;48import org.junit.Test;49import org.openqa.selenium.WebDriver;50import org.openqa.selenium.remote.DesiredCapabilities;51import org.openqa.selenium.remote.RemoteWebDriver;52import org.openqa.selenium.remote.SessionId;53import java.net.MalformedURLException;54import java.net.URL;55public class BrowserVersionTest {56 public void testBrowserVersion() throws MalformedURLException {
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import java.net.URL;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5public class BrowserVersionTest {6 public static void main(String[] args) throws Exception {7 DesiredCapabilities capabilities = DesiredCapabilities.chrome();8 capabilities.setBrowserName("chrome");9 capabilities.setVersion("42.0");10 capabilities.setCapability("platform", "LINUX");11 capabilities.setCapability("browserVersion", "42.0");12 System.out.println(driver.getTitle());13 driver.quit();14 }15}16package org.openqa.selenium.remote;17import java.net.URL;18import org.openqa.selenium.remote.DesiredCapabilities;19import org.openqa.selenium.remote.RemoteWebDriver;20public class BrowserVersionTest {21 public static void main(String[] args) throws Exception {22 DesiredCapabilities capabilities = DesiredCapabilities.chrome();23 capabilities.setBrowserName("chrome");24 capabilities.setVersion("42.0");25 capabilities.setCapability("platform", "LINUX");26 capabilities.setCapability("browserVersion", "42.0");27 System.out.println(driver.getTitle());28 driver.quit();29 }30}31package org.openqa.selenium;32import java.net.URL;33import org.openqa.selenium.remote.DesiredCapabilities;34import org.openqa.selenium.remote.RemoteWebDriver;35public class BrowserVersionTest {36 public static void main(String[] args) throws Exception {37 DesiredCapabilities capabilities = DesiredCapabilities.chrome();38 capabilities.setBrowserName("chrome");39 capabilities.setVersion("42.0");40 capabilities.setCapability("platform", "LINUX");41 capabilities.setCapability("browserVersion", "42.0");42 System.out.println(driver.getTitle());43 driver.quit();44 }45}
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import org.openqa.selenium.remote.DesiredCapabilities;3public class BrowserVersion {4 private final String name;5 private final String version;6 public BrowserVersion(String browserName, String browserVersion) {7 this.name = browserName;8 this.version = browserVersion;9 }10 public BrowserVersion(DesiredCapabilities caps) {11 this(caps.getBrowserName(), caps.getVersion());12 }13 public String getName() {14 return name;15 }16 public String getVersion() {17 return version;18 }19 public String toString() {20 return "BrowserVersion{" +21 '}';22 }23}24package ru.qatools.gridrouter.sessions;25import org.openqa.selenium.remote.DesiredCapabilities;26import java.util.ArrayList;27import java.util.List;28public class Browser {29 private final String name;30 private final List<BrowserVersion> versions;31 public Browser(String browserName, List<BrowserVersion> versions) {32 this.name = browserName;33 this.versions = versions;34 }35 public Browser(String browserName, String version) {36 this.name = browserName;37 this.versions = new ArrayList<>();38 versions.add(new BrowserVersion(browserName, version));39 }40 public Browser(DesiredCapabilities caps) {41 this(caps.getBrowserName(), caps.getVersion());42 }43 public List<BrowserVersion> getVersions() {44 return versions;45 }46 public String getName() {47 return name;48 }49 public String toString() {50 return "Browser{" +51 '}';52 }53}54package ru.qatools.gridrouter.sessions;55import org.openqa.selenium.remote.DesiredCapabilities;56import java.util.ArrayList;57import java.util.List;58public class Browser {59 private final String name;60 private final List<BrowserVersion> versions;61 public Browser(String browserName, List<BrowserVersion> versions) {62 this.name = browserName;63 this.versions = versions;64 }65 public Browser(String browserName, String version) {
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4public class BrowserVersion {5 public static final String BROWSER_VERSION = "browserVersion";6 private final String browserVersion;7 public BrowserVersion(String browserVersion) {8 this.browserVersion = browserVersion;9 }10 public static BrowserVersion fromCapabilities(DesiredCapabilities caps) {11 return new BrowserVersion(caps.getVersion());12 }13 public String getBrowserVersion() {14 return browserVersion;15 }16 public boolean isCompatibleWith(RemoteWebDriver driver) {17 return getBrowserVersion().equals(driver.getCapabilities().getVersion());18 }19 public boolean isCompatibleWith(BrowserVersion version) {20 return getBrowserVersion().equals(version.getBrowserVersion());21 }22 public String toString() {23 return "BrowserVersion{" +24 '}';25 }26}27package ru.qatools.gridrouter.sessions;28import org.openqa.selenium.remote.DesiredCapabilities;29public class BrowserCapabilities {30 public static final String BROWSER_NAME = "browserName";31 private final String browserName;32 private final BrowserVersion browserVersion;33 public BrowserCapabilities(String browserName, String browserVersion) {34 this.browserName = browserName;35 this.browserVersion = new BrowserVersion(browserVersion);36 }37 public static BrowserCapabilities fromDesiredCapabilities(DesiredCapabilities caps) {38 return new BrowserCapabilities(caps.getBrowserName(), caps.getVersion());39 }40 public String getBrowserName() {41 return browserName;42 }43 public BrowserVersion getBrowserVersion() {44 return browserVersion;45 }46 public String toString() {47 return "BrowserCapabilities{" +48 '}';49 }50}51package ru.qatools.gridrouter.sessions;52import org.openqa.selenium.remote.DesiredCapabilities;53import java.util.HashMap;54import java.util.Map;55public class BrowserCapabilitiesFactory {56 private Map<String, BrowserCapabilities> browserCapabilitiesMap = new HashMap<>();57 public BrowserCapabilitiesFactory() {58 browserCapabilitiesMap.put("
BrowserVersion
Using AI Code Generation
1package ru.qatools.gridrouter.sessions;2import java.io.IOException;3import java.util.HashMap;4import java.util.Map;5import java.util.concurrent.atomic.AtomicInteger;6import org.openqa.grid.common.RegistrationRequest;7import org.openqa.grid.common.SeleniumProtocol;8import org.openqa.grid.internal.Registry;9import org.openqa.grid.internal.TestSession;10import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;11import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;12import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;13import org.openqa.grid.web.Hub;14import org.openqa.selenium.remote.DesiredCapabilities;15public class BrowserVersion {16 public static void main(String[] args) throws IOException, InterruptedException {17 GridHubConfiguration hubConfig = new GridHubConfiguration();18 hubConfig.setPort(4444);19 Hub hub = new Hub(hubConfig);20 hub.start();21 GridNodeConfiguration nodeConfig = new GridNodeConfiguration();22 nodeConfig.setPort(5555);23 nodeConfig.setHost("localhost");24 nodeConfig.setRegister(true);25 nodeConfig.setRegisterCycle(5000);26 nodeConfig.setUnregisterIfStillDownAfter(10000);27 nodeConfig.setDownPollingLimit(2);28 nodeConfig.setCapabilities(29 new DesiredCapabilities[] { new DesiredCapabilities("firefox", "1", null) });30 nodeConfig.setProxy("org.openqa.grid.selenium.proxy.DefaultRemoteProxy");31 RegistrationRequest nodeRequest = new RegistrationRequest(nodeConfig);32 DefaultRemoteProxy proxy = new DefaultRemoteProxy(nodeRequest, Registry.newInstance());33 proxy.startRemoteServer();34 proxy.startPolling();35 Thread.sleep(10000);36 Map<String, Object> requestedCapabilities = new HashMap<String, Object>();37 requestedCapabilities.put("browserName", "firefox");38 requestedCapabilities.put("version", "1");39 TestSession session = hub.getNewSession(requestedCapabilities);40 session.terminateSynchronousFOR_TEST_ONLY();41 proxy.stop();42 hub.stop();43 }44}45package ru.qatools.gridrouter.sessions;46import java.io.IOException;47import java.util.HashMap;48import java.util.Map
BrowserVersion
Using AI Code Generation
1package com.browserstack.browserstack;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.chrome.ChromeDriverService;10import org.openqa.selenium.chrome.ChromeDriverService.Builder;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.CapabilityType;14import org.openqa.selenium.chrome.ChromeOptions;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.By;17import org.openqa.selenium.Keys;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.JavascriptExecutor;20import org.openqa.selenium.support.ui.ExpectedConditions;21import org.openqa.selenium.support.ui.WebDriverWait;22import org.openqa.selenium.support.ui.Select;23import org.openqa.selenium.interactions.Actions;24import org.openqa.selenium.Alert;25import org.openqa.selenium.NoSuchElementException;26import org.openqa.selenium.StaleElementReferenceException;27import org.openqa.selenium.TimeoutException;28import org.openqa.selenium.WebDriverException;29import org.openqa.selenium.support.ui.FluentWait;30import org.openqa.selenium.support.ui.Wait;31import org.openqa.selenium.support.ui.Sleeper;32import java.util.concurrent.TimeUnit;33import java.util.concurrent.atomic.AtomicInteger;34import java.util.function.Function;35import java.util.List;36import java.util.ArrayList;37import java.util.Set;38import java.util.Iterator;39import java.util.HashMap;40import java.util.Map;41import java.util.LinkedHashMap;42import java.util.concurrent.TimeUnit;43import java.util.concurrent.atomic.AtomicInteger;44import java.util.function.Function;45import java.util.List;46import java.util.ArrayList;47import java.util.Set;48import java.util.Iterator;49import java.util.HashMap;50import java.util.Map;51import java.util.LinkedHashMap;52import java.io.File;53import java.io.IOException;54import java.io.InputStream;55import java.io.OutputStream;56import java.io.FileOutputStream;57import java.io.ByteArrayInputStream;58import java.io.ByteArrayOutputStream;59import java.io.FileWriter;60import java.io.BufferedWriter;61import java.io.PrintWriter;62import java.io.BufferedReader;63import java.io.InputStreamReader;64import java.net.URL;65import java.net.HttpURLConnection;66import java.net.MalformedURLException;67import java.net.URLEncoder;68import java.net.URI;69import java.net.URISyntaxException;70import java.util.zip.ZipEntry;71import java.util.zip.ZipInputStream;72import java.util.zip.ZipOutputStream;73import java.util.zip.ZipFile;74import java.util.zip.ZipException;75import java.util.zip.GZIPInputStream;76import java
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!