diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/AssertionsBase.java b/playwright/src/main/java/com/microsoft/playwright/impl/AssertionsBase.java index 9c00602d..ff348a3d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/AssertionsBase.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/AssertionsBase.java @@ -47,7 +47,6 @@ void expectImpl(String expression, List expectedText, Object options = new FrameExpectOptions(); } options.expectedText = expectedText; - options.isNot = isNot; expectImpl(expression, options, expected, message); } @@ -55,13 +54,14 @@ void expectImpl(String expression, FrameExpectOptions expectOptions, Object expe if (expectOptions.timeout == null) { expectOptions.timeout = AssertionsTimeout.defaultTimeout; } - if (expectOptions.isNot) { + expectOptions.isNot = isNot; + if (isNot) { message = message.replace("expected to", "expected not to"); } FrameExpectResult result = actualLocator.expect(expression, expectOptions); if (result.matches == isNot) { Object actual = result.received == null ? null : Serialization.deserialize(result.received); - String log = String.join("\n", result.log); + String log = (result.log == null) ? "" : String.join("\n", result.log); if (!log.isEmpty()) { log = "\nCall log:\n" + log; } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestLocatorAssertions.java b/playwright/src/test/java/com/microsoft/playwright/TestLocatorAssertions.java index 3a248062..ff7b7c71 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestLocatorAssertions.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestLocatorAssertions.java @@ -20,6 +20,7 @@ import com.microsoft.playwright.assertions.PlaywrightAssertions; import org.junit.jupiter.api.Test; import org.opentest4j.AssertionFailedError; +import org.opentest4j.ValueWrapper; import java.util.regex.Pattern; @@ -656,9 +657,9 @@ void isCheckedFail() { AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> { assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setTimeout(1000)); }); - assertNull(e.getExpected()); - assertNull(e.getActual()); - assertTrue(e.getMessage().contains("Locator expected to be checked"), e.getMessage()); + assertEquals("checked", e.getExpected().getStringRepresentation()); + assertEquals("unchecked", e.getActual().getStringRepresentation()); + assertTrue(e.getMessage().contains("Locator expected to be: checked"), e.getMessage()); } @Test @@ -668,9 +669,10 @@ void notIsCheckedFail() { AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> { assertThat(locator).not().isChecked(new LocatorAssertions.IsCheckedOptions().setTimeout(1000)); }); - assertNull(e.getExpected()); - assertNull(e.getActual()); - assertTrue(e.getMessage().contains("Locator expected not to be checked"), e.getMessage()); + + assertEquals("checked", e.getExpected().getStringRepresentation()); + assertEquals("checked", e.getActual().getStringRepresentation()); + assertTrue(e.getMessage().contains("Locator expected not to be: checked"), e.getMessage()); } @Test @@ -686,7 +688,7 @@ void isCheckedFalseFail() { Locator locator = page.locator("input"); AssertionFailedError error = assertThrows(AssertionFailedError.class, () -> assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setChecked(false).setTimeout(1000))); - assertTrue(error.getMessage().contains("Locator expected to be unchecked"), error.getMessage()); + assertTrue(error.getMessage().contains("Locator expected to be: unchecked"), error.getMessage()); } @Test