Skip to content

Commit

Permalink
stabilize FileUpload-IT´s (primefaces#9399)
Browse files Browse the repository at this point in the history
* stabilize FileUpload-IT´s

* checkstyle

* stability refinements

* stability refinements
  • Loading branch information
christophs78 authored Nov 11, 2022
1 parent f37d114 commit 515725b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import java.util.stream.Collectors;

import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.primefaces.selenium.AbstractPrimePageTest;
import org.primefaces.selenium.PrimeSelenium;
import org.primefaces.selenium.component.DataTable;
import org.primefaces.selenium.component.model.datatable.Row;

Expand Down Expand Up @@ -79,4 +82,19 @@ protected void assertUploadedFiles(DataTable uploadedFiles, File... files) {
}
}

protected void wait4EmptyMesssage(DataTable uploadedFiles) {
PrimeSelenium.waitGui().until(ExpectedConditions.visibilityOf(
uploadedFiles.findElement(By.tagName("tbody")).findElement(By.cssSelector("tr.ui-datatable-empty-message"))));
}

protected void wait4File(DataTable uploadedFiles, String filename) {
PrimeSelenium.waitGui().until(ExpectedConditions.textToBePresentInElement(
uploadedFiles.findElement(By.tagName("tbody")), filename));
}

protected void wait4File(DataTable uploadedFiles, int row, String filename) {
PrimeSelenium.waitGui().until(ExpectedConditions.textToBePresentInElement(
uploadedFiles.findElement(By.tagName("tbody")).findElements(By.tagName("tr")).get(row - 1), filename));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testBasicSingleUpload(Page page) {
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file.getName()), fileUpload.getWidgetValue());
page.button.click();
wait4File(page.uploadedFiles, 1, file.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -70,6 +71,7 @@ public void testBasicSingleUploadTwice(Page page) {
fileUpload.setValue(file1);
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file1.getName()), fileUpload.getWidgetValue());
page.button.click();
wait4File(page.uploadedFiles, 1, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -80,6 +82,7 @@ public void testBasicSingleUploadTwice(Page page) {
fileUpload.setValue(file2);
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file2.getName()), fileUpload.getWidgetValue());
page.button.click();
wait4File(page.uploadedFiles, 2, file2.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -103,6 +106,7 @@ public void testBasicSingleUploadSizeLimit(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValue().contains(invalidSizeMsg));
Assertions.assertTrue(fileUpload.getWidgetValue().contains(file.getName()));
page.button.click();
wait4EmptyMesssage(page.uploadedFiles);

// Assert
assertNoJavascriptErrors();
Expand All @@ -127,6 +131,7 @@ public void testBasicSingleUploadAllowTypes(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValue().contains(invalidTypeMsg));
Assertions.assertTrue(fileUpload.getWidgetValue().contains(file.getName()));
page.button.click();
wait4EmptyMesssage(page.uploadedFiles);

// Assert
assertNoJavascriptErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testBasicMultipleUploadSingleFile(Page page) {
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file.getName()), fileUpload.getWidgetValue());
page.button.click();
wait4File(page.uploadedFiles, 1, file.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -74,6 +75,7 @@ public void testBasicMultipleUploadMultipleFiles(Page page) throws Exception {
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file1.getName()), fileUpload.getWidgetValue());
Assertions.assertTrue(fileUpload.getWidgetValue().matches(".*\\+\\s*1$"));
page.button.click();
wait4File(page.uploadedFiles, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -97,6 +99,7 @@ public void testBasicMultipleUploadMultipleFilesTwice(Page page) throws Exceptio
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file1.getName()), fileUpload.getWidgetValue());
Assertions.assertTrue(fileUpload.getWidgetValue().matches(".*\\+\\s*1$"));
page.button.click();
wait4File(page.uploadedFiles, 1, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -111,6 +114,7 @@ public void testBasicMultipleUploadMultipleFilesTwice(Page page) throws Exceptio
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file3.getName()), fileUpload.getWidgetValue());
Assertions.assertTrue(fileUpload.getWidgetValue().matches(".*\\+\\s*1$"));
page.button.click();
wait4File(page.uploadedFiles, 3, file3.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -137,6 +141,7 @@ public void testBasicMultipleUploadFileLimit(Page page) {
// the widget shows only the file limit message
Assertions.assertTrue(fileUpload.getWidgetValue().equals(fileLimitMsg));
page.button.click();
wait4EmptyMesssage(page.uploadedFiles);

// Assert
assertNoJavascriptErrors();
Expand All @@ -161,6 +166,7 @@ public void testBasicMultipleUploadSizeLimit(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValue().contains(invalidSizeMsg));
Assertions.assertTrue(fileUpload.getWidgetValue().contains(file.getName()));
page.button.click();
wait4EmptyMesssage(page.uploadedFiles);

// Assert
assertNoJavascriptErrors();
Expand All @@ -185,6 +191,7 @@ public void testBasicMultipleUploadAllowTypes(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValue().contains(invalidTypeMsg));
Assertions.assertTrue(fileUpload.getWidgetValue().contains(file.getName()));
page.button.click();
wait4EmptyMesssage(page.uploadedFiles);

// Assert
assertNoJavascriptErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void testAdvancedSingleUpload(Page page) {
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValue().startsWith(file.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 1, file.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -69,6 +70,7 @@ public void testAdvancedSingleUploadTwice(Page page) {
fileUpload.setValue(file1);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 1, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -79,6 +81,7 @@ public void testAdvancedSingleUploadTwice(Page page) {
fileUpload.setValue(file2);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file2.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 2, file2.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -98,6 +101,7 @@ public void testAdvancedSingleUploadCancel(Page page) {
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedCancelButton().click();
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertTrue(fileUpload.getWidgetValues().isEmpty(), fileUpload.getWidgetValues().toString());

// Assert
Expand All @@ -121,6 +125,7 @@ public void testAdvancedSingleUploadFileLimit(Page page) {
fileUpload.setValue(file1);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 1, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void testAdvancedMultipleUploadSingleFile(Page page) throws Exception {
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 1, file.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -72,6 +73,7 @@ public void testAdvancedMultipleUploadMultipleFiles(Page page) throws Exception
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file2.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -94,6 +96,7 @@ public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Excep
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file2.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -107,6 +110,7 @@ public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Excep
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 3, ".csv"); // order is not stable

// Assert
assertNoJavascriptErrors();
Expand Down Expand Up @@ -159,6 +163,7 @@ public void testAdvancedMultipleUploadFileLimit(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file4.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName());

// Assert
assertNoJavascriptErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public class FileUpload009Test extends AbstractFileUploadTest {
public void testAdvancedMultipleUploadSingleFile(Page page) throws Exception {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());

// Act
File file = locateClientSideFile("file1.csv");
fileUpload.setValue(file);
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file.getName());

// Assert
assertNoJavascriptErrors();
Expand All @@ -62,6 +64,7 @@ public void testAdvancedMultipleUploadSingleFile(Page page) throws Exception {
public void testAdvancedMultipleUploadMultipleFiles(Page page) throws Exception {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());

// Act
Expand All @@ -73,6 +76,7 @@ public void testAdvancedMultipleUploadMultipleFiles(Page page) throws Exception
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file2.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName()); // order is not stable

// Assert
assertNoJavascriptErrors();
Expand All @@ -85,6 +89,7 @@ public void testAdvancedMultipleUploadMultipleFiles(Page page) throws Exception
public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Exception {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());

// Act
Expand All @@ -96,6 +101,7 @@ public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Excep
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file1.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file2.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName()); // order is not stable

// Assert
assertNoJavascriptErrors();
Expand All @@ -110,6 +116,7 @@ public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Excep
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, 3, ".csv"); // order is not stable

// Assert
assertNoJavascriptErrors();
Expand All @@ -122,6 +129,7 @@ public void testAdvancedMultipleUploadMultipleFilesTwice(Page page) throws Excep
public void testAdvancedMultipleUploadCancel(Page page) {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());

// Act
Expand All @@ -145,6 +153,7 @@ public void testAdvancedMultipleUploadCancel(Page page) {
public void testAdvancedMultipleUploadFileLimit(Page page) {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());
String fileLimitMsg = fileUpload.getWidgetConfiguration().getString("fileLimitMessage");
Assertions.assertNotNull(fileLimitMsg);
Expand All @@ -162,6 +171,7 @@ public void testAdvancedMultipleUploadFileLimit(Page page) {
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file3.getName()), fileUpload.getWidgetValues().toString());
Assertions.assertTrue(fileUpload.getWidgetValues().contains(file4.getName()), fileUpload.getWidgetValues().toString());
fileUpload.getAdvancedUploadButton().click();
wait4File(page.uploadedFiles, file1.getName()); // order is not stable

// Assert
assertNoJavascriptErrors();
Expand All @@ -185,6 +195,7 @@ public void testAdvancedMultipleUploadFileLimit(Page page) {
public void testAdvancedMultipleUploadSizeLimit(Page page) {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());
String invalidSizeMsg = fileUpload.getWidgetConfiguration().getString("invalidSizeMessage");
Assertions.assertNotNull(invalidSizeMsg);
Expand All @@ -208,6 +219,7 @@ public void testAdvancedMultipleUploadSizeLimit(Page page) {
public void testAdvancedMultipleUploadAllowTypes(Page page) {
// Arrange
FileUpload fileUpload = page.fileupload;
wait4EmptyMesssage(page.uploadedFiles);
Assertions.assertEquals("", fileUpload.getValue());
String invalidTypeMsg = fileUpload.getWidgetConfiguration().getString("invalidFileMessage");
Assertions.assertNotNull(invalidTypeMsg);
Expand Down

0 comments on commit 515725b

Please sign in to comment.