Skip to content

Commit

Permalink
More helpers for add-ons
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Nov 17, 2023
1 parent 60caf09 commit 1dfcf8c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
58 changes: 44 additions & 14 deletions src/main/java/in/virit/mopo/Mopo.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package in.virit.mopo;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.assertions.PlaywrightAssertions;

import java.util.ArrayList;
import java.util.List;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.setDefaultAssertionTimeout;

/**
* General utilities for Playwright & Vaadin.
Expand All @@ -19,10 +20,6 @@ public Mopo(Page page) {
this.page = page;
}

public void waitForConnectionToSettle() {
waitForConnectionToSettle(page);
}

public static void waitForConnectionToSettle(Page page) {
// Default to be bit larger than the defaults for lazy value change events
int minWait = 500;
Expand All @@ -43,13 +40,6 @@ public static void waitForConnectionToSettle(Page page, int minWait) {

}

/**
* Asserts that there are no JS errors in the dev console.
*/
public void assertNoJsErrors() {
assertNoJsErrors(page);
}

/**
* Asserts that there are no JS errors in the dev console.
*/
Expand All @@ -69,4 +59,44 @@ public static void assertNoJsErrors(Page page) {
return;
}
}

public void waitForConnectionToSettle() {
waitForConnectionToSettle(page);
}

/**
* Asserts that there are no JS errors in the dev console.
*/
public void assertNoJsErrors() {
assertNoJsErrors(page);
}

public List<String> getDevelopmentTimeViewNames(Browser browser, Page page) {
List<String> urls = new ArrayList<>();

String url = page.url();
String substring = url.substring(0, url.lastIndexOf("/"));
String temp = substring + "/kjhgfhjkhgb";
Page page1 = browser.newPage();
page1.navigate(temp);

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

page1.waitForSelector("#outlet a");

List<ElementHandle> anchors = page1.locator("#outlet a").elementHandles();
for (ElementHandle anchor : anchors) {
String href = anchor.getAttribute("href");
if (href != null) {
urls.add(substring + "/" + href);
}
}

page1.close();
return urls;
}
}
14 changes: 13 additions & 1 deletion src/test/java/firitin/pw/AddonHelpersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.List;

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")
Expand Down Expand Up @@ -66,4 +67,15 @@ public void doRandomStuffAndChangeFirstRow() throws InterruptedException {
assertTrue(exceptionThrown);
assertThat(page.locator("vaadin-dev-tools>div.error")).isAttached();
}


@Test
public void listView() {
page.navigate("http://localhost:" + port + "/addonhelpers");

// One could now open each of these and e.g. check for not JS errors
List<String> developmentTimeViewNames = mopo.getDevelopmentTimeViewNames(browser, page);
developmentTimeViewNames.forEach(System.out::println);

}
}

0 comments on commit 1dfcf8c

Please sign in to comment.