From 21408b6c8407c21202b447c221b3dfce2adc0727 Mon Sep 17 00:00:00 2001 From: James Nord Date: Fri, 19 Feb 2021 15:12:30 +0000 Subject: [PATCH 1/3] Fix formvalidation FormValidation was failing as the structure of the validation changed. ``` Too many validation elements: [[[[[[[FirefoxDriver: firefox on LINUX (5967b81a-5dce-41f8-a115-117b72e60140)] -> css selector: [path='/useincluderegex/includeRegex']]] -> xpath: ./../../following-sibling::tr/td[2] | ./../following-sibling::div]] -> tag name: div], [[[[[[FirefoxDriver: firefox on LINUX (5967b81a-5dce-41f8-a115-117b72e60140)] -> css selector: [path='/useincluderegex/includeRegex']]] -> xpath: ./../../following-sibling::tr/td[2] | ./../following-sibling::div]] -> tag name: div], [[[[[[FirefoxDriver: firefox on LINUX (5967b81a-5dce-41f8-a115-117b72e60140)] -> css selector: [path='/useincluderegex/includeRegex']]] -> xpath: ./../../following-sibling::tr/td[2] | ./../following-sibling::div]] -> tag name: div], [[[[[[FirefoxDriver: firefox on LINUX (5967b81a-5dce-41f8-a115-117b72e60140)] -> css selector: [path='/useincluderegex/includeRegex']]] -> xpath: ./../../following-sibling::tr/td[2] | ./../following-sibling::div]] -> tag name: div]] ``` THis fixes the FormValidationTest (to some extent) however there is a bug in firefox that causes it not to show the alert when navigating away from a configuration page. works with chrome so this is at least a step in the right direction. --- .../test/acceptance/po/FormValidation.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java index 9857a94b77..e99ce75711 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java @@ -30,11 +30,11 @@ import org.openqa.selenium.Keys; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; - import javax.annotation.Nonnull; import java.util.List; import static org.hamcrest.Matchers.*; +import static org.jenkinsci.test.acceptance.po.CapybaraPortingLayer.by; /** * Result of form field validation. @@ -67,23 +67,24 @@ public static FormValidation await(Control control) { // Special handling for validation buttons and their markup if (element.getTagName().equals("button")) { - WebElement spinner = element.findElement(control.by.xpath("./../../../following-sibling::div[1]")); + WebElement spinner = element.findElement(by.xpath("./../../../following-sibling::div[1]")); // Wait as long as there is some spinner shown on the page control.waitFor().until(() -> !spinner.isDisplayed()); // Expand details (are there any) before we get the area element as doing so afterwards would stale the element reference for (WebElement elem : element.findElements(By.linkText("(show details)"))) { elem.click(); } - validationArea = element.findElement(control.by.xpath("./../../../following-sibling::div[2]")); + validationArea = element.findElement(by.xpath("./../../../following-sibling::div[2]")); } else { // Fire validation if it was not already element.sendKeys(Keys.TAB); // Wait for validation area to stop being
validationArea = control.waitFor().until(() -> { - WebElement va = element.findElement(control.by.xpath("./../../following-sibling::tr/td[2] | ./../following-sibling::div")); + // path to validation area is ../validation-error-area tr + WebElement va = element.findElement(by.xpath("../../div[contains(@class,'validation-error-area')]")); try { - va.findElement(control.by.xpath("./div")); + va.findElement(by.xpath("./div[2]")); return va; } catch (NoSuchElementException noDiv) { // https://issues.jenkins-ci.org/browse/JENKINS-59605?focusedCommentId=377474&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-377474 @@ -97,7 +98,7 @@ public static FormValidation await(Control control) { } public FormValidation(WebElement element) { - List divs = element.findElements(CapybaraPortingLayer.by.tagName("div")); + List divs = element.findElements(By.xpath("div[2]/div")); switch (divs.size()) { case 0: // TODO remove after https://issues.jenkins-ci.org/browse/JENKINS-59605 this.kind = Kind.OK; From f867e16ee135427affaf0aea454bdf194567daf3 Mon Sep 17 00:00:00 2001 From: James Nord Date: Fri, 19 Feb 2021 15:37:27 +0000 Subject: [PATCH 2/3] Update src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java Co-authored-by: Vincent Latombe --- .../java/org/jenkinsci/test/acceptance/po/FormValidation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java index e99ce75711..ae151d1e86 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java @@ -98,7 +98,7 @@ public static FormValidation await(Control control) { } public FormValidation(WebElement element) { - List divs = element.findElements(By.xpath("div[2]/div")); + List divs = element.findElements(by.xpath("div[2]/div")); switch (divs.size()) { case 0: // TODO remove after https://issues.jenkins-ci.org/browse/JENKINS-59605 this.kind = Kind.OK; From 2f6ccc6f8ea21ef42b857e3c3a175d733d39a38e Mon Sep 17 00:00:00 2001 From: James Nord Date: Fri, 19 Feb 2021 15:55:13 +0000 Subject: [PATCH 3/3] Update src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java --- .../java/org/jenkinsci/test/acceptance/po/FormValidation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java index ae151d1e86..44811d30a2 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/FormValidation.java @@ -81,7 +81,7 @@ public static FormValidation await(Control control) { // Wait for validation area to stop being
validationArea = control.waitFor().until(() -> { - // path to validation area is ../validation-error-area tr + // path to validation area is the parents sibling with class `validation-error-area` WebElement va = element.findElement(by.xpath("../../div[contains(@class,'validation-error-area')]")); try { va.findElement(by.xpath("./div[2]"));