diff --git a/docs-site/docs/recipes/download-and-verify-a-pdf.md b/docs-site/docs/recipes/download-and-verify-a-pdf.md new file mode 100644 index 0000000..6a1f8de --- /dev/null +++ b/docs-site/docs/recipes/download-and-verify-a-pdf.md @@ -0,0 +1,53 @@ +--- +description: "Download and verify a PDF in Selenium: DownloadManager waits for the file to appear in the download directory, handling partial downloads, so you can assert it exists and is non-empty." +id: download-and-verify-a-pdf +title: Download and verify a PDF +sidebar_label: Download & verify a PDF +--- + +# Download and verify a PDF + +Click a download link, wait for the file to land, and assert it's a real PDF. `DownloadManager` polls the download directory and ignores partial (`.crdownload`) files until they're complete — no `Thread.sleep()`. + +```java title="InvoiceTest.java" +import com.seleniumboot.browser.DownloadManager; +import com.seleniumboot.test.BaseTest; +import java.io.File; +import org.openqa.selenium.By; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class InvoiceTest extends BaseTest { + + @Test + public void downloadsInvoicePdf() { + open("/invoices/123"); + $("#download-pdf").click(); + + // Dynamic filename (timestamped) → wait for any file, up to 15s: + File pdf = DownloadManager.waitForAnyFile(15); + + Assert.assertTrue(pdf.getName().endsWith(".pdf")); + Assert.assertTrue(pdf.length() > 0); // non-empty + } +} +``` + +Known filename? Wait for it by name instead: + +```java +File pdf = DownloadManager.waitForFile("invoice-123.pdf", 15); +``` + +Set the download directory in config (defaults to `./target/downloads`): + +```yaml title="selenium-boot.yml" +browser: + downloadDir: ./target/downloads +``` + +:::tip Clean state between tests +Call `DownloadManager.clearDownloads()` in `@BeforeMethod` so a stale file from a previous run can't satisfy the wait. +::: + +**Deeper reference:** [DownloadManager](/docs/guides/download-manager) — waiting strategies, partial-download handling, and cleanup. diff --git a/docs-site/docs/recipes/handle-iframes.md b/docs-site/docs/recipes/handle-iframes.md new file mode 100644 index 0000000..21cc13c --- /dev/null +++ b/docs-site/docs/recipes/handle-iframes.md @@ -0,0 +1,41 @@ +--- +description: "Handle iframes in Selenium without manual switchTo() bookkeeping: Selenium Boot's withinFrame runs your actions inside the frame and restores the previous context automatically, even when nested." +id: handle-iframes +title: Handle iframes +sidebar_label: Handle iframes +--- + +# Handle iframes + +Interacting with content inside an `