Best Selenium code snippet using org.openqa.selenium.grid.data.Session.getStereotype
Source:GridModel.java
...240 }241 if (id.equals(slot.getSession().get().getId())) {242 Slot released = new Slot(243 slot.getId(),244 slot.getStereotype(),245 slot.getLastStarted(),246 Optional.empty());247 amend(entry.getKey(), node, released);248 return;249 }250 }251 }252 }253 } finally {254 writeLock.unlock();255 }256 }257 private void reserve(NodeStatus status, Slot slot) {258 Instant now = Instant.now();259 Slot reserved = new Slot(260 slot.getId(),261 slot.getStereotype(),262 now,263 Optional.of(new Session(264 RESERVED,265 status.getUri(),266 slot.getStereotype(),267 slot.getStereotype(),268 now)));269 amend(UP, status, reserved);270 }271 public void setSession(SlotId slotId, Session session) {272 Require.nonNull("Slot ID", slotId);273 AvailabilityAndNode node = findNode(slotId.getOwningNodeId());274 if (node == null) {275 LOG.warning("Grid model and reality have diverged. Unable to find node " + slotId.getOwningNodeId());276 return;277 }278 Optional<Slot> maybeSlot = node.status.getSlots().stream()279 .filter(slot -> slotId.equals(slot.getId()))280 .findFirst();281 if (!maybeSlot.isPresent()) {282 LOG.warning("Grid model and reality have diverged. Unable to find slot " + slotId);283 return;284 }285 Slot slot = maybeSlot.get();286 Optional<Session> maybeSession = slot.getSession();287 if (!maybeSession.isPresent()) {288 LOG.warning("Grid model and reality have diverged. Slot is not reserved. " + slotId);289 return;290 }291 Session current = maybeSession.get();292 if (!RESERVED.equals(current.getId())) {293 LOG.warning("Gid model and reality have diverged. Slot has session and is not reserved. " + slotId);294 return;295 }296 Slot updated = new Slot(297 slot.getId(),298 slot.getStereotype(),299 session == null ? slot.getLastStarted() : session.getStartTime(),300 Optional.ofNullable(session));301 amend(node.availability, node.status, updated);302 }303 private void amend(Availability availability, NodeStatus status, Slot slot) {304 Set<Slot> newSlots = new HashSet<>(status.getSlots());305 newSlots.removeIf(s -> s.getId().equals(slot.getId()));306 newSlots.add(slot);307 nodes(availability).remove(status);308 nodes(availability).add(new NodeStatus(309 status.getId(),310 status.getUri(),311 status.getMaxSessionCount(),312 newSlots,...
Source:Host.java
...96 Lock writeLock = lock.writeLock();97 writeLock.lock();98 try {99 this.slots = status.getSlots().stream()100 .map(slot -> new Slot(node, slot.getStereotype(), slot.getSession().isPresent() ? ACTIVE : AVAILABLE))101 .collect(toImmutableSet());102 // By definition, we can never have more sessions than we have slots available103 this.maxSessionCount = Math.min(this.slots.size(), status.getMaxSessionCount());104 } finally {105 writeLock.unlock();106 }107 }108 public NodeId getId() {109 return nodeId;110 }111 public DistributorStatus.NodeSummary asSummary() {112 Map<Capabilities, Integer> stereotypes = new HashMap<>();113 Map<Capabilities, Integer> used = new HashMap<>();114 Set<Session> activeSessions = new HashSet<>();115 slots.forEach(slot -> {116 stereotypes.compute(slot.getStereotype(), (key, curr) -> curr == null ? 1 : curr + 1);117 if (slot.getStatus() != AVAILABLE) {118 used.compute(slot.getStereotype(), (key, curr) -> curr == null ? 1 : curr + 1);119 activeSessions.add(slot.getCurrentSession());120 }121 });122 return new DistributorStatus.NodeSummary(123 nodeId,124 uri,125 getHostStatus(),126 maxSessionCount,127 stereotypes,128 used,129 activeSessions);130 }131 public Availability getHostStatus() {132 return status;...
Source:Grid.java
...48 Map<Capabilities, Integer> capabilities = new HashMap<>();49 Set<org.openqa.selenium.grid.data.Session> sessions = new HashSet<>();50 for (Slot slot : status.getSlots()) {51 slot.getSession().ifPresent(sessions::add);52 int count = capabilities.getOrDefault(slot.getStereotype(), 0);53 count++;54 capabilities.put(slot.getStereotype(), count);55 }56 toReturn.add(new Node(57 status.getId(),58 status.getUri(),59 status.getAvailability(),60 status.getMaxSessionCount(),61 capabilities,62 sessions));63 }64 return toReturn.build();65 }66 public int getSessionCount() {67 return distributorStatus.get().getNodes().stream()68 .map(NodeStatus::getSlots)...
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!