Skip to content

Commit

Permalink
fix dashboard-view plugin tests (#1491)
Browse files Browse the repository at this point in the history
* fix dashboard-view plugin tests

* fix index and add field
  • Loading branch information
mawinter69 committed Feb 29, 2024
1 parent 0d7a876 commit d53a587
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
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

0 comments on commit d53a587

Please sign in to comment.