Created
November 24, 2022 14:01
-
-
Save leofernandesmo/6ea38906b53c6b71cf03decda290a238 to your computer and use it in GitHub Desktop.
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
package br.ufal.edge; | |
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
import org.junit.After; | |
import org.junit.AfterClass; | |
import org.junit.Before; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
import com.microsoft.playwright.Browser; | |
import com.microsoft.playwright.BrowserContext; | |
import com.microsoft.playwright.Page; | |
import com.microsoft.playwright.Playwright; | |
import com.microsoft.playwright.options.AriaRole; | |
public class AppTest { | |
// Shared between all tests in this class. | |
static Playwright playwright; | |
static Browser browser; | |
// New instance for each test method. | |
BrowserContext context; | |
Page page; | |
@BeforeClass | |
public static void launchBrowser() { | |
playwright = Playwright.create(); | |
browser = playwright.chromium().launch(); | |
} | |
@AfterClass | |
public static void closeBrowser() { | |
playwright.close(); | |
} | |
@Before | |
public void createContextAndPage() { | |
context = browser.newContext(); | |
page = context.newPage(); | |
} | |
@After | |
public void closeContext() { | |
context.close(); | |
} | |
@Test | |
public void shouldClickButton() { | |
page.navigate("data:text/html,<script>var result;</script><button onclick='result=\"Clicked\"'>Go</button>"); | |
page.locator("button").click(); | |
assertEquals("Clicked", page.evaluate("result")); | |
} | |
@Test | |
public void shouldCheckTheBox() { | |
page.setContent("<input id='checkbox' type='checkbox'></input>"); | |
page.locator("input").check(); | |
assertTrue((Boolean) page.evaluate("() => window['checkbox'].checked")); | |
} | |
@Test | |
public void shouldSearchWiki() { | |
page.navigate("https://www.wikipedia.org/"); | |
page.locator("input[name=\"search\"]").click(); | |
page.locator("input[name=\"search\"]").fill("playwright"); | |
page.locator("input[name=\"search\"]").press("Enter"); | |
assertEquals("https://en.wikipedia.org/wiki/Playwright", page.url()); | |
} | |
@Test | |
public void sohuldLocalizarCargaCorretamente() { | |
page.navigate("http://localhost:8080/cargo-tracker/"); | |
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Public Tracking Interface")).click(); | |
page.getByTitle("Valid tracking ID").click(); | |
page.getByPlaceholder("XYZ789").fill("ABC123"); | |
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Track!")).click(); | |
assertThat(page.locator("#result")).containsText("Cargo ABC123 is currently In port Helsinki"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment