Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Restore JSON deserialization behaviour.
- Handle text (and similar) input elements which only become visible when interacted with.

## [0.35.0] - 2025-12-22
### Removed
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/zaproxy/zest/core/v1/ZestClientElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.zaproxy.zest.impl.ZestUtils;

/** An abstract class representing an action on a client element. */
public abstract class ZestClientElement extends ZestClient {
Expand Down Expand Up @@ -90,15 +91,24 @@ public WebElement getWebElement(ZestRuntime runtime) throws ZestClientFailExcept

if (this.waitForMsec > 0) {
WebDriverWait wait = new WebDriverWait(wd, Duration.ofMillis(waitForMsec));
return wait.until(getExpectedCondition(by));
try {
return wait.until(getExpectedCondition(by));
} catch (Exception e) {
Comment thread
psiinon marked this conversation as resolved.
// Ignore, as some frameworks keep elements hidden until you act on them
return ZestUtils.withoutImplicitWait(wd, () -> findElement(wd, by));
}
}
return wd.findElement(by);
return findElement(wd, by);

} catch (Exception e) {
throw new ZestClientFailException(this, e);
}
}

private WebElement findElement(WebDriver wd, By by) {
return wd.findElement(by);
}

/**
* Gets the excepted condition to wait for the element.
*
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/zaproxy/zest/impl/ZestBasicRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -617,7 +615,7 @@ public boolean isDebug() {
@Override
public void addWebDriver(String handle, WebDriver wd) {
webDriverMap.put(handle, wd);
wd.manage().timeouts().implicitlyWait(Duration.of(10, ChronoUnit.SECONDS));
ZestUtils.turnOnImplicitWait(wd);
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/zaproxy/zest/impl/ZestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
package org.zaproxy.zest.impl;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;
import org.openqa.selenium.WebDriver;
import org.zaproxy.zest.core.v1.ZestResponse;

public class ZestUtils {

private static final int DEFAULT_IMPLICIT_WAIT_SECONDS = 10;

public static List<String> getForms(ZestResponse response) {
List<String> list = new ArrayList<>();
Source src = new Source(response.getHeaders() + response.getBody());
Expand Down Expand Up @@ -49,4 +55,23 @@ public static List<String> getFields(ZestResponse response, int formId) {
}
return list;
}

public static void turnOffImplicitWait(WebDriver wd) {
wd.manage().timeouts().implicitlyWait(Duration.of(0, ChronoUnit.SECONDS));
}

public static void turnOnImplicitWait(WebDriver wd) {
wd.manage()
.timeouts()
.implicitlyWait(Duration.of(DEFAULT_IMPLICIT_WAIT_SECONDS, ChronoUnit.SECONDS));
}

public static <T> T withoutImplicitWait(WebDriver wd, Supplier<? extends T> function) {
turnOffImplicitWait(wd);
try {
return function.get();
} finally {
turnOnImplicitWait(wd);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -226,12 +227,13 @@ protected Response serve(IHTTPSession session) {
ZestClientFailException ex =
assertThrows(ZestClientFailException.class, () -> runner.run(script, null));
assertThat(ex)
.hasMessageContaining(
"Expected condition failed: waiting for element found by By.id: test-submit to be clickable");
.message()
.contains("org.openqa.selenium.NoSuchElementException: Unable to locate element:")
.contains("test-submit");
}

@Test
void shouldFailIfElementEnabledAfterWaiting() {
void shouldSubmitDisabledElementWhenClickableWaitFailsButElementInDom() throws Exception {
// Given
server.addHandler(
new NanoServerHandler(PATH_SERVER_FILE) {
Expand All @@ -249,25 +251,13 @@ protected Response serve(IHTTPSession session) {
});
ZestScript script = new ZestScript();
runner = new ZestBasicRunner();
TestClientLaunch clientLaunch =
new TestClientLaunch(
"windowHandle",
"""
setTimeout(() => {
document.getElementById("test-submit").disabled = false;
}, "10000");
""");
script.add(clientLaunch);
script.add(new ZestClientLaunch("windowHandle", "firefox", getServerUrl(PATH_SERVER_FILE)));
script.add(
newZestClientElementSubmit(
"windowHandle", "id", "test-submit", (int) TimeUnit.SECONDS.toMillis(5)));

// When / Then
ZestClientFailException ex =
assertThrows(ZestClientFailException.class, () -> runner.run(script, null));
assertThat(ex)
.hasMessageContaining(
"Expected condition failed: waiting for element found by By.id: test-submit to be clickable");
assertDoesNotThrow(() -> runner.run(script, null));
}

@Test
Expand Down
Loading