Skip to content

Commit 2f3c4b2

Browse files
Merge 25.7 to develop (#2551)
2 parents 8f8fea0 + 18d4c4f commit 2f3c4b2

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

src/org/labkey/test/TestFileUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import java.nio.file.Paths;
6565
import java.nio.file.SimpleFileVisitor;
6666
import java.nio.file.attribute.BasicFileAttributes;
67+
import java.security.MessageDigest;
68+
import java.security.NoSuchAlgorithmException;
6769
import java.security.Security;
6870
import java.util.ArrayList;
6971
import java.util.Arrays;
@@ -105,6 +107,9 @@ public static String getFileContents(final File file)
105107
return getFileContents(path);
106108
}
107109

110+
/**
111+
* Get text content of a file. Will throw an error for non-text files (e.g. PDF).
112+
*/
108113
public static String getFileContents(Path path)
109114
{
110115
try
@@ -117,6 +122,21 @@ public static String getFileContents(Path path)
117122
}
118123
}
119124

125+
/**
126+
* Compute MD5 hash for the given file. Useful checking file equivalence.
127+
*/
128+
public static String getMD5Hash(Path path)
129+
{
130+
try
131+
{
132+
return new String(MessageDigest.getInstance("MD5").digest(Files.readAllBytes(path)), StandardCharsets.UTF_8);
133+
}
134+
catch (IOException | NoSuchAlgorithmException fail)
135+
{
136+
throw new RuntimeException(fail);
137+
}
138+
}
139+
120140
public static String getStreamContentsAsString(InputStream is) throws IOException
121141
{
122142
return StringUtils.join(IOUtils.readLines(is, Charset.defaultCharset()).toArray(), System.lineSeparator());

src/org/labkey/test/pages/reports/ScriptReportPage.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import org.openqa.selenium.WebElement;
1818
import org.openqa.selenium.support.ui.ExpectedConditions;
1919

20+
import java.net.URLDecoder;
21+
import java.nio.charset.StandardCharsets;
2022
import java.util.Map;
21-
import java.util.Objects;
2223
import java.util.Optional;
2324

2425
import static org.labkey.test.components.ext4.Checkbox.Ext4Checkbox;
@@ -89,12 +90,25 @@ public String saveReport(String name, boolean isSaveAs, int wait)
8990
{
9091
saveReportWithName(name, isSaveAs);
9192
}
92-
return Objects.requireNonNullElse(getReportId(), reportIdBeforeSave);
93+
String reportIdAfterSave = getReportId();
94+
return reportIdAfterSave == null ? reportIdBeforeSave : reportIdAfterSave;
9395
}
9496

9597
public String getReportId()
9698
{
97-
return getUrlParam("reportId", true);
99+
String paramName = "reportId";
100+
101+
Map<String, String> params = WebTestHelper.parseUrlQuery(getURL());
102+
String paramValue = params.get(paramName);
103+
104+
if (paramValue == null)
105+
{
106+
paramValue = params.entrySet().stream()
107+
.filter(entry -> entry.getKey().endsWith("." + paramName))
108+
.map(Map.Entry::getValue).findFirst().orElse(null);
109+
}
110+
111+
return paramValue == null ? null : URLDecoder.decode(paramValue, StandardCharsets.UTF_8);
98112
}
99113

100114
/**

src/org/labkey/test/tests/FileAttachmentColumnTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ private void validateSampleData(String sampleType, String folderPath, List<File>
550550
{
551551
// verify fie download behavior
552552
File downloadedFile = doAndWaitForDownload(() -> optionalFileLink.get().click());
553-
checker().wrapAssertion(() -> Assertions.assertThat(TestFileUtils.getFileContents(downloadedFile))
553+
checker().wrapAssertion(() -> Assertions.assertThat(TestFileUtils.getMD5Hash(downloadedFile.toPath()))
554554
.as("expect the downloaded file to be the expected file")
555-
.isEqualTo(TestFileUtils.getFileContents(file))); // guard against renames like file2.xyz
555+
.isEqualTo(TestFileUtils.getMD5Hash(file.toPath()))); // guard against renames like file2.xyz
556556
}
557557
}
558558
}
@@ -576,9 +576,9 @@ private void validateAssayRun(String assayName, String folderPath, String runNam
576576
if (optionalFileLink.isPresent())
577577
{
578578
var file = doAndWaitForDownload(()-> optionalFileLink.get().click());
579-
checker().wrapAssertion(()-> Assertions.assertThat(TestFileUtils.getFileContents(file))
579+
checker().wrapAssertion(()-> Assertions.assertThat(TestFileUtils.getMD5Hash(file.toPath()))
580580
.as("expect the downloaded file to have equivalent content")
581-
.isEqualTo(TestFileUtils.getFileContents(runFile)));
581+
.isEqualTo(TestFileUtils.getMD5Hash(runFile.toPath())));
582582
}
583583

584584
var resultsPage = runsPage.clickAssayIdLink(runName);
@@ -644,9 +644,9 @@ private void validateDatasetData(String datasetName, String folderPath, List<Fil
644644
{
645645
// verify fie download behavior
646646
File downloadedFile = doAndWaitForDownload(() -> optionalFileLink.get().click());
647-
checker().wrapAssertion(() -> Assertions.assertThat(TestFileUtils.getFileContents(downloadedFile))
647+
checker().wrapAssertion(() -> Assertions.assertThat(TestFileUtils.getMD5Hash(downloadedFile.toPath()))
648648
.as("expect the downloaded file to be the expected file")
649-
.isEqualTo(TestFileUtils.getFileContents(file))); // guard against renames like file2.xyz
649+
.isEqualTo(TestFileUtils.getMD5Hash(file.toPath()))); // guard against renames like file2.xyz
650650
}
651651
}
652652
}

src/org/labkey/test/tests/SimpleModuleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ private void validateThumbnails(String thumbnailImage, @Nullable String thumbnai
850850
Locator popup = Locator.tag("div").withAttribute("id", "helpDiv").descendant("img").withAttributeContaining("src", popupImage).
851851
withAttributeContaining("style", popupWidth != null ? "width:" + popupWidth : "max-width:300px");
852852
shortWait().until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#helpDiv")));
853-
String src = StringUtils.trimToEmpty(popup.findElement(getDriver()).getDomAttribute("src"));
853+
String src = StringUtils.trimToEmpty(popup.findElement(getDriver()).getDomProperty("src"));
854854

855855
fireEvent(thumbnail, SeleniumEvent.mouseout);
856856
Locator.tagWithClass("th", "labkey-selectors").findElement(getDriver()).click(); // safe out-click in the first header cell
@@ -1230,7 +1230,7 @@ private void verifyReportThumbnail(@LoggedParam String reportTitle)
12301230
WebElement reportLink = waitForElement(Locator.xpath("//a[text()='" + reportTitle + "']"));
12311231
mouseOver(reportLink);
12321232
WebElement thumbnail = waitForElement(Locator.xpath("//div[@class='thumbnail']/img").notHidden());
1233-
String thumbnailData = WebTestHelper.getHttpResponse(thumbnail.getDomAttribute("src")).getResponseBody();
1233+
String thumbnailData = WebTestHelper.getHttpResponse(thumbnail.getDomProperty("src")).getResponseBody();
12341234

12351235
int lengthToCompare = 5000;
12361236
int diff = LevenshteinDistance.getDefaultInstance().apply(expectedThumbnail.substring(0, lengthToCompare), thumbnailData.substring(0, lengthToCompare));

0 commit comments

Comments
 (0)