Best Selenium code snippet using org.openqa.selenium.internal.Require.argument
Source:OpenTelemetryPropagator.java
...36 public <C> void inject(TraceContext toInject, C carrier, Setter<C> setter) {37 Require.nonNull("Trace context to inject to", toInject);38 Require.nonNull("Carrier", carrier);39 Require.nonNull("Setter", setter);40 Require.argument("Trace context", toInject).instanceOf(OpenTelemetryContext.class);41 httpTextFormat.inject(42 ((OpenTelemetryContext) toInject).getContext(), carrier, setter::set);43 }44 @Override45 public <C> OpenTelemetryContext extractContext(46 TraceContext existing, C carrier, BiFunction<C, String, String> getter) {47 Require.nonNull("Trace context to extract from", existing);48 Require.nonNull("Carrier", carrier);49 Require.nonNull("Getter", getter);50 Require.argument("Trace context", existing).instanceOf(OpenTelemetryContext.class);51 Context extracted =52 httpTextFormat.extract(53 ((OpenTelemetryContext) existing).getContext(), carrier, getter::apply);54 // If the extracted context is the root context, then we continue to be a55 // child span of the existing context.56 SpanId id = TracingContextUtils.getSpan(extracted).getContext().getSpanId();57 if (DefaultSpan.getInvalid().getContext().getSpanId().equals(id)) {58 return (OpenTelemetryContext) existing;59 }60 return new OpenTelemetryContext(tracer, extracted);61 }62}...
Source:Status.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.remote.tracing;18import org.openqa.selenium.internal.Require;19public class Status {20 private final Kind kind;21 private final String description;22 public static final Status OK = new Status(Kind.OK, "");23 public static final Status ABORTED = new Status(Kind.ABORTED, "");24 public static final Status CANCELLED = new Status(Kind.CANCELLED, "");25 public static final Status NOT_FOUND = new Status(Kind.NOT_FOUND, "");26 public static final Status RESOURCE_EXHAUSTED = new Status(Kind.RESOURCE_EXHAUSTED, "");27 public static final Status UNKNOWN = new Status(Kind.UNKNOWN, "");28 public static final Status INVALID_ARGUMENT = new Status(Kind.INVALID_ARGUMENT, "");29 public static final Status DEADLINE_EXCEEDED = new Status(Kind.DEADLINE_EXCEEDED, "");30 public static final Status ALREADY_EXISTS = new Status(Kind.ALREADY_EXISTS, "");31 public static final Status PERMISSION_DENIED = new Status(Kind.PERMISSION_DENIED, "");32 public static final Status OUT_OF_RANGE = new Status(Kind.OUT_OF_RANGE, "");33 public static final Status UNIMPLEMENTED = new Status(Kind.UNIMPLEMENTED, "");34 public static final Status INTERNAL = new Status(Kind.INTERNAL, "");35 public static final Status UNAVAILABLE = new Status(Kind.UNAVAILABLE, "");36 public static final Status UNAUTHENTICATED = new Status(Kind.UNAUTHENTICATED, "");37 private Status(Kind kind, String description) {38 this.kind = Require.nonNull("Kind", kind);39 this.description = Require.nonNull("Description", description);40 }41 public Status withDescription(String description) {42 return new Status(getKind(), Require.nonNull("Description", description));43 }44 public Kind getKind() {45 return kind;46 }47 public String getDescription() {48 return description;49 }50 public enum Kind {51 OK,52 ABORTED,53 CANCELLED,54 NOT_FOUND,55 RESOURCE_EXHAUSTED,56 UNKNOWN,57 INVALID_ARGUMENT,58 DEADLINE_EXCEEDED,59 ALREADY_EXISTS,60 PERMISSION_DENIED,61 OUT_OF_RANGE,62 UNIMPLEMENTED,63 INTERNAL,64 UNAVAILABLE,65 UNAUTHENTICATED66 }67}...
Source:BaseActiveSession.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.node;18import org.openqa.selenium.Capabilities;19import org.openqa.selenium.ImmutableCapabilities;20import org.openqa.selenium.grid.data.Session;21import org.openqa.selenium.internal.Require;22import org.openqa.selenium.remote.Dialect;23import org.openqa.selenium.remote.SessionId;24import java.net.URI;25import java.net.URISyntaxException;26import java.net.URL;27import java.time.Instant;28public abstract class BaseActiveSession implements ActiveSession {29 private final Session session;30 private final Dialect downstream;31 private final Dialect upstream;32 protected BaseActiveSession(33 SessionId id,34 URL url,35 Dialect downstream,36 Dialect upstream,37 Capabilities stereotype,38 Capabilities capabilities,39 Instant startTime) {40 URI uri;41 try {42 uri = Require.nonNull("URL", url).toURI();43 } catch (URISyntaxException e) {44 throw new IllegalArgumentException(e);45 }46 this.session = new Session(47 Require.nonNull("Session id", id),48 uri,49 ImmutableCapabilities.copyOf(Require.nonNull("Stereotype", stereotype)),50 ImmutableCapabilities.copyOf(Require.nonNull("Capabilities", capabilities)),51 Require.nonNull("Start time", startTime));52 this.downstream = Require.nonNull("Downstream dialect", downstream);53 this.upstream = Require.nonNull("Upstream dialect", upstream);54 }55 @Override56 public SessionId getId() {57 return session.getId();58 }59 @Override60 public Capabilities getStereotype() {61 return session.getStereotype();62 }63 @Override64 public Capabilities getCapabilities() {65 return session.getCapabilities();66 }67 @Override68 public Instant getStartTime() {69 return session.getStartTime();70 }71 @Override72 public URI getUri() {73 return session.getUri();74 }75 @Override76 public Dialect getUpstreamDialect() {77 return upstream;78 }79 @Override80 public Dialect getDownstreamDialect() {81 return downstream;82 }83 public Session asSession() {84 return session;85 }86}...
Source:CollectionCoercer.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.json;18import org.openqa.selenium.internal.Require;19import java.lang.reflect.ParameterizedType;20import java.lang.reflect.Type;21import java.util.Collection;22import java.util.function.BiFunction;23import java.util.stream.Collector;24public class CollectionCoercer<T extends Collection> extends TypeCoercer<T> {25 private final Class<T> stereotype;26 private final JsonTypeCoercer coercer;27 private final Collector<Object, ?, ? extends T> collector;28 public CollectionCoercer(29 Class<T> stereotype,30 JsonTypeCoercer coercer,31 Collector<Object, ?, T> collector) {32 this.stereotype = Require.nonNull("Stereotype", stereotype);33 this.coercer = Require.nonNull("Coercer", coercer);34 this.collector = Require.nonNull("Collector", collector);35 }36 @Override37 public boolean test(Class<?> aClass) {38 return stereotype.isAssignableFrom(aClass);39 }40 @Override41 public BiFunction<JsonInput, PropertySetting, T> apply(Type type) {42 Type valueType;43 if (type instanceof ParameterizedType) {44 ParameterizedType pt = (ParameterizedType) type;45 valueType = pt.getActualTypeArguments()[0];46 } else if (type instanceof Class) {47 valueType = Object.class;48 } else {49 throw new IllegalArgumentException("Unhandled type: " + type.getClass());50 }51 return (jsonInput, setting) -> {52 jsonInput.beginArray();53 T toReturn = new JsonInputIterator(jsonInput).asStream()54 .map(in -> coercer.coerce(in, valueType, setting))55 .collect(collector);56 jsonInput.endArray();57 return toReturn;58 };59 }60}...
Source:WrappedPrintWriter.java
...29 this(new OutputStreamWriter(out, Charset.defaultCharset()), lineLength, indentBy);30 }31 public WrappedPrintWriter(Writer out, int lineLength, int indentBy) {32 super(out);33 this.lineLength = Require.argument("Line length", lineLength).greaterThan(9, "Lines must be 10 or more characters");34 this.indentBy = Require.nonNegative("An indent", indentBy);35 }36 @Override37 public void write(int c) {38 if (c == '\n') {39 super.write(c);40 position = 0;41 } else if (position > lineLength && Character.isWhitespace(c)) {42 super.write('\n');43 for (int i = 0; i < indentBy; i++) {44 super.write(' ');45 }46 position = indentBy;47 return;...
Source:ClassPathResource.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.web;18import org.openqa.selenium.internal.Require;19import java.io.IOException;20import java.io.UncheckedIOException;21import java.net.JarURLConnection;22import java.net.URL;23import java.util.Optional;24import java.util.Set;25import java.util.jar.JarFile;26public class ClassPathResource implements Resource {27 private final Resource delegate;28 public ClassPathResource(URL resourceUrl, String stripPrefix) {29 Require.nonNull("Resource URL", resourceUrl);30 Require.nonNull("Prefix to strip", stripPrefix);31 if ("jar".equals(resourceUrl.getProtocol())) {32 try {33 JarURLConnection juc = (JarURLConnection) resourceUrl.openConnection();34 JarFile jarFile = juc.getJarFile();35 this.delegate = new JarFileResource(jarFile, juc.getEntryName(), stripPrefix);36 } catch (IOException e) {37 throw new UncheckedIOException(e);38 }39 } else {40 throw new IllegalArgumentException("Unable to handle scheme of type " + resourceUrl.getProtocol());41 }42 }43 @Override44 public String name() {45 return delegate.name();46 }47 @Override48 public Optional<Resource> get(String path) {49 Require.nonNull("Path", path);50 return delegate.get(path);51 }52 @Override53 public boolean isDirectory() {54 return delegate.isDirectory();55 }56 @Override57 public Set<Resource> list() {58 return delegate.list();59 }60 @Override61 public Optional<byte[]> read() {62 return delegate.read();63 }64}...
Source:CompositeAction.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.interactions;18import org.openqa.selenium.internal.Require;19import java.util.ArrayList;20import java.util.Collections;21import java.util.List;22/**23 * An action for aggregating actions and triggering all of them at the same time.24 *25 */26public class CompositeAction implements Action, IsInteraction {27 private final List<Action> actionsList = new ArrayList<>();28 @Override29 public void perform() {30 for (Action action : actionsList) {31 action.perform();32 }33 }34 public CompositeAction addAction(Action action) {35 actionsList.add(Require.nonNull("Action", action));36 return this;37 }38 /**39 * @deprecated No replacement.40 */41 //VisibleForTesting42 @Deprecated43 int getNumberOfActions() {44 return actionsList.size();45 }46 @Override47 public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {48 List<Interaction> interactions = new ArrayList<>();49 for (Action action : actionsList) {50 if (!(action instanceof IsInteraction)) {51 throw new IllegalArgumentException(52 String.format("Action must implement IsInteraction: %s", action));53 }54 interactions.addAll(((IsInteraction) action).asInteractions(mouse, keyboard));55 }56 return Collections.unmodifiableList(interactions);57 }58}...
argument
Using AI Code Generation
1import java.util.List;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6public class SeleniumTest {7 public static void main(String[] args) {8 WebDriver driver = new ChromeDriver();9 WebElement searchBox = driver.findElement(By.name("q"));10 searchBox.sendKeys("Selenium");11 searchBox.submit();12 System.out.println(searchResults.size());13 for(WebElement result : searchResults) {14 System.out.println(result.getText());15 }16 driver.close();17 }18}19public static <T> T argumentNotNull(T arg, String argName)20public static <T> T argumentNotNull(T arg, String argName, String message)21public static <T> T argumentNotNull(T arg, String argName, String message, Object... args)22public static <T> T argumentNotNull(T arg, String argName, Throwable cause)23public static <T> T argumentNotNull(T arg, String argName, Throwable cause, String message, Object... args)24public static void argument(boolean condition, String message, Object... args)25public static void argument(boolean condition, Throwable cause, String message, Object... args)26public static void argument(boolean condition, String message)27public static void argument(boolean condition, Throwable cause, String message)28public static void argument(boolean condition, Throwable cause)29public static void argument(boolean condition)30public static void argument(boolean condition, String message, Throwable cause)31public static void argument(boolean condition, String message, Object[] args, Throwable cause)32public static boolean isNotNull(Object arg)
argument
Using AI Code Generation
1import org.openqa.selenium.internal.Require;2public class RequireTest {3public static void main(String[] args) {4Require.nonNull("Test", null);5}6}7at org.openqa.selenium.internal.Require.nonNull(Require.java:43)8at RequireTest.main(RequireTest.java:8)9import org.openqa.selenium.internal.Require;10public class RequireTest {11public static void main(String[] args) {12Require.nonNull("Test", "test");13}14}15import org.openqa.selenium.internal.Require;16public class RequireTest {17public static void main(String[] args) {18Require.nonEmpty("Test", "test");19}20}21import org.openqa.selenium.internal.Require;22public class RequireTest {23public static void main(String[] args) {24Require.nonEmpty("Test", "");25}26}27at org.openqa.selenium.internal.Require.nonEmpty(Require.java:53)28at RequireTest.main(RequireTest.java:8)29import org.openqa.selenium.internal.Require;30public class RequireTest {31public static void main(String[] args) {32Require.nonEmpty("Test", " ");33}34}35at org.openqa.selenium.internal.Require.nonEmpty(Require.java:53)36at RequireTest.main(RequireTest.java:8)37import org.openqa.selenium.internal.Require;
argument
Using AI Code Generation
1package org.openqa.selenium.internal;2public class Require {3 private Require() {4 }5 public static void nonNull(String name, Object value) {6 if (value == null) {7 throw new NullPointerException(8 String.format("You must provide a value for %s", name));9 }10 }11}12package org.openqa.selenium.internal;13import org.junit.Test;14import static org.junit.Assert.fail;15public class RequireTest {16 public void nonNullShouldThrowExceptionIfArgumentIsNull() {17 try {18 Require.nonNull("foo", null);19 fail("Should have thrown");20 } catch (NullPointerException e) {21 }22 }23}24package org.openqa.selenium.internal;25import org.junit.Test;26import static org.junit.Assert.fail;27public class RequireTest {28 public void nonNullShouldNotThrowExceptionIfArgumentIsNotNull() {29 Require.nonNull("foo", "bar");30 }31}32package org.openqa.selenium.internal;33import org.junit.Test;34import static org.junit.Assert.fail;35public class RequireTest {36 public void nonNullShouldThrowExceptionIfArgumentIsNull() {37 try {38 Require.nonNull("foo", null);39 fail("Should have thrown");40 } catch (NullPointerException e) {41 }42 }43 public void nonNullShouldNotThrowExceptionIfArgumentIsNotNull() {44 Require.nonNull("foo", "bar");45 }46}47package org.openqa.selenium.internal;48import org.junit.Test;49import static org.junit.Assert.fail;50public class RequireTest {51 public void nonNullShouldThrowExceptionIfArgumentIsNull() {52 try {53 Require.nonNull("foo", null);54 fail("Should have thrown");55 } catch (NullPointerException e) {56 }57 }58 public void nonNullShouldNotThrowExceptionIfArgumentIsNotNull() {59 Require.nonNull("foo", "bar");60 }61}62package org.openqa.selenium.internal;63import org.junit.Test;64import static org.junit.Assert.fail;65public class RequireTest {
argument
Using AI Code Generation
1 Require.nonNull("Element", element);2 Require.nonNull("Locator", locator);3 Require.nonNull("Driver", driver);4 Require.nonNull("Timeout", timeout);5 Require.nonNull("TimeUnit", unit);6 Argument nonNullElement = Argument.nonNull("Element", element);7 Argument nonNullLocator = Argument.nonNull("Locator", locator);8 Argument nonNullDriver = Argument.nonNull("Driver", driver);9 Argument nonNullTimeout = Argument.nonNull("Timeout", timeout);10 Argument nonNullUnit = Argument.nonNull("TimeUnit", unit);11 Require.nonNull("Element", element);12 Require.nonNull("Locator", locator);13 Require.nonNull("Driver", driver);14 Require.nonNull("Timeout", timeout);15 Require.nonNull("TimeUnit", unit);16 Argument nonNullElement = Argument.nonNull("Element", element);17 Argument nonNullLocator = Argument.nonNull("Locator", locator);18 Argument nonNullDriver = Argument.nonNull("Driver", driver);19 Argument nonNullTimeout = Argument.nonNull("Timeout", timeout);20 Argument nonNullUnit = Argument.nonNull("TimeUnit", unit);21 Require.nonNull("Element", element);22 Require.nonNull("Locator", locator);23 Require.nonNull("Driver", driver);24 Require.nonNull("Timeout", timeout);25 Require.nonNull("TimeUnit", unit);26 Argument nonNullElement = Argument.nonNull("Element", element);27 Argument nonNullLocator = Argument.nonNull("Locator", locator);28 Argument nonNullDriver = Argument.nonNull("Driver", driver);29 Argument nonNullTimeout = Argument.nonNull("Timeout", timeout);30 Argument nonNullUnit = Argument.nonNull("TimeUnit", unit);31 Require.nonNull("Element", element);32 Require.nonNull("Locator", locator);33 Require.nonNull("Driver", driver);34 Require.nonNull("Timeout", timeout);35 Require.nonNull("TimeUnit", unit);
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!!