-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a helper to check for JS exceptions
Essential for add-on testing
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package firitin.pw; | ||
|
||
import com.microsoft.playwright.Browser; | ||
import com.microsoft.playwright.BrowserType; | ||
import com.microsoft.playwright.Page; | ||
import com.microsoft.playwright.Playwright; | ||
import in.virit.mopo.Mopo; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Tag("playwright") | ||
public class AddonHelpersIT { | ||
private final int port = 9998; | ||
|
||
static Playwright playwright = Playwright.create(); | ||
|
||
static { | ||
} | ||
|
||
private Browser browser; | ||
private Page page; | ||
private Mopo mopo; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
browser = playwright.chromium() | ||
.launch(new BrowserType.LaunchOptions() | ||
.setHeadless(false) | ||
.setDevtools(true) | ||
); | ||
|
||
page = browser.newPage(); | ||
page.setDefaultTimeout(5000); // die faster if needed | ||
mopo = new Mopo(page); | ||
} | ||
|
||
@AfterEach | ||
public void closePlaywright() { | ||
page.close(); | ||
browser.close(); | ||
} | ||
|
||
@Test | ||
public void doRandomStuffAndChangeFirstRow() throws InterruptedException { | ||
page.navigate("http://localhost:" + port + "/addonhelpers"); | ||
|
||
// There should be a JS error in the dev console, assert that | ||
mopo.assertNoJsErrors(); | ||
|
||
page.getByText("Throw JS exception").click(); | ||
|
||
boolean exceptionThrown = false; | ||
try { | ||
mopo.assertNoJsErrors(); | ||
} catch (java.lang.AssertionError e) { | ||
// Expected | ||
System.out.println(e.getMessage()); | ||
exceptionThrown = true; | ||
} | ||
assertTrue(exceptionThrown); | ||
assertThat(page.locator("vaadin-dev-tools>div.error")).isAttached(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package firitin.ui; | ||
|
||
import com.vaadin.flow.component.button.Button; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route | ||
public class AddOnHelpersView extends VerticalLayout { | ||
|
||
public AddOnHelpersView() { | ||
add("Test view"); | ||
|
||
add(new Button("Throw JS exception", e -> { | ||
// deliberately cause a JS exception | ||
getElement().executeJs("window.foo();"); | ||
})); | ||
} | ||
} |