Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting black spot on the Chrome - Tablet Emulator screenshot while Capturing the entire page #71

Closed
seliniumtester opened this issue May 26, 2016 · 12 comments
Labels

Comments

@seliniumtester
Copy link

Getting black spot on the Chrome-Tablet emulator screenshot while Capturing the entire page by using
new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(webDriver);

Same works fine for Chrome- Phone emulator.

Please provide resolution for this issue.

Here is the code.
String baseUrl = "https://github.com/yandex-qatools/ashot";

    Map<String, String> mobileEmulation = new HashMap<String, String>();
    mobileEmulation.put("deviceName", "Apple iPad");
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("mobileEmulation", mobileEmulation);
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    WebDriver driver = new ChromeDriver(capabilities);
    driver.manage().window().maximize();

    driver.get(baseUrl);

    final Screenshot screenshot = new AShot()
              .shootingStrategy(ShootingStrategies.viewportPasting(100))
              .takeScreenshot(driver);

    final BufferedImage image = screenshot.getImage();
    ImageIO.write(image, "PNG", new File("C:\\Selenium\\"+ "Ahot-Tablet.png"));

Tablet Screenshot:
ahot-tablet

Phone Screenshot:
ahot-phone

@pazone
Copy link
Owner

pazone commented May 26, 2016

Hello. It looks like your phone emulator has dpr = 1, but tablet has dpr > 1. You should set it in shooting strategy.

Try to use

new AShot().shootindStrategy(ShootingStrategies.viewportRetina(100, 0, 0, <yourDpr>));

@seliniumtester
Copy link
Author

Hi, Thanks for the suggestion. I have tried the same with the below code,
final Screenshot screenshot = new AShot()
.shootingStrategy(ShootingStrategies.viewportRetina(100, 0, 0, 2))
.takeScreenshot(driver);

Now, i am getting more black area. Please advice.

Screenshot:
1-login1

@pazone
Copy link
Owner

pazone commented May 26, 2016

As I understood, you are using build in Chrome tools to emulate tablet. Are you using Chrome's presets for it or custom capabilities? Which kind of tablet you want to emulate? Can you show me how are you doing it?

@seliniumtester
Copy link
Author

Hi, yes i am using the build in Chrome emulator. I am using the below custom capability provided in the chromedriver.exe. I am trying to emulate Apple iPad device.

Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Apple iPad");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);

@pazone
Copy link
Owner

pazone commented May 26, 2016

Consider this code string deviceMetrics.put("pixelRatio", 3.0); here . You are using preset with unknown pixel ratio.
Add this to your caps: deviceMetrics.put("pixelRatio", 1.0); - it will make your emulation screenshotable :) Also avoid to launch webdriver on displays with DPR != 1. For example mac book with retina. You can do it but you should calculate your result DPR. It can be hard sometimes.

@seliniumtester
Copy link
Author

seliniumtester commented May 27, 2016

Hi, I have added the capability as per your suggestion. Still, i am getting this issue. Please advice.

Please find the code below.

Browser Setup:

code

AShot:

    final Screenshot screenshot = new AShot()
          .shootingStrategy(ShootingStrategies.viewportPasting(100))
        .takeScreenshot(driver);

or
final Screenshot screenshot = new AShot()
.shootingStrategy(ShootingStrategies.viewportRetina(1000, 0, 0, 1))
.takeScreenshot(driver);

Screenshot:
ahot-tablet1

@pazone
Copy link
Owner

pazone commented May 30, 2016

Are you getting this when trying to take screenshot of other page? If you are launching chrome locally I need to know you local dpr, it also can be != 1.

@rovner
Copy link

rovner commented May 30, 2016

It's really looks like a bug for me in viewport_height.js for chrome emulation in portrait mode.
See

//portrait
window.innerHeight
1360 // should be 1024
document.documentElement.clientHeight
1024
//landscape
document.documentElement.clientHeight
768
window.innerHeight
768

@seliniumtester you could workaround your code by using landscape orientation for now

        Map<String, Object> deviceMetrics = new HashMap<>();
        deviceMetrics.put("width", 1024);
        deviceMetrics.put("height", 768);
        deviceMetrics.put("pixelRatio", 1.0);

@pazone pazone self-assigned this May 30, 2016
@pazone pazone added the bug label May 30, 2016
@seliniumtester
Copy link
Author

@pazone yes i am getting this issue in other pages as well. I am having dpr as 1.

@rovner thanks for the suggestion. But, for landscape view also i am getting the same issue,Please refer the below screenshot.

ahot-landscape

@seliniumtester
Copy link
Author

Also i am getting the below warning message in the console when Ashot takes screenshot. Please advice.

May 30, 2016 10:49:06 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver
WARNING: Augmenter should be applied to the instances of @augmentable classes or previously augmented instances only

@pazone
Copy link
Owner

pazone commented Jul 25, 2017

@seliniumtester Could you please take look at ShootingStrategies factory. You can solve your problem by using ShootingStrategies.viewportRetina(...) shooting strategy. You should figure our the DPR of your device to adjust it. Sorry for long response.

@MayankOkeyUser
Copy link

WebDriver driver = new ChromeDriver();
Object output = ((JavascriptExecutor) driver).executeScript("return window.devicePixelRatio");
String value = String.valueOf(output);
float windowDPR = Float.parseFloat(value);

use DPR here :
Screenshot screenshotfull= new AShot().shootingStrategy(ShootingStrategies.viewportRetina(1000, 0, 0, windowDPR)).takeScreenshot(driver);

you will get rid of Black Space from ScreenShot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants