Skip to content

Commit

Permalink
Avoid depending on labels, rather use the button name (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe authored Oct 11, 2024
1 parent 854ae6c commit 190f938
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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);
}
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/org/jenkinsci/test/acceptance/po/View.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -114,11 +104,6 @@ public String getFormName() {
return "viewConfig";
}

@Override
public String getSubmitButtonText() {
return "OK";
}

public static Matcher<View> hasDescription(String description) {
return new Matcher<>("Has description " + description) {
@Override
Expand Down

0 comments on commit 190f938

Please sign in to comment.