From 3f3d3253a1ff7f806bb6159cd72fc9de9fb7c8ec Mon Sep 17 00:00:00 2001 From: Mohammad Saddam Hossain Date: Tue, 14 Jul 2026 11:29:33 +0530 Subject: [PATCH] docs(recipes): add Recipes section batch 1 (upload, download PDF, iframes, Shadow DOM) Closes #6 Task-titled, copy-pasteable recipe pages under docs/recipes/, matching how people actually search ("selenium upload file") rather than by framework concept. Each is short and links into its underlying guide instead of duplicating it (keeps SEO authority consolidated): - Upload a file -> BasePage.upload(By, path) -> base-page guide - Download & verify a PDF -> DownloadManager.waitForAnyFile -> download-manager guide - Handle iframes -> BasePage.withinFrame -> base-page guide - Handle Shadow DOM -> shadowFind/Click/Type/Pierce -> base-page guide New "Recipes" sidebar category. All snippets verified against the real API (helpers live on BasePage; DownloadManager is static). SEO description frontmatter on all four. Build passes. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../docs/recipes/download-and-verify-a-pdf.md | 53 +++++++++++++++++++ docs-site/docs/recipes/handle-iframes.md | 41 ++++++++++++++ docs-site/docs/recipes/handle-shadow-dom.md | 50 +++++++++++++++++ docs-site/docs/recipes/upload-a-file.md | 39 ++++++++++++++ docs-site/sidebars.js | 10 ++++ 5 files changed, 193 insertions(+) create mode 100644 docs-site/docs/recipes/download-and-verify-a-pdf.md create mode 100644 docs-site/docs/recipes/handle-iframes.md create mode 100644 docs-site/docs/recipes/handle-shadow-dom.md create mode 100644 docs-site/docs/recipes/upload-a-file.md 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 `