From 5c07e5e99a1fc9ec6b0a4db8fddc785a1e885b79 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 2 Sep 2015 18:34:04 +0200 Subject: [PATCH] Remove some more potential FP --- .../ProjectAdministrationTest.java | 22 ++++++++----------- .../test/java/selenium/LazyDomElement.java | 2 +- .../src/test/java/selenium/LazyShould.java | 2 +- it/it-tests/src/test/java/selenium/Retry.java | 1 - .../src/test/java/selenium/SeleneseTest.java | 21 ++++++++++++------ ...display-alerts-correctly-history-page.html | 5 +++++ .../project-deletion/project-deletion.html | 5 +++++ ...ate-impossible-because-duplicate-keys.html | 6 ++--- ...lk-update-impossible-because-no-input.html | 5 +++++ ...lk-update-impossible-because-no-match.html | 5 +++++ .../bulk-update-success.html | 5 +++++ .../fine-grained-update-impossible.html | 5 +++++ .../fine-grained-update-success.html | 5 +++++ 13 files changed, 63 insertions(+), 26 deletions(-) diff --git a/it/it-tests/src/test/java/administration/suite/administration/ProjectAdministrationTest.java b/it/it-tests/src/test/java/administration/suite/administration/ProjectAdministrationTest.java index 939b2af95a5..7b9b49257e5 100644 --- a/it/it-tests/src/test/java/administration/suite/administration/ProjectAdministrationTest.java +++ b/it/it-tests/src/test/java/administration/suite/administration/ProjectAdministrationTest.java @@ -104,7 +104,7 @@ public class ProjectAdministrationTest { * Test updated for SONAR-3570 and SONAR-5923 */ @Test - public void project_deletion() throws Exception { + public void project_deletion() { String projectAdminUser = "project-deletion-with-admin-permission-on-project"; SonarClient adminClient = orchestrator.getServer().adminWsClient(); try { @@ -117,10 +117,9 @@ public class ProjectAdministrationTest { adminClient.permissionClient().addPermission( PermissionParameters.create().user(projectAdminUser).component("sample").permission("admin")); - // Use the old runner because it fails with the new Selenium runner - orchestrator.executeSelenese( + new SeleneseTest( Selenese.builder().setHtmlTestsInClasspath("project-deletion", "/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html").build() - ); + ).runOn(orchestrator); } finally { adminClient.userClient().deactivate(projectAdminUser); } @@ -128,7 +127,7 @@ public class ProjectAdministrationTest { // SONAR-4203 @Test - public void delete_version_of_multimodule_project() throws Exception { + public void delete_version_of_multimodule_project() { GregorianCalendar today = new GregorianCalendar(); SonarRunner build = SonarRunner.create(projectDir("shared/xoo-multi-modules-sample")) .setProperty("sonar.dynamicAnalysis", "false") @@ -162,7 +161,7 @@ public class ProjectAdministrationTest { // SONAR-3326 @Test - public void display_alerts_correctly_in_history_page() throws Exception { + public void display_alerts_correctly_in_history_page() { QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient(); QualityGate qGate = qgClient.create("AlertsForHistory"); qgClient.setDefault(qGate.id()); @@ -178,8 +177,7 @@ public class ProjectAdministrationTest { .setHtmlTestsInClasspath("display-alerts-history-page", "/administration/suite/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html" ).build(); - // Use the old runner because it fails with the new Selenium runner - orchestrator.executeSelenese(selenese); + new SeleneseTest(selenese).runOn(orchestrator); qgClient.unsetDefault(); qgClient.destroy(qGate.id()); @@ -189,7 +187,7 @@ public class ProjectAdministrationTest { * SONAR-1352 */ @Test - public void display_period_alert_on_project_dashboard() throws Exception { + public void display_period_alert_on_project_dashboard() { QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient(); QualityGate qGate = qgClient.create("AlertsForDashboard"); qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("LT").warningThreshold("0").errorThreshold("10") @@ -246,8 +244,7 @@ public class ProjectAdministrationTest { "/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-match.html", "/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-success.html" ).build(); - // Use the old runner because it fails with the new Selenium runner - orchestrator.executeSelenese(selenese); + new SeleneseTest(selenese).runOn(orchestrator); } /** @@ -263,8 +260,7 @@ public class ProjectAdministrationTest { "/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-impossible.html", "/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-success.html" ).build(); - // Use the old runner because it fails with the new Selenium runner - orchestrator.executeSelenese(selenese); + new SeleneseTest(selenese).runOn(orchestrator); } /** diff --git a/it/it-tests/src/test/java/selenium/LazyDomElement.java b/it/it-tests/src/test/java/selenium/LazyDomElement.java index 52cb6388621..1a230bd0e5a 100644 --- a/it/it-tests/src/test/java/selenium/LazyDomElement.java +++ b/it/it-tests/src/test/java/selenium/LazyDomElement.java @@ -71,7 +71,7 @@ class LazyDomElement { } public LazyShould should() { - return new LazyShould(this, Retry._5_SECONDS, true); + return new LazyShould(this, Retry._30_SECONDS, true); } public void fill(final CharSequence text) { diff --git a/it/it-tests/src/test/java/selenium/LazyShould.java b/it/it-tests/src/test/java/selenium/LazyShould.java index 92ddbc6bf62..c344ba70e2a 100644 --- a/it/it-tests/src/test/java/selenium/LazyShould.java +++ b/it/it-tests/src/test/java/selenium/LazyShould.java @@ -99,7 +99,7 @@ class LazyShould { public LazyShould contain(final String text) { return verify( - doesOrNot("contain(") + text + ")", + doesOrNot("contain") + "(" + text + ")", new Predicate>() { @Override public boolean apply(List elements) { diff --git a/it/it-tests/src/test/java/selenium/Retry.java b/it/it-tests/src/test/java/selenium/Retry.java index 1623284adf8..cc13823546d 100644 --- a/it/it-tests/src/test/java/selenium/Retry.java +++ b/it/it-tests/src/test/java/selenium/Retry.java @@ -33,7 +33,6 @@ import static java.util.concurrent.TimeUnit.SECONDS; class Retry { public static final Retry _30_SECONDS = new Retry(30, SECONDS); - public static final Retry _5_SECONDS = new Retry(5, SECONDS); private final long timeoutInMs; diff --git a/it/it-tests/src/test/java/selenium/SeleneseTest.java b/it/it-tests/src/test/java/selenium/SeleneseTest.java index f78438a80b0..9d7d2bb495d 100644 --- a/it/it-tests/src/test/java/selenium/SeleneseTest.java +++ b/it/it-tests/src/test/java/selenium/SeleneseTest.java @@ -21,6 +21,7 @@ package selenium; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.selenium.Selenese; +import org.assertj.core.util.Strings; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -38,7 +39,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import static java.util.regex.Pattern.DOTALL; import static org.assertj.core.api.Assertions.assertThat; -import static selenium.Retry._5_SECONDS; +import static selenium.Retry._30_SECONDS; public class SeleneseTest { private final Selenese suite; @@ -127,6 +128,7 @@ public class SeleneseTest { return this; case "assertTextPresent": assertTextPresent(param1); + return this; case "assertTextNotPresent": assertTextNotPresent(param1); return this; @@ -134,7 +136,7 @@ public class SeleneseTest { assertLocation(param1); return this; case "waitForElementPresent": - waitForElementPresent(param1); + waitForElementPresent(param1, param2); return this; case "waitForVisible": waitForVisible(param1); @@ -148,6 +150,7 @@ public class SeleneseTest { confirm(param1); return this; case "setTimeout": + case "pause": // Ignore return this; } @@ -179,7 +182,7 @@ public class SeleneseTest { private LazyDomElement find(String selector) { selector = replacePlaceholders(selector); - if (selector.startsWith("link=")) { + if (selector.startsWith("link=") || selector.startsWith("Link=")) { return find("a").withText(selector.substring(5)); } @@ -217,7 +220,7 @@ public class SeleneseTest { } System.out.println(" - selectFrame(" + id + ")"); - _5_SECONDS.execute(new Runnable() { + _30_SECONDS.execute(new Runnable() { @Override public void run() { driver.switchTo().frame(id); @@ -325,8 +328,12 @@ public class SeleneseTest { find("body").should().not().contain(text); } - private void waitForElementPresent(String selector) { - find(selector).should().exist(); + private void waitForElementPresent(String selector, String text) { + if (Strings.isNullOrEmpty(text)) { + find(selector).should().exist(); + } else { + find(selector).withText(text).should().exist(); + } } private void waitForVisible(String selector) { @@ -340,7 +347,7 @@ public class SeleneseTest { private void confirm(final String message) { System.out.println(" - confirm(" + message + ")"); - _5_SECONDS.execute(new Runnable() { + _30_SECONDS.execute(new Runnable() { @Override public void run() { driver.switchTo().alert().accept(); diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html index 1845a5a031d..4dc4d198472 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=History diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html index 9de248da681..e424badc70a 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html @@ -53,6 +53,11 @@ /sonar/dashboard/index/sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Deletion diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-duplicate-keys.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-duplicate-keys.html index 7e3f7a63ec2..b58daa1a5e2 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-duplicate-keys.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-duplicate-keys.html @@ -39,9 +39,9 @@ - waitForElementPresent - link=Update Key - + click + css=#context-navigation .navbar-admin-link + clickAndWait diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-input.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-input.html index 3f925bc2226..e160f298142 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-input.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-input.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Update Key diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-match.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-match.html index 7bd340476d7..f42db7bc348 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-match.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-impossible-because-no-match.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Update Key diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-success.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-success.html index 1a778ecf599..20d7fbbd725 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-success.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/bulk-update-success.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Update Key diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-impossible.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-impossible.html index c4191f938b9..7bf565c8221 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-impossible.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-impossible.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Update Key diff --git a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-success.html b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-success.html index aaa1d9929f3..eff5373a8c6 100644 --- a/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-success.html +++ b/it/it-tests/src/test/resources/administration/suite/ProjectAdministrationTest/project-update-keys/fine-grained-update-success.html @@ -38,6 +38,11 @@ /sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample + + click + css=#context-navigation .navbar-admin-link + + waitForElementPresent link=Update Key -- 2.39.5