Skip to content

Commit ad5db80

Browse files
committed
fix locator assertions tests
1 parent cf08bf6 commit ad5db80

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/AssertionsBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ void expectImpl(String expression, List<ExpectedTextValue> expectedText, Object
4747
options = new FrameExpectOptions();
4848
}
4949
options.expectedText = expectedText;
50-
options.isNot = isNot;
5150
expectImpl(expression, options, expected, message);
5251
}
5352

5453
void expectImpl(String expression, FrameExpectOptions expectOptions, Object expected, String message) {
5554
if (expectOptions.timeout == null) {
5655
expectOptions.timeout = AssertionsTimeout.defaultTimeout;
5756
}
58-
if (expectOptions.isNot) {
57+
expectOptions.isNot = isNot;
58+
if (isNot) {
5959
message = message.replace("expected to", "expected not to");
6060
}
6161
FrameExpectResult result = actualLocator.expect(expression, expectOptions);
6262
if (result.matches == isNot) {
6363
Object actual = result.received == null ? null : Serialization.deserialize(result.received);
64-
String log = String.join("\n", result.log);
64+
String log = (result.log == null) ? "" : String.join("\n", result.log);
6565
if (!log.isEmpty()) {
6666
log = "\nCall log:\n" + log;
6767
}

playwright/src/test/java/com/microsoft/playwright/TestLocatorAssertions.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.microsoft.playwright.assertions.PlaywrightAssertions;
2121
import org.junit.jupiter.api.Test;
2222
import org.opentest4j.AssertionFailedError;
23+
import org.opentest4j.ValueWrapper;
2324

2425
import java.util.regex.Pattern;
2526

@@ -656,9 +657,9 @@ void isCheckedFail() {
656657
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> {
657658
assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setTimeout(1000));
658659
});
659-
assertNull(e.getExpected());
660-
assertNull(e.getActual());
661-
assertTrue(e.getMessage().contains("Locator expected to be checked"), e.getMessage());
660+
assertEquals("checked", e.getExpected().getStringRepresentation());
661+
assertEquals("unchecked", e.getActual().getStringRepresentation());
662+
assertTrue(e.getMessage().contains("Locator expected to be: checked"), e.getMessage());
662663
}
663664

664665
@Test
@@ -668,9 +669,10 @@ void notIsCheckedFail() {
668669
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> {
669670
assertThat(locator).not().isChecked(new LocatorAssertions.IsCheckedOptions().setTimeout(1000));
670671
});
671-
assertNull(e.getExpected());
672-
assertNull(e.getActual());
673-
assertTrue(e.getMessage().contains("Locator expected not to be checked"), e.getMessage());
672+
673+
assertEquals("checked", e.getExpected().getStringRepresentation());
674+
assertEquals("checked", e.getActual().getStringRepresentation());
675+
assertTrue(e.getMessage().contains("Locator expected not to be: checked"), e.getMessage());
674676
}
675677

676678
@Test
@@ -686,7 +688,7 @@ void isCheckedFalseFail() {
686688
Locator locator = page.locator("input");
687689
AssertionFailedError error = assertThrows(AssertionFailedError.class,
688690
() -> assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setChecked(false).setTimeout(1000)));
689-
assertTrue(error.getMessage().contains("Locator expected to be unchecked"), error.getMessage());
691+
assertTrue(error.getMessage().contains("Locator expected to be: unchecked"), error.getMessage());
690692
}
691693

692694
@Test

0 commit comments

Comments
 (0)