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 dashboard-view plugin tests #1491

Merged
merged 2 commits into from
Feb 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public class BuildStatisticsPortlet extends AbstractDashboardViewPortlet {
*/
@SuppressWarnings("checkstyle:javadocvariable")
public enum JobType {
FAILED(2), UNSTABLE(3), SUCCESS(4), PENDING(5),
DISABLED(6), ABORTED(7), NOT_BUILT(8), TOTAL(9);
FAILED(1, "td"), UNSTABLE(2, "td"), SUCCESS(3, "td"), PENDING(4, "td"),
DISABLED(5, "td"), ABORTED(6, "td"), NOT_BUILT(7, "td"), TOTAL(8, "th");

private final int row;
private final String name;

JobType(int r) {
JobType(int r, String name) {
row = r;
this.name = name;
}
}

Expand All @@ -48,9 +50,7 @@ public BuildStatisticsPortlet(DashboardView parent, String path) {
* @return build statistics table
*/
public WebElement getTable() {
WebElement portlet = find(By.xpath("//div[contains(.,'" + PORTLET_NAME + "')]/following::table[1]"));

return portlet.findElement(By.id("statistics"));
return find(By.xpath("//div[contains(.,'" + PORTLET_NAME + "')]/following::table[1]"));
}

/**
Expand All @@ -60,7 +60,7 @@ public WebElement getTable() {
* @return number of builds
*/
public int getNumberOfBuilds(JobType type) {
return Integer.parseInt(getTable().findElement(By.xpath(".//tbody/tr[" + type.row + "]/td[3]")).getText().trim());
return Integer.parseInt(getTable().findElement(By.xpath(".//tbody/tr[" + type.row + "]/" + type.name + "[3]")).getText().trim());
}

/**
Expand All @@ -70,6 +70,6 @@ public int getNumberOfBuilds(JobType type) {
* @return percentage of builds
*/
public String getPercentageOfBuilds(JobType type) {
return getTable().findElement(By.xpath(".//tbody/tr[" + type.row + "]/td[4]")).getText().trim();
return getTable().findElement(By.xpath(".//tbody/tr[" + type.row + "]/" + type.name + "[4]")).getText().trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public LatestBuildsPortlet(DashboardView parent, String path) {
* @return latest builds table
*/
public WebElement getTable() {
WebElement portlet = find(By.xpath("//div[contains(.,'" + PORTLET_NAME + "')]/following::table[1]"));

return portlet.findElement(By.id("statistics"));
return find(By.xpath("//div[contains(.,'" + PORTLET_NAME + "')]/following::table[1]"));
}

private WebElement getRow(int row) {
Expand Down Expand Up @@ -76,8 +74,9 @@ public int getNumberOfBuilds() {
* @return True, if this Portlet contains a job with the given name.
*/
public boolean hasJob(String jobName) {
WebElement table = getTable();
try {
return !getTable().findElements(By.linkText(jobName)).isEmpty();
return !table.findElements(By.linkText(jobName)).isEmpty();
} catch (NoSuchElementException e) {
return false;
}
Expand All @@ -90,8 +89,9 @@ public boolean hasJob(String jobName) {
* @return True, if this Portlet contains a build with the given number.
*/
public boolean hasBuild(int buildNr) {
WebElement table = getTable();
try {
return !getTable().findElements(By.linkText("#" + buildNr)).isEmpty();
return !table.findElements(By.linkText("#" + buildNr)).isEmpty();
} catch (NoSuchElementException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public WebElement getTable() throws NoSuchElementException {
* @return True, if this Portlet contains a job with the given name.
*/
public boolean hasJob(String jobName) {
WebElement table = getTable();
try {
return !getTable().findElements(By.partialLinkText(jobName)).isEmpty();
return !table.findElements(By.partialLinkText(jobName)).isEmpty();
} catch (NoSuchElementException e) {
return false;
}
Expand Down