Skip to content
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

Fix Various Test Issue #2126

Merged
merged 14 commits into from
Nov 11, 2024
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
46 changes: 44 additions & 2 deletions src/org/labkey/test/components/core/ApiKeyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;

public class ApiKeyDialog extends ModalDialog
{
Expand Down Expand Up @@ -42,8 +44,48 @@ public ApiKeyDialog copyKey()

public String getClipboardContent() throws IOException, UnsupportedFlavorException
{
return (String) Toolkit.getDefaultToolkit().getSystemClipboard()
.getData(DataFlavor.stringFlavor);
DataFlavor[] flavors = Toolkit.getDefaultToolkit().getSystemClipboard().getAvailableDataFlavors();
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

// Adding debug info for TeamCity run.
// Windows is not giving DataFlavor (MIME Type) for the data on the clipboard.
getWrapper().log("Available flavors: " + Arrays.stream(flavors).toList());
getWrapper().log("Best flavor: " + DataFlavor.selectBestTextFlavor(flavors));

if (t != null)
{

// Adding debug info for TeamCity run.
getWrapper().log("Is DataFlavor.imageFlavor supported? " + t.isDataFlavorSupported(DataFlavor.imageFlavor));
getWrapper().log("Is DataFlavor.allHtmlFlavor supported? " + t.isDataFlavorSupported(DataFlavor.allHtmlFlavor));
getWrapper().log("Is DataFlavor.fragmentHtmlFlavor supported? " + t.isDataFlavorSupported(DataFlavor.fragmentHtmlFlavor));
getWrapper().log("Is DataFlavor.selectionHtmlFlavor supported? " + t.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor));
getWrapper().log("Is DataFlavor.javaFileListFlavor supported? " + t.isDataFlavorSupported(DataFlavor.javaFileListFlavor));
getWrapper().log("Is DataFlavor.stringFlavor supported? " + t.isDataFlavorSupported(DataFlavor.stringFlavor));

DataFlavor[] transferFlavors = t.getTransferDataFlavors();
getWrapper().log("Transferable supported data flavors: " + Arrays.stream(transferFlavors).toList());

if (flavors.length > 0)
{
getWrapper().log("Best Text Flavor: " + DataFlavor.selectBestTextFlavor(flavors));
return (String) Toolkit.getDefaultToolkit().getSystemClipboard()
.getData(DataFlavor.selectBestTextFlavor(flavors));
}
else
{
getWrapper().log("There are no DataFlavors to use.");
// Return a value to indicate something is on the clipboard but no DataFlavor was provided.
return "There are no DataFlavors to use.";
}

}
else
{
getWrapper().log("The clipboard is empty.");
return "";
}

}

public boolean isCopyButtonDisplayed()
Expand Down
16 changes: 6 additions & 10 deletions src/org/labkey/test/components/ui/entities/EntityInsertPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.test.components.ui.entities;

import org.junit.Assert;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.Component;
Expand Down Expand Up @@ -140,18 +141,14 @@ public EntityInsertPanel addRecords(List<Map<String, Object>> records)
showGrid();
elementCache().grid.addRows(records.size());

List<Integer> rowIndices = elementCache().grid.getEditableRowIndices();

if(rowIndices.size() < records.size())
{
throw new IllegalStateException("Trying to add more records than there are rows. Number of records to create: " + records.size() + " number of available rows: " + rowIndices.size());
}
Assert.assertFalse(String.format("Trying to add more records than there are rows. Number of records to create: %d number of available rows: %d",
records.size(), elementCache().grid.getRowCount()),
elementCache().grid.getRowCount() < records.size());

int index = 0;

for(Map<String, Object> record : records)
{
setRecordValues(record, rowIndices.get(index));
setRecordValues(record, index);
index++;
}

Expand All @@ -160,8 +157,7 @@ public EntityInsertPanel addRecords(List<Map<String, Object>> records)

public EntityInsertPanel setRecordValues(Map<String, Object> columnValues)
{
int insertRowIndex = getEditableGrid().getEditableRowIndices().get(0);
return setRecordValues(columnValues, insertRowIndex);
return setRecordValues(columnValues, 0);
}

public EntityInsertPanel setRecordValues(Map<String, Object> columnValues, int row)
Expand Down
4 changes: 2 additions & 2 deletions src/org/labkey/test/components/ui/grids/DetailTableEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ public DetailDataPanel clickSave()
elementCache().saveButton.click();

// If save causes some update, wait until it is completed.
WebDriverWrapper.waitFor(()->!BootstrapLocators.loadingSpinner.existsIn(getDriver()),
"Save has taken too long to complete.", 15_000);
getWrapper().longWait().withMessage("Update took too long to complete.")
.until(ExpectedConditions.stalenessOf(elementCache().saveButton));

return new DetailDataPanel.DetailDataPanelFinder(getDriver()).withTitle(title).waitFor();
}
Expand Down
53 changes: 0 additions & 53 deletions src/org/labkey/test/components/ui/grids/EditableGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,59 +318,6 @@ public int getRowCount()
return getRows().size();
}

/**
* As best as possible get a list of row indices from the grid for editable rows. That is rows where the values can
* be entered or changed.
*
* @return A list of indices (0 based) for rows that can be edited.
*/
public List<Integer> getEditableRowIndices()
{
return getRowTypes().get(0);
}

/**
* Some EditableGrids have read only rows. These are rows in the grid that display data but cannot be updated. As
* best as possible return a list of those rows.
*
* @return A list of indices (0 based) of rows that cannot be edited.
*/
public List<Integer> getReadonlyRowIndices()
{
return getRowTypes().get(1);
}

private List<List<Integer>> getRowTypes()
{
List<Integer> unPopulatedRows = new ArrayList<>();
List<Integer> populatedRows = new ArrayList<>();

// Need to look at an attribute of a cell to see if it has pre-populated data.
// But this info will not be in the select or row-number cells, so we'll use the last column
// (CSS selector is 1-based not 0-based).
int checkColumn = getColumnNames().size();
int rowCount = 0;

for (WebElement row : getRows())
{
String classAttribute = row.findElement(By.cssSelector("td:nth-child(" + checkColumn + ") > div"))
.getAttribute("class");

if ((!classAttribute.contains("cell-selection")) && (!classAttribute.contains("cell-read-only")))
{
unPopulatedRows.add(rowCount);
}
else
{
populatedRows.add(rowCount);
}

rowCount++;
}

return new ArrayList<>(Arrays.asList(unPopulatedRows, populatedRows));
}

/**
* <p>
* For a given column, 'columnNameToSet', set the lookup cell in the first row where the value in column 'columnNameToSearch'
Expand Down