Skip to content

Commit

Permalink
Merge pull request #426 from telekom/feature/bump-commons-io
Browse files Browse the repository at this point in the history
Bump Apache libs commons-io and commons-lang3
  • Loading branch information
martingrossmann authored Oct 1, 2024
2 parents 89e4ae6 + 0bb0af7 commit 1027771
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 36 deletions.
5 changes: 2 additions & 3 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ dependencies {
implementation 'org.reflections:reflections:0.9.12'
// </Testerra>

api 'commons-io:commons-io:2.6'
// StringUtils needs api dep
api 'org.apache.commons:commons-lang3:3.9'
api 'commons-io:commons-io:2.16.1'
api 'org.apache.commons:commons-lang3:3.17.0'

// <PdfUtils>
implementation 'org.apache.pdfbox:pdfbox:3.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import eu.tsystems.mms.tic.testframework.report.model.context.Screenshot;
import eu.tsystems.mms.tic.testframework.report.model.context.Video;
import eu.tsystems.mms.tic.testframework.utils.FileUtils;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
Expand All @@ -47,8 +48,6 @@ public DefaultReport() {
currentReportDirectory = tempReportDirectory;
}



private File addFile(File sourceFile, File directory, FileMode fileMode) {
try {
switch (fileMode) {
Expand All @@ -73,6 +72,7 @@ public File finalizeReport() {
}

if (tempReportDirectory.exists()) {
log().debug("Temporary directory is {}", tempReportDirectory);
FileUtils.moveDirectory(tempReportDirectory, finalReportDirectory);
currentReportDirectory = finalReportDirectory;
log().info("Report written to " + finalReportDirectory.getAbsolutePath());
Expand Down Expand Up @@ -115,7 +115,7 @@ public Report addVideo(Video video, FileMode fileMode) {
}

@Override
public Video provideVideo(File file, FileMode fileMode) {
public Video provideVideo(File file, FileMode fileMode) {
Video video = new Video(file);
addVideo(video, fileMode);
return video;
Expand All @@ -127,6 +127,7 @@ public Video provideVideo(File file, FileMode fileMode) {
public File getReportDirectory() {
return currentReportDirectory;
}

/**
* @return Final report directory defined by the user
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import eu.tsystems.mms.tic.testframework.report.utils.IExecutionContextController;
import eu.tsystems.mms.tic.testframework.testing.AssertProvider;
import eu.tsystems.mms.tic.testframework.utils.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import eu.tsystems.mms.tic.testframework.utils.UITestUtils;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -195,9 +194,10 @@ private static MatchStep prepare(
/**
* Matches image pixels and returns an absolute distance value
*/
public static MatchStep matchPixels(final TakesScreenshot takesScreenshot, final String targetImageName) {
final File screenshot = takesScreenshot.getScreenshotAs(OutputType.FILE);
return matchPixels(screenshot, targetImageName);
public static MatchStep matchPixels(WebDriver webDriver, final String targetImageName) {
Screenshot screenshot = new Screenshot();
UITestUtils.takeWebDriverScreenshotToFile(webDriver, screenshot.getScreenshotFile());
return matchPixels(screenshot.getScreenshotFile(), targetImageName);
}

public static MatchStep matchPixels(final File screenshot, final String targetImageName) {
Expand Down Expand Up @@ -483,7 +483,7 @@ public static boolean isMatchDimensions(final MatchStep step) {
public static void assertScreenshot(WebDriver webDriver, String targetImageName, double confidenceThreshold) {
final String assertMessage = String.format("pixel distance (%%) of WebDriver screenshot to image '%s'", targetImageName);

LayoutCheck.MatchStep matchStep = LayoutCheck.matchPixels((TakesScreenshot) webDriver, targetImageName);
LayoutCheck.MatchStep matchStep = LayoutCheck.matchPixels(webDriver, targetImageName);
assertWithLayoutCheck(matchStep, confidenceThreshold, assertMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -78,7 +79,6 @@ public class UITestUtils implements WebDriverManagerProvider {
private static final DateFormat FILES_DATE_FORMAT = new SimpleDateFormat("dd_MM_yyyy__HH_mm_ss");
private static final Report report = Testerra.getInjector().getInstance(Report.class);
private static final IExecutionContextController executionContextController = Testerra.getInjector().getInstance(IExecutionContextController.class);
private static final int IE_SCREENSHOT_LIMIT = 1200;

@Deprecated
private UITestUtils() {
Expand Down Expand Up @@ -207,28 +207,16 @@ private static Screenshot takeScreenshot(WebDriver decoratedWebDriver, String or
}

public static void takeWebDriverScreenshotToFile(WebDriver decoratedWebDriver, File screenShotTargetFile) {
/*
* The ChromeDriver doesn't support Screenshots of a large Site currently (Selenium 2.44), only the viewport ist
* captured. To allow full-page screenshots, we stitch several viewport-screenshots together.
* If this is eventually supported by WebDriver, this special branch can be removed.
*/
if (Browsers.ie.equalsIgnoreCase(WEB_DRIVER_MANAGER.getRequestedBrowser(decoratedWebDriver).orElse(null))) {
Rectangle viewport = new JSUtils().getViewport(decoratedWebDriver);

if (viewport.height > IE_SCREENSHOT_LIMIT) {
LOGGER.warn("IE: Not taking screenshot because screen size is larger than height limit of " + IE_SCREENSHOT_LIMIT);
return;
}
}

// take screenshot
makeSimpleScreenshot(decoratedWebDriver, screenShotTargetFile);
}

private static void makeSimpleScreenshot(WebDriver driver, File screenShotTargetFile) {
try {
File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.moveFile(file, screenShotTargetFile);
// Using FileOutputStream prevents from file permission issues on -ix systems:
// '((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)' creates files with user-only permissions
// Moving the file with latest org.apache.commons.io.FileUtils does not change permissions any more
try (OutputStream os = new FileOutputStream(screenShotTargetFile)) {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
os.write(screenshot);
} catch (Exception e) {
LOGGER.error("Unable to take screenshot to file", e);
}
Expand All @@ -237,7 +225,7 @@ private static void makeSimpleScreenshot(WebDriver driver, File screenShotTarget
/**
* Save page source to file.
*
* @param pageSource page source.
* @param pageSource page source.
* @param sourceTargetFile target file.
*/
private static void savePageSource(final String pageSource, final File sourceTargetFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected TestPage getTestPage() {
@BeforeTest(alwaysRun = true)
public void setUp() throws Exception {
try {
staticServer.start(80);
staticServer.start(8080);
} catch (BindException e) {
log().warn("Use already running WebServer: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void configureChromeOptions(Method method) {
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-search-engine-choice-screen");
});
WEB_DRIVER_MANAGER.setUserAgentConfig(Browsers.chrome, (ChromeConfig) options -> {
options.addArguments("--disable-search-engine-choice-screen");
});
}

protected AbstractWebDriverRequest getWebDriverRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Class<WebTestPage> getPageClass() {
return WebTestPage.class;
}

@Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Expected that WebTestPage url=\\[http://localhost/Input/input.html\\] ends with \\[nonexistingfile.html\\] is true")
@Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Expected that WebTestPage url=\\[http://localhost:8080/Input/input.html\\] ends with \\[nonexistingfile.html\\] is true")
public void test_Page_url_format() {
WebTestPage page = getPage();
CONTROL.withTimeout(0, () -> page.expect().url().endsWith("nonexistingfile.html").is(true));
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/test/resources/Smoke.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<test name="test1">
<classes>
<!-- <class name="eu.tsystems.mms.tic.testframework.test.common.PropertyManagerTest"></class>-->
<class name="eu.tsystems.mms.tic.testframework.test.layoutcheck.LayoutCheckTest">
<class name="eu.tsystems.mms.tic.testframework.playground.DriverAndGuiElementTest">
<methods>
<include name="testT01_CheckElementLayout"/>
<include name="testFailing"/>
</methods>
</class>
</classes>
Expand Down

0 comments on commit 1027771

Please sign in to comment.