### Install Playwright Browser Binaries Source: https://github.com/coreyti/playwright-elixir/blob/main/man/basics/getting-started.md Execute this Mix task to download and install the necessary browser binaries required by Playwright to function. This ensures Playwright can control browsers like Chromium, Firefox, and WebKit. ```bash $ mix playwright.install ``` -------------------------------- ### Launch Browser and Navigate Web Page in Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/man/basics/getting-started.md This example demonstrates the basic usage of Playwright in Elixir. It shows how to launch a browser, create a new page, navigate to a URL, retrieve the page title, and close the browser. It requires the Playwright library to be installed. ```elixir {:ok, browser} = Playwright.launch(:chromium) page = browser |> Playwright.Browser.new_page() page |> Playwright.Page.goto("http://example.com") page |> Playwright.Page.title() |> IO.puts() browser |> Playwright.Browser.close() ``` -------------------------------- ### Add Playwright Dependency to mix.exs Source: https://github.com/coreyti/playwright-elixir/blob/main/man/basics/getting-started.md This snippet shows how to add the Playwright Elixir package to your project's dependencies in the `mix.exs` file. Ensure you have the correct version specified. ```elixir def deps do [ {:playwright, "~> 1.18.0-alpha.1"} ] end ``` -------------------------------- ### Start Playwright Browser and Navigate in Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to initialize Playwright, launch a browser, create a new page, and navigate to a specific URL using Elixir. It requires the Playwright library to be installed. ```elixir Application.ensure_all_started(:playwright) {:ok, _browser} = Playwright.Browser.launch() {:ok, page} = Playwright.Browser.new_page(browser) Playwright.Page.goto(page, "https://example.com") ``` -------------------------------- ### Launching a Browser with Playwright Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This code example shows how to launch a browser instance using Playwright in Elixir. It demonstrates starting a browser and navigating to a specified URL. This is a fundamental step for any browser automation task. ```elixir iex(1)> {:ok, browser} = Playwright.Browser.launch() {:ok, %Playwright.Browser{driver: %Playwright.Driver{pid: #PID<0.178.0>}}} iex(2)> {:ok, page} = Playwright.Browser.new_page(browser) {:ok, %Playwright.Page{driver: %Playwright.Driver{pid: #PID<0.178.0>}, id: "page1"}} iex(3)> Playwright.Page.goto(page, "https://example.com") :ok ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Install Playwright and Browsers (npm) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright/README.md Installs Playwright as a development dependency and downloads all supported browsers. Alternatively, specific browsers can be installed, or existing browser channels can be used. ```shell npm i -D @playwright/test # install supported browsers npx playwright install ``` -------------------------------- ### Elixir Playwright Initialization and Basic Navigation Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to initialize Playwright within an Elixir project and perform basic browser navigation, such as launching a browser and opening a URL. It highlights the core setup required to start using Playwright for automation tasks. ```elixir Application.ensure_all_started(:playwright) {:ok, browser} = Playwright.Browser.launch("chromium") {:ok, page} = Playwright.Browser.new_page(browser) Playwright.Page.goto(page, "https://www.example.com") IO.puts("Page loaded successfully!") # Close the browser Playwright.Browser.close(browser) ``` -------------------------------- ### Initialize Playwright Project (npm) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright/README.md Initializes a new Playwright project or adds Playwright to an existing one. This command sets up the configuration file, example tests, and a GitHub Actions workflow. ```shell # Run from your project's root directory npm init playwright@latest # Or create a new project npm init playwright@latest new-project ``` -------------------------------- ### Setting up Playwright Elixir Project Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to set up a new Elixir project using Playwright. It involves adding Playwright as a dependency and initializing it within your application. Ensure you have Elixir and Erlang installed. ```elixir def deps do [ {:playwright, "~> 0.1.0"} ] end defp application do [applications: [:playwright]] end ``` -------------------------------- ### Install Playwright Browsers (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Installs the necessary Playwright browser binaries and drivers for Elixir. This is a prerequisite for running Playwright tests. It ensures that Playwright has access to the browsers it needs to automate. ```elixir mix playwright.install ``` -------------------------------- ### Elixir: Launching a browser with Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Demonstrates how to launch a browser instance using Playwright in Elixir. This is a fundamental step for any web automation task. It requires the Playwright library to be installed. ```elixir iex(1)> {:ok, browser} = Playwright.Browser.launch() {:ok, %Playwright.Browser{channel: :chromium}} iex(2)> Playwright.Browser.close(browser) :ok ``` -------------------------------- ### Untitled No description -------------------------------- ### Playwright Elixir Setup and Basic Usage Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to set up and use Playwright within an Elixir project. It covers initializing Playwright, launching a browser, creating a new page, navigating to a URL, and interacting with elements. ```elixir iex(1)> {:ok, _pid} = Playwright.start_link() {:ok, #PID<0.168.0>} i ex(2)> {:ok, browser} = Playwright.chromium() {:ok, %Playwright.Browser{handle: "browser_13154723345550050287"}} i ex(3)> {:ok, page} = Playwright.Browser.new_page(browser) {:ok, %Playwright.Page{handle: "page_13154723345550430952"}} i ex(4)> Playwright.Page.goto(page, "https://example.com") {:ok, %Playwright.Response{}} i ex(5)> Playwright.Page.title(page) {:ok, "Example Domain"} i ex(6)> Playwright.Browser.close(browser) :ok ``` -------------------------------- ### Launch Browser and Navigate with Playwright Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to launch a new browser instance and navigate to a specific URL using Playwright in Elixir. It assumes Playwright is installed and configured. ```elixir iex> {:ok, _browser} = Playwright.Browser.launch() iex> {:ok, page} = Playwright.Browser.new_page(browser) iex> Playwright.Page.goto(page, "https://example.com") ``` -------------------------------- ### React Component Mounting and Setup Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Sets up a component instance during the mounting phase. It assigns props and state, resolves context, and calls lifecycle methods such as `componentWillMount` and `componentDidMount`. This is a critical step in rendering a component for the first time. ```javascript function ss(e,t,n,r){var i=e.stateNode;i.props=n,i.state=e.memoizedState,i.refs=ad,ua(e);var l=t.contextType;typeof l=="object"&&l!==null?i.context=Ge(l):(l=Pe(t)?pn:we.current,i.context=Kn(e,l)),i.state=e.memoizedState,l=t.getDerivedStateFromProps,typeof l=="function"&&(os(e,t,l,n),i.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof i.getSnapshotBeforeUpdate=="function"||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(t=i.state,typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount(),t!==i.state&&Sl.enqueueReplaceState(i,i.state,null),il(e,n,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)} ``` -------------------------------- ### Elixir Playwright: Basic Browser Launch and Navigation Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to initialize Playwright in Elixir, launch a browser instance, create a new page, and navigate to a specified URL. It requires the Playwright Elixir library to be installed and configured. ```elixir iex> {:ok, _browser} = Playwright.launch() {:ok, %Playwright.Browser{}} iex> {:ok, page} = Playwright.Browser.new_page(browser) {:ok, %Playwright.Page{}} iex> Playwright.Page.goto(page, "https://example.com") :ok ``` -------------------------------- ### Root Container Handling (React-like) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet shows the handling of the root container for the application. It includes logic for initial setup and updates, ensuring the container's information is correctly managed. ```javascript case 4:return qn(),ps(e,t),e===null&&Ur(t.stateNode.containerInfo),ve(t),null; ``` -------------------------------- ### Elixir Playwright Browser Launch and Navigation Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to launch a browser instance, navigate to a specific URL, and close the browser using Playwright in Elixir. It requires the Playwright library to be installed and configured. ```elixir alias Playwright.Sync.BrowserType browser = BrowserType.launch() page = browser |> BrowserType.new_page() page |> Playwright.Sync.Page.goto("https://example.com") # Further actions with the page can be performed here browser |> BrowserType.close() ``` -------------------------------- ### Elixir: Navigating to a URL with Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Shows how to open a new browser context and navigate to a specific URL using Playwright in Elixir. This involves launching a browser, creating a new page, and then navigating. Ensure Playwright is installed. ```elixir iex(1)> {:ok, browser} = Playwright.Browser.launch() {:ok, %Playwright.Browser{channel: :chromium}} iex(2)> {:ok, page} = Playwright.Browser.new_page(browser) {:ok, %Playwright.Page{}} iex(3)> Playwright.Page.goto(page, "https://www.google.com") %{status: 200, url: "https://www.google.com/"} iex(4)> Playwright.Browser.close(browser) :ok ``` -------------------------------- ### Untitled No description -------------------------------- ### Get Page Title and Content in Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This code example shows how to retrieve the title and the text content of the body element from a webpage using Playwright in Elixir. It assumes a page object has already been created and navigated. ```elixir title = Playwright.Page.title(page) body_text = Playwright.Page.text(page, "body") IO.puts("Page title: #{title}") IO.puts("Body text: #{body_text}") ``` -------------------------------- ### Interact with Input Fields in Elixir using Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This example shows how to locate an input field, fill it with text, and retrieve its value using Playwright in Elixir. It's useful for form submissions and data entry simulations. Assumes Playwright Elixir library is installed. ```elixir Mix.install([:playwright]) {:ok, browser} = Playwright.launch() {:ok, page} = Browser.new_page(browser) Page.goto(page, "https://example.com") # Replace with a page with an input field # Assuming an input field with id 'my-input' {:ok, _} = Page.fill(page, "#my-input", "Hello Playwright") {:ok, value} = Page.input_value(page, "#my-input") IO.puts("Input value: #{value}") Browser.close(browser) ``` -------------------------------- ### Initialize Playwright and Launch Browser (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet shows how to initialize Playwright and launch a browser instance in Elixir. It covers setting up the Playwright context and opening a new browser. No external dependencies beyond the Playwright Elixir library are required. ```elixir iex> {:ok, playwright} = Playwright.start() {:ok, %Playwright{}} iex> {:ok, browser} = Playwright.chromium(playwright) {:ok, %Browser{}} iex> {:ok, page} = Browser.new_page(browser) {:ok, %Page{}} ``` -------------------------------- ### Install fsevents using npm Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/fsevents/README.md This command installs the fsevents package using npm. It supports Node.js v8.16 and higher. ```sh npm install fsevents ``` -------------------------------- ### Get Element Text (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Retrieves the inner text of an element identified by a selector. Useful for assertions or extracting data from the page. ```elixir iex(8)> Playwright.Page.inner_text(page, "h1") "Example Domain" ``` -------------------------------- ### Untitled No description -------------------------------- ### Get Page Title (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Retrieves the title of the current web page. This is useful for verifying page content or for logging purposes. ```elixir iex(4)> Playwright.Page.title(page) "Example Domain" ``` -------------------------------- ### Get Text Content of an Element in Elixir with Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Shows how to select an element and retrieve its text content. This is useful for assertions and extracting information from a web page. ```elixir iex> {:ok, text} = Playwright.Page.inner_text(page, "h1") {:ok, "Welcome!"} ``` -------------------------------- ### Elixir Code Snippet for Playwright Test Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This snippet demonstrates how to use Playwright with Elixir to interact with a web page. It includes setup, navigation, and element interaction. ```elixir Mix.Task.run("deps.get") Application.ensure_all_started(:playwright) {:ok, browser} = Playwright.Browser.launch() {:ok, page} = Playwright.Browser.new_page(browser) case Playwright.Page.goto(page, "https://example.com") do {:ok, _response} -> IO.puts "Successfully navigated to example.com" {:error, reason} -> IO.puts "Navigation failed: #{inspect(reason)}" end case Playwright.Browser.close(browser) do :ok -> IO.puts "Browser closed successfully" {:error, reason} -> IO.puts "Failed to close browser: #{inspect(reason)}" end ``` -------------------------------- ### Initialize Playwright with Browser Types and Devices Source: https://github.com/coreyti/playwright-elixir/blob/main/test/support/fixtures/reference.txt This comprehensive JSON object initializes the main Playwright instance. It links the previously created browser types and includes a detailed list of device descriptors for mobile emulation. ```json {"guid":"","method":"__create__","params":{"type":"Playwright","initializer":{"chromium":{"guid":"browser-type@539de53f7eedd550f0ef6a5b2122c0c7"},"firefox":{"guid":"browser-type@2eadb5e660083383945f0bad441bb79e"},"webkit":{"guid":"browser-type@51c303c0045951cda28ff18c616898dd"},"android":{"guid":"android@e70cdf86b013e68909e9e7b3ca2e4146"},"electron":{"guid":"electron@993bbd30f0bf86d4d72d5dc4493e3be8"},"deviceDescriptors":[{"name":"Blackberry PlayBook","descriptor":{"userAgent":"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+","viewport":{"width":600,"height":1024},"deviceScaleFactor":1,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Blackberry PlayBook landscape","descriptor":{"userAgent":"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+","viewport":{"width":1024,"height":600},"deviceScaleFactor":1,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"BlackBerry Z30","descriptor":{"userAgent":"Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+","viewport":{"width":360,"height":640},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"BlackBerry Z30 landscape","descriptor":{"userAgent":"Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+","viewport":{"width":640,"height":360},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy Note 3","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":360,"height":640},"deviceScaleFactor":3,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy Note 3 landscape","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":640,"height":360},"deviceScaleFactor":3,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy Note II","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":360,"height":640},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy Note II landscape","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":640,"height":360},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy S III","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":360,"height":640},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy S III landscape","descriptor":{"userAgent":"Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30","viewport":{"width":640,"height":360},"deviceScaleFactor":2,"isMobile":true,"hasTouch":true,"defaultBrowserType":"webkit"}},{"name":"Galaxy S5","descriptor":{"userAgent":"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile"}}]},"guid":"playwright@9c5f05e0182f282524576c1695230a8f"}} ``` -------------------------------- ### JavaScript Code Snippet for Page Navigation Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html A JavaScript example of using Playwright to navigate to a specific URL and wait for the page to load. Essential for setting up test scenarios. ```javascript await page.goto('https://example.com'); ``` -------------------------------- ### Setting Viewport and Emulating Devices with Playwright Elixir Source: https://context7.com/coreyti/playwright-elixir/llms.txt Demonstrates how to configure the browser viewport size and emulate specific devices using Playwright Elixir. Includes setting viewport dimensions for a page and creating a new browser context with device emulation settings like user agent, scale factor, and touch support. Requires a `browser` instance. ```elixir # Set viewport size page = Playwright.Browser.new_page(browser) Playwright.Page.set_viewport_size(page, %{width: 1920, height: 1080}) # Create context with device emulation context = Playwright.Browser.new_context(browser, %{ viewport: %{width: 375, height: 667}, user_agent: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)", device_scale_factor: 2, is_mobile: true, has_touch: true }) page = Playwright.BrowserContext.new_page(context) Playwright.Page.goto(page, "https://example.com") ``` -------------------------------- ### Find Signature Marker with Playwright Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Searches for a specific signature marker within a buffer. This is often used to locate the start of zip entries or other data structures. ```typescript async s2(e, t, n, r, i) { const l = new Uint8Array(4), o = ue(l); u2(o, 0, t); const s = r + i; return await a(r) || await a(Math.min(s, n)); async function a(u) { const p = n - u, g = await pe(e, p, u); for (let m = g.length - r; m >= 0; m--) if (g[m] == l[0] && g[m + 1] == l[1] && g[m + 2] == l[2] && g[m + 3] == l[3]) return { offset: p + m, buffer: g.slice(m, m + r).buffer } } } ``` -------------------------------- ### Launch Browser and Navigate Page in Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Demonstrates how to launch a browser instance and navigate to a specific URL using Playwright Elixir. This is a fundamental step for any browser automation task. It requires the `:playwright` dependency. ```elixir iex> {:ok, browser} = Playwright.Browser.launch() {:ok, %Playwright.Browser{}} iex> {:ok, page} = Playwright.Browser.new_page(browser) {:ok, %Playwright.Page{}} iex> Playwright.Page.goto(page, "https://example.com") :ok ``` -------------------------------- ### Untitled No description -------------------------------- ### Get Context from Fiber (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Retrieves the context value from a React Fiber node. It traverses up the Fiber tree to find the nearest context provider and returns its context value. ```elixir function n1(e){if(!e)return Jt; e=e._reactInternals;e:{if(wn(e)!==e||e.tag!==1)throw Error(T(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Pe(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(T(171))} if(e.tag===1){var n=e.type;if(Pe(n))return td(e,n,t)} return t } ``` -------------------------------- ### Untitled No description -------------------------------- ### Launch Browser and Create Page in Elixir with Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Demonstrates how to launch a browser, create a new browser context, and open a new page using Playwright in Elixir. This is a fundamental step for any browser automation task. ```elixir iex> {:ok, browser} = Playwright.Browser.launch() {:ok, %Playwright.Browser{...}} iex> {:ok, context} = Playwright.Browser.new_context(browser) {:ok, %Playwright.BrowserContext{...}} iex> {:ok, page} = Playwright.BrowserContext.new_page(context) {:ok, %Playwright.Page{...}} ``` -------------------------------- ### Initialize Android and Electron Browser Types Source: https://github.com/coreyti/playwright-elixir/blob/main/test/support/fixtures/reference.txt This code snippet initializes both the Android and Electron browser types. These initializations do not require specific executable paths, indicating they use default configurations. ```json {"guid":"","method":"__create__","params":{"type":"Android","initializer":{},"guid":"android@e70cdf86b013e68909e9e7b3ca2e4146"}} ``` ```json {"guid":"","method":"__create__","params":{"type":"Electron","initializer":{},"guid":"electron@993bbd30f0bf86d4d72d5dc4493e3be8"}} ``` -------------------------------- ### Install Playwright Elixir Dependency Source: https://github.com/coreyti/playwright-elixir/blob/main/README.md This snippet shows how to add the Playwright Elixir package to your project's dependencies in the `mix.exs` file. This is the standard method for including Elixir libraries in a project. ```elixir def deps do [ {:playwright, "~> 1.49.1-alpha.2"} ] end ``` -------------------------------- ### Untitled No description -------------------------------- ### Navigate to URL and Get Page Title in Elixir with Playwright Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Shows how to navigate a Playwright page to a specific URL and retrieve the page's title. This is useful for verifying page loads and content. ```elixir iex> {:ok, _response} = Playwright.Page.goto(page, "https://elixir-lang.org") {:ok, %Playwright.Response{...}} iex> Playwright.Page.title(page) "Elixir - A functional, concurrent, general-purpose programming language built on the Erlang VM" ``` -------------------------------- ### Local Storage Management Class Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html A JavaScript class for managing browser local storage. It provides methods to get and set string, JSON objects, and includes an event emitter for change notifications. ```javascript class Em{constructor(){this.onChangeEmitter=new EventTarget}getString(t,n){return localStorage[t]||n}setString(t,n){var r;localStorage[t]=n,this.onChangeEmitter.dispatchEvent(new Event(t)),(r=window.saveSettings)==null||r.call(window)}getObject(t,n){if(!localStorage[t])return n;try{return JSON.parse(localStorage[t])}catch{return n}}setObject(t,n){var r;localStorage[t]=JSON.stringify(n),this.onChangeEmitter.dispatchEvent(new Event(t)),(r=window.saveSettings)==null||r.call(window)}}new Em ``` -------------------------------- ### Launch a Browser Instance (Elixir) Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html Launches a new browser instance using Playwright in Elixir. This is the first step in automating a browser. It returns a browser context that can be used to create pages. ```elixir iex> {:ok, pid} = Playwright.launch() {:ok, #PID<0.198.0>} iex> Process.exit(pid, :normal) :ok ``` -------------------------------- ### Taking a Screenshot with Playwright Elixir Source: https://github.com/coreyti/playwright-elixir/blob/main/priv/static/node_modules/playwright-core/lib/vite/htmlReport/index.html This code example demonstrates how to capture a screenshot of the current page using Playwright in Elixir. It saves the screenshot to a file. This is useful for visual regression testing and debugging. ```elixir iex(6)> Playwright.Page.screenshot(page, path: "example.png") :ok ``` -------------------------------- ### Initialize WebKit Browser Type Source: https://github.com/coreyti/playwright-elixir/blob/main/test/support/fixtures/reference.txt This code snippet initializes the WebKit browser type. It points to a script that likely launches the WebKit browser. ```json {"guid":"","method":"__create__","params":{"type":"BrowserType","initializer":{"executablePath":"/Users/corey/Library/Caches/ms-playwright/webkit-1472/pw_run.sh","name":"webkit"},"guid":"browser-type@51c303c0045951cda28ff18c616898dd"}} ``` -------------------------------- ### Initialize Firefox Browser Type Source: https://github.com/coreyti/playwright-elixir/blob/main/test/support/fixtures/reference.txt This code snippet shows the initialization of the Firefox browser type. It includes the path to the Firefox executable, likely a nightly build. ```json {"guid":"","method":"__create__","params":{"type":"BrowserType","initializer":{"executablePath":"/Users/corey/Library/Caches/ms-playwright/firefox-1250/firefox/Nightly.app/Contents/MacOS/firefox","name":"firefox"},"guid":"browser-type@2eadb5e660083383945f0bad441bb79e"}} ```