How to use Interface HasFullPageScreenshot class of org.openqa.selenium.firefox package

Best Selenium code snippet using org.openqa.selenium.firefox.Interface HasFullPageScreenshot

Source:FirefoxDriver.java Github

copy

Full Screen

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.firefox;18import static org.openqa.selenium.remote.CapabilityType.PROXY;19import com.google.common.collect.ImmutableMap;20import org.openqa.selenium.Beta;21import org.openqa.selenium.Capabilities;22import org.openqa.selenium.ImmutableCapabilities;23import org.openqa.selenium.MutableCapabilities;24import org.openqa.selenium.OutputType;25import org.openqa.selenium.PersistentCapabilities;26import org.openqa.selenium.Proxy;27import org.openqa.selenium.WebDriverException;28import org.openqa.selenium.devtools.CdpEndpointFinder;29import org.openqa.selenium.devtools.CdpInfo;30import org.openqa.selenium.devtools.CdpVersionFinder;31import org.openqa.selenium.devtools.Connection;32import org.openqa.selenium.devtools.DevTools;33import org.openqa.selenium.devtools.DevToolsException;34import org.openqa.selenium.devtools.HasDevTools;35import org.openqa.selenium.devtools.noop.NoOpCdpInfo;36import org.openqa.selenium.html5.LocalStorage;37import org.openqa.selenium.html5.SessionStorage;38import org.openqa.selenium.html5.WebStorage;39import org.openqa.selenium.internal.Require;40import org.openqa.selenium.remote.CommandInfo;41import org.openqa.selenium.remote.FileDetector;42import org.openqa.selenium.remote.RemoteWebDriver;43import org.openqa.selenium.remote.RemoteWebDriverBuilder;44import org.openqa.selenium.remote.html5.RemoteWebStorage;45import org.openqa.selenium.remote.http.ClientConfig;46import org.openqa.selenium.remote.http.HttpClient;47import org.openqa.selenium.remote.service.DriverCommandExecutor;48import org.openqa.selenium.remote.service.DriverService;49import java.net.URI;50import java.nio.file.Path;51import java.util.Map;52import java.util.Optional;53/**54 * An implementation of the {#link WebDriver} interface that drives Firefox.55 * <p>56 * The best way to construct a {@code FirefoxDriver} with various options is to make use of the57 * {@link FirefoxOptions}, like so:58 *59 * <pre>60 * FirefoxOptions options = new FirefoxOptions()61 * .addPreference("browser.startup.page", 1)62 * .addPreference("browser.startup.homepage", "https://www.google.co.uk")63 * .setAcceptInsecureCerts(true)64 * .setHeadless(true);65 * WebDriver driver = new FirefoxDriver(options);66 * </pre>67 */68public class FirefoxDriver extends RemoteWebDriver69 implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasDevTools {70 private final Capabilities capabilities;71 private final RemoteWebStorage webStorage;72 private final HasExtensions extensions;73 private final HasFullPageScreenshot fullPageScreenshot;74 private final HasContext context;75 private final Optional<URI> cdpUri;76 protected FirefoxBinary binary;77 private DevTools devTools;78 public FirefoxDriver() {79 this(new FirefoxOptions());80 }81 /**82 * @deprecated Use {@link #FirefoxDriver(FirefoxOptions)}.83 */84 @Deprecated85 public FirefoxDriver(Capabilities desiredCapabilities) {86 this(new FirefoxOptions(Require.nonNull("Capabilities", desiredCapabilities)));87 }88 /**89 * @deprecated Use {@link #FirefoxDriver(FirefoxDriverService, FirefoxOptions)}.90 */91 @Deprecated92 public FirefoxDriver(FirefoxDriverService service, Capabilities desiredCapabilities) {93 this(94 Require.nonNull("Driver service", service),95 new FirefoxOptions(desiredCapabilities));96 }97 public FirefoxDriver(FirefoxOptions options) {98 this(new FirefoxDriverCommandExecutor(GeckoDriverService.createDefaultService()), options);99 }100 public FirefoxDriver(FirefoxDriverService service) {101 this(service, new FirefoxOptions());102 }103 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) {104 this(new FirefoxDriverCommandExecutor(service), options);105 }106 private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) {107 super(executor, checkCapabilitiesAndProxy(options));108 webStorage = new RemoteWebStorage(getExecuteMethod());109 extensions = new AddHasExtensions().getImplementation(getCapabilities(), getExecuteMethod());110 fullPageScreenshot = new AddHasFullPageScreenshot().getImplementation(getCapabilities(), getExecuteMethod());111 context = new AddHasContext().getImplementation(getCapabilities(), getExecuteMethod());112 Capabilities capabilities = super.getCapabilities();113 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();114 Optional<URI> cdpUri = CdpEndpointFinder.getReportedUri("moz:debuggerAddress", capabilities)115 .flatMap(reported -> CdpEndpointFinder.getCdpEndPoint(clientFactory, reported));116 this.cdpUri = cdpUri;117 this.capabilities = cdpUri.map(uri ->118 new ImmutableCapabilities(119 new PersistentCapabilities(capabilities)120 .setCapability("se:cdp", uri.toString())121 .setCapability("se:cdpVersion", "85.0")))122 .orElse(new ImmutableCapabilities(capabilities));123 }124 @Beta125 public static RemoteWebDriverBuilder builder() {126 return RemoteWebDriver.builder().oneOf(new FirefoxOptions());127 }128 /**129 * Check capabilities and proxy if it is set130 */131 private static Capabilities checkCapabilitiesAndProxy(Capabilities capabilities) {132 if (capabilities == null) {133 return new ImmutableCapabilities();134 }135 MutableCapabilities caps = new MutableCapabilities(capabilities);136 // Ensure that the proxy is in a state fit to be sent to the extension137 Proxy proxy = Proxy.extractFrom(capabilities);138 if (proxy != null) {139 caps.setCapability(PROXY, proxy);140 }141 return caps;142 }143 @Override144 public Capabilities getCapabilities() {145 return capabilities;146 }147 @Override148 public void setFileDetector(FileDetector detector) {149 throw new WebDriverException(150 "Setting the file detector only works on remote webdriver instances obtained " +151 "via RemoteWebDriver");152 }153 @Override154 public LocalStorage getLocalStorage() {155 return webStorage.getLocalStorage();156 }157 @Override158 public SessionStorage getSessionStorage() {159 return webStorage.getSessionStorage();160 }161 @Override162 public String installExtension(Path path) {163 Require.nonNull("Path", path);164 return extensions.installExtension(path);165 }166 @Override167 public String installExtension(Path path, Boolean temporary) {168 Require.nonNull("Path", path);169 Require.nonNull("Temporary", temporary);170 return extensions.installExtension(path, temporary);171 }172 @Override173 public void uninstallExtension(String extensionId) {174 Require.nonNull("Extension ID", extensionId);175 extensions.uninstallExtension(extensionId);176 }177 /**178 * Capture the full page screenshot and store it in the specified location.179 *180 * @param <X> Return type for getFullPageScreenshotAs.181 * @param outputType target type, @see OutputType182 * @return Object in which is stored information about the screenshot.183 * @throws WebDriverException on failure.184 */185 @Override186 public <X> X getFullPageScreenshotAs(OutputType<X> outputType) throws WebDriverException {187 Require.nonNull("OutputType", outputType);188 return fullPageScreenshot.getFullPageScreenshotAs(outputType);189 }190 @Override191 public FirefoxCommandContext getContext() {192 return context.getContext();193 }194 @Override195 public void setContext(FirefoxCommandContext commandContext) {196 Require.nonNull("Firefox Command Context", commandContext);197 context.setContext(commandContext);198 }199 @Override200 public Optional<DevTools> maybeGetDevTools() {201 if (devTools != null) {202 return Optional.of(devTools);203 }204 if (!cdpUri.isPresent()) {205 return Optional.empty();206 }207 URI wsUri = cdpUri.orElseThrow(() ->208 new DevToolsException("This version of Firefox or geckodriver does not support CDP"));209 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();210 ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);211 HttpClient wsClient = clientFactory.createClient(wsConfig);212 Connection connection = new Connection(wsClient, wsUri.toString());213 CdpInfo cdpInfo = new CdpVersionFinder().match("85.0").orElseGet(NoOpCdpInfo::new);214 devTools = new DevTools(cdpInfo::getDomains, connection);215 return Optional.of(devTools);216 }217 @Override218 public DevTools getDevTools() {219 if (!cdpUri.isPresent()) {220 throw new DevToolsException("This version of Firefox or geckodriver does not support CDP");221 }222 return maybeGetDevTools()223 .orElseThrow(() -> new DevToolsException("Unable to initialize CDP connection"));224 }225 public static final class SystemProperty {226 /**227 * System property that defines the location of the Firefox executable file.228 */229 public static final String BROWSER_BINARY = "webdriver.firefox.bin";230 /**231 * System property that defines the location of the file where Firefox log should be stored.232 */233 public static final String BROWSER_LOGFILE = "webdriver.firefox.logfile";234 /**235 * System property that defines the profile that should be used as a template.236 * When the driver starts, it will make a copy of the profile it is using,237 * rather than using that profile directly.238 */239 public static final String BROWSER_PROFILE = "webdriver.firefox.profile";240 }241 public static final class Capability {242 public static final String BINARY = "firefox_binary";243 public static final String PROFILE = "firefox_profile";244 public static final String MARIONETTE = "marionette";245 }246 private static class FirefoxDriverCommandExecutor extends DriverCommandExecutor {247 public FirefoxDriverCommandExecutor(DriverService service) {248 super(service, getExtraCommands());249 }250 private static Map<String, CommandInfo> getExtraCommands() {251 return ImmutableMap.<String, CommandInfo>builder()252 .putAll(new AddHasContext().getAdditionalCommands())253 .putAll(new AddHasExtensions().getAdditionalCommands())254 .putAll(new AddHasFullPageScreenshot().getAdditionalCommands())255 .build();256 }257 }258}...

Full Screen

Full Screen

Source:AddHasFullPageScreenshot.java Github

copy

Full Screen

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.firefox;18import com.google.auto.service.AutoService;19import com.google.common.collect.ImmutableMap;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.OutputType;22import org.openqa.selenium.internal.Require;23import org.openqa.selenium.remote.AdditionalHttpCommands;24import org.openqa.selenium.remote.AugmenterProvider;25import org.openqa.selenium.remote.CommandInfo;26import org.openqa.selenium.remote.ExecuteMethod;27import org.openqa.selenium.remote.http.HttpMethod;28import java.util.Map;29import java.util.function.Predicate;30import static org.openqa.selenium.remote.Browser.FIREFOX;31@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})32public class AddHasFullPageScreenshot<X> implements AugmenterProvider<HasFullPageScreenshot>, AdditionalHttpCommands {33 public static final String FULL_PAGE_SCREENSHOT = "fullPageScreenshot";34 private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of(35 FULL_PAGE_SCREENSHOT, new CommandInfo("/session/:sessionId/moz/screenshot/full", HttpMethod.GET));36 @Override37 public Map<String, CommandInfo> getAdditionalCommands() {38 return COMMANDS;39 }40 @Override41 public Predicate<Capabilities> isApplicable() {42 return FIREFOX::is;43 }44 @Override45 public Class<HasFullPageScreenshot> getDescribedInterface() {46 return HasFullPageScreenshot.class;47 }48 @Override49 public HasFullPageScreenshot getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {50 return new HasFullPageScreenshot() {51 @Override52 public <X> X getFullPageScreenshotAs(OutputType<X> outputType) {53 Require.nonNull("Output Type", outputType);54 Object result = executeMethod.execute(FULL_PAGE_SCREENSHOT, null);55 if (result instanceof String) {56 String base64EncodedPng = (String) result;57 return outputType.convertFromBase64Png(base64EncodedPng);58 } else if (result instanceof byte[]) {59 return outputType.convertFromPngBytes((byte[]) result);60 } else {61 throw new RuntimeException(String.format(62 "Unexpected result for %s command: %s",63 FULL_PAGE_SCREENSHOT,64 result == null ? "null" : result.getClass().getName() + " instance"));65 }66 }67 };68 }69}...

Full Screen

Full Screen

Source:HasFullPageScreenshot.java Github

copy

Full Screen

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.firefox;18import org.openqa.selenium.Beta;19import org.openqa.selenium.OutputType;20/**21 * Used by classes to indicate that they can take a full page screenshot.22 */23@Beta24public interface HasFullPageScreenshot {25 /**26 * Capture the full page screenshot and store it in the specified location.27 *28 * @param outputType target type, @see OutputType29 * @return Object in which is stored information about the screenshot.30 */31 <X> X getFullPageScreenshotAs(OutputType<X> outputType);32}...

Full Screen

Full Screen

Interface HasFullPageScreenshot

Using AI Code Generation

copy

Full Screen

1public class FullPageScreenShot implements HasFullPageScreenshot {2public class FullPageScreenShot implements TakesScreenshot {3public class FullPageScreenShot implements WebDriver {4public class FullPageScreenShot implements TakesScreenshot {5[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ FullPageScreenShot ---6[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ FullPageScreenShot ---7[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ FullPageScreenShot ---

Full Screen

Full Screen

Interface HasFullPageScreenshot

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.HasFullPageScreenshot;3import org.openqa.selenium.OutputType;4import org.openqa.selenium.TakesScreenshot;5import org.openqa.selenium.WebDriver;6import java.io.File;7import org.apache.commons.io.FileUtils;8public class FullPageScreenshot {9 public static void main(String[] args) {10 System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");11 WebDriver driver = new FirefoxDriver();12 HasFullPageScreenshot screenshot = (HasFullPageScreenshot)driver;13 TakesScreenshot screenshot1 = (TakesScreenshot)driver;14 File source = screenshot.getScreenshotAs(OutputType.FILE);15 File source1 = screenshot1.getScreenshotAs(OutputType.FILE);16 try {17 FileUtils.copyFile(source, new File("C:\\Users\\DELL\\Desktop\\FullPageScreenshot.png"));18 FileUtils.copyFile(source1, new File("C:\\Users\\DELL\\Desktop\\Screenshot.png"));19 }20 catch(Exception e)21 {22 System.out.println(e.getMessage());23 }24 driver.close();25 }26}

Full Screen

Full Screen

Interface HasFullPageScreenshot

Using AI Code Generation

copy

Full Screen

1package com.selenium4beginners.selenium_tutorials.ci;2import java.io.File;3import org.openqa.selenium.By;4import org.openqa.selenium.OutputType;5import org.openqa.selenium.TakesScreenshot;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.firefox.FirefoxOptions;10import org.openqa.selenium.firefox.FirefoxProfile;11import org.openqa.selenium.internal.WrapsDriver;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14import com.google.common.io.Files;15public class FF_Screenshot_FullPage {16 public static void main(String[] args) throws InterruptedException {17 FirefoxProfile profile = new FirefoxProfile();18 profile.setPreference("extensions.screenshots.disabled", true);19 profile.setPreference("extensions.screenshots.system-disabled", true);20 FirefoxOptions options = new FirefoxOptions();21 options.setProfile(profile);22 WebDriver driver = new FirefoxDriver(options);23 WebDriverWait wait = new WebDriverWait(driver, 10);24 wait.until(ExpectedConditions.visibilityOf(downloadButton));25 downloadButton.click();26 wait.until(ExpectedConditions.visibilityOf(downloadPage));27 File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);28 Files.copy(screenshot, new File("src/test/resources/screenshot.png"));29 File screenshot1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);30 Files.copy(screenshot1, new File("src/test/resources/screenshot1.png"));31 driver.quit();32 }33}

Full Screen

Full Screen

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

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

Most used methods in Interface-HasFullPageScreenshot

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