From 190f938efc8781423284bfacadad7ecf6e479067 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Fri, 11 Oct 2024 10:35:17 +0200 Subject: [PATCH] Avoid depending on labels, rather use the button name (#1754) --- .../acceptance/po/ConfigurablePageObject.java | 16 ++++++---------- .../org/jenkinsci/test/acceptance/po/View.java | 15 --------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/ConfigurablePageObject.java b/src/main/java/org/jenkinsci/test/acceptance/po/ConfigurablePageObject.java index 31d115a03..2fb4813eb 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/ConfigurablePageObject.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/ConfigurablePageObject.java @@ -45,6 +45,10 @@ * @author ogondza. */ public abstract class ConfigurablePageObject extends PageObject { + + private static final By SAVE_BUTTON = By.xpath( + "//div[contains(@class, 'bottom-sticker-inner')]//input[@type='submit'] | //div[contains(@class, 'bottom-sticker-inner')]//button[contains(@name, 'Submit')]"); + protected ConfigurablePageObject(PageObject context, URL url) { super(context, url); } @@ -109,21 +113,13 @@ public void configure() { visit(getConfigUrl()); } waitFor(By.xpath("//form[contains(@name, '" + getFormName() + "')]"), 10); - waitFor( - By.xpath( - "//div[contains(@class, 'bottom-sticker-inner')]//input[@type='submit'] | //div[contains(@class, 'bottom-sticker-inner')]//button[contains(text(), '" - + getSubmitButtonText() + "')]"), - 5); + waitFor(SAVE_BUTTON, 5); } public String getFormName() { return "config"; } - public String getSubmitButtonText() { - return "Save"; - } - /** * Makes sure that the browser is currently opening the configuration page. */ @@ -135,7 +131,7 @@ public void ensureConfigPage() { public abstract URL getConfigUrl(); public void save() { - WebElement e = find(by.button("Save")); + WebElement e = find(SAVE_BUTTON); e.click(); waitFor(e).until(CapybaraPortingLayerImpl::isStale); } diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/View.java b/src/main/java/org/jenkinsci/test/acceptance/po/View.java index 15d08a552..b0b445a33 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/View.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/View.java @@ -1,9 +1,5 @@ package org.jenkinsci.test.acceptance.po; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; -import static org.jenkinsci.test.acceptance.Matchers.hasContent; - import com.fasterxml.jackson.databind.JsonNode; import com.google.inject.Injector; import java.net.URL; @@ -60,12 +56,6 @@ public void delete() { runThenHandleDialog(() -> clickLink("Delete View")); } - @Override - public void save() { - clickButton("OK"); - assertThat(driver, not(hasContent("This page expects a form submission"))); - } - public BuildHistory getBuildHistory() { return new BuildHistory(this); } @@ -114,11 +104,6 @@ public String getFormName() { return "viewConfig"; } - @Override - public String getSubmitButtonText() { - return "OK"; - } - public static Matcher hasDescription(String description) { return new Matcher<>("Has description " + description) { @Override