I have a task to make screenshots of mobile version of web pages.
I took Selenide and Ashot for that. In desktop view all correct. But in mobile emulation view of page, there is some probles. It shows one picture, but captures another. Maybe someone know another solution, or how to fix that problem ?
public class ChromeMobileEmulation implements WebDriverProvider {
@Override
public WebDriver createDriver(DesiredCapabilities desiredCapabilities) {
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "iPhone X");
ChromeOptions chromeOptions = new ChromeOptions().setHeadless(true);
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
chromeOptions.addArguments("--diagnostics", "--disable-blink-features");
WebDriverManager.chromedriver().setup();
return new ChromeDriver(chromeOptions);
}
@BeforeAll
public static void setUp() throws IOException {
propertyLoader();
createFolders();
SelenideLogger.addListener("allure", new AllureSelenide().screenshots(true).savePageSource(false));
Configuration.browser = System.getProperty("browser");
Configuration.timeout = 10000;
RestAssured.filters(new AllureRestAssured());
chromeMobile = new SelenideDriver(new SelenideConfig()
.browser(ChromeMobileEmulation.class.getName())
.headless(true)
.browserSize("375x812"));
}
private Screenshot capturePage(int scrollTime) {
return new AShot().shootingStrategy(viewportPasting(scrollTime)).takeScreenshot(getWebDriver());
}
protected void capturePageToVault(String pageName, String url, SelenideDriver driver, int scrollTime) throws IOException {
driver.open(url);
expected = capturePage(scrollTime, driver.getWebDriver());
ImageIO.write(expected.getImage(), "png", expectedImg(pageName));
}
}
WORKING SOLUTION FOR ME
private Screenshot capturePage(int scrollTime, WebDriver driver) {
return new AShot()
.coordsProvider(new WebDriverCoordsProvider())
.shootingStrategy(viewportPasting(scaling(3), scrollTime))
.takeScreenshot(driver);
}