Skip to content

Update Aquality package to use Selenium 4.8.1 #25

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

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://dev.azure.com/aquality-automation/aquality-automation/_apis/build/status/aquality-automation.aquality-selenium-java-template?branchName=master)](https://dev.azure.com/aquality-automation/aquality-automation/_build/latest?definitionId=9&branchName=master)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=aquality-automation_aquality-selenium-java-template&metric=alert_status)](https://sonarcloud.io/dashboard?id=aquality-automation_aquality-selenium-java-template)
[![Allure report](https://github.com/aquality-automation/aquality-selenium-java-template/actions/workflows/test-with-allure-report.yml/badge.svg)](https://aquality-automation.github.io/aquality-selenium-java-template/)

# Aquality Selenium Template Project
Template for [aquality-selenium-java](https://github.com/aquality-automation/aquality-selenium-java) library.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package aquality.selenium.template.utilities;

import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

import java.io.File;
import java.nio.file.Paths;
import java.util.Objects;

@UtilityClass
public class FileHelper {
private static final String RESOURCES_PATH = "/src/test/resources/";
private static final String JAVASCRIPT_PATH = "/javascript/";

private static String getProjectBaseDir(){
return System.getProperty("user.dir") != null ? System.getProperty("user.dir") : System.getProperty("project.basedir");
return System.getProperty("user.dir") != null ? System.getProperty("user.dir") : System.getProperty("project.basedir");
}

public static File getResourceFileByName(String fileName) {
return Paths.get(getProjectBaseDir(), RESOURCES_PATH + fileName).toFile();
}

@SneakyThrows
public static File getJavascriptFileByName(String fileNameWithoutExtension) {
return new File(Objects.requireNonNull(
FileHelper.class.getResource(JAVASCRIPT_PATH + fileNameWithoutExtension + ".js")).toURI());
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package aquality.selenium.template.utilities;

import aquality.selenium.browser.AqualityServices;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
import ru.yandex.qatools.ashot.shooting.ShootingStrategy;

import javax.imageio.ImageIO;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static aquality.selenium.browser.AqualityServices.getBrowser;
import static aquality.selenium.browser.AqualityServices.getLogger;
import static aquality.selenium.template.utilities.FileHelper.getJavascriptFileByName;

public class ScreenshotProvider implements IScreenshotProvider {

public byte[] takeScreenshot() {
int scrollTimeout = 500;
ShootingStrategy shootingStrategy = ShootingStrategies.viewportPasting(scrollTimeout);
Screenshot fpScreenshot = new AShot()
.shootingStrategy(shootingStrategy)
.takeScreenshot(AqualityServices.getBrowser().getDriver());

try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(fpScreenshot.getImage(), "jpg", baos);
baos.flush();
return baos.toByteArray();
} catch (IOException ioe) {
AqualityServices.getLogger()
.debug("IO Exception during preparing screenshot of full page%nException message", ioe);
return new byte[] {};
try {
int fullWidth = (int)(long) getBrowser().executeScript(getJavascriptFileByName("getScrollHeight"));
int fullHeight = (int)(long) getBrowser().executeScript(getJavascriptFileByName("getScrollHeight"));
getBrowser().setWindowSize(fullWidth, fullHeight);
return getBrowser().getScreenshot();
}
catch (IOException exception) {
getLogger().fatal("IO Exception during preparing screenshot of full page", exception);
return new byte[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return document.body.parentNode.scrollHeight;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return document.body.parentNode.scrollWidth;
14 changes: 1 addition & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
</dependency>

<dependency>
Expand All @@ -41,18 +41,6 @@
<version>31.1-jre</version>
</dependency>

<dependency>
<groupId>ru.yandex.qatools.ashot</groupId>
<artifactId>ashot</artifactId>
<version>1.5.4</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down