public class Puppeteer extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Browser |
connect(ConnectOptions options)
建立与浏览器的连接
该方法使用给定的连接选项,通过Puppeteer实例来启动和管理浏览器的连接
browserWSEndpoint、browserURL或者ConnectionTransport至少有一个配置
此外还要指定连接协议 protocol,如果不指定,默认通过cdp连接
browserWSEndpoint的形式是 ws:http://host:port,可通过
Browser.wsEndpoint()获取
browserURL: 类似 localhost:8080
firefox浏览器连接协议 webdriver bidi,chrome浏览器连接协议 cdp |
static RevisionInfo |
downloadBrowser()
下载默认版本的浏览器,默认下载 chrome 浏览器,默认版本配置在
BrowserRevision
本方法负责下载用于自动化测试的浏览器该方法使用Puppeteer类来初始化浏览器Fetcher对象,
并通过该对象下载浏览器到指定的项目根目录下 |
static RevisionInfo |
downloadBrowser(FetcherOptions options)
通过自定义配置选项下载浏览器
根据提供的选项下载浏览器此方法首先检查选项中提供的安装路径是否为空如果为空,
则将其默认设置为当前用户目录然后,创建一个BrowserFetcher对象并使用指定的路径和选项
开始下载过程最后,返回下载的浏览器信息
|
static RevisionInfo |
downloadBrowser(String version)
下载Product#CHROME的某个版本的浏览器
本方法用于下载指定版本的浏览器它首先验证版本号是否有效,然后使用 FetcherOptions 配置下载过程,
最后通过 BrowserFetcher 执行实际的下载操作
|
String |
getCacheDir() |
Product |
getProduct() |
static Browser |
launch()
以默认参数启动浏览器
launch Browser by default options
|
static Browser |
launch(boolean headless) |
static Browser |
launch(LaunchOptions options) |
static Browser |
rawLaunch(LaunchOptions options,
Puppeteer puppeteer)
The method launches a browser instance with given arguments.
|
void |
setCacheDir(String cacheDir) |
void |
setProduct(Product product) |
public static Browser launch() throws IOException
IOException - IO异常public static Browser launch(boolean headless) throws IOException
IOExceptionpublic static Browser launch(LaunchOptions options) throws IOException
IOExceptionpublic static Browser rawLaunch(LaunchOptions options, Puppeteer puppeteer) throws IOException
options - launch options
browserWSEndpoint、browserURL、transport三者至少选一个puppeteer - puppeteer实例IOException - IO异常public static Browser connect(ConnectOptions options) throws Exception
browserWSEndpoint、browserURL或者ConnectionTransport至少有一个配置 此外还要指定连接协议 protocol,如果不指定,默认通过cdp连接
browserWSEndpoint的形式是 ws:http://host:port,可通过Browser.wsEndpoint()获取
browserURL: 类似 localhost:8080
firefox浏览器连接协议 webdriver bidi,chrome浏览器连接协议 cdpoptions - 连接到浏览器所需的配置选项,例如浏览器的browserWSEndpoint、browserURL或者ConnectionTransport等Exception - 如果连接过程中出现错误,将抛出异常public static RevisionInfo downloadBrowser() throws IOException, InterruptedException
BrowserRevision
本方法负责下载用于自动化测试的浏览器该方法使用Puppeteer类来初始化浏览器Fetcher对象, 并通过该对象下载浏览器到指定的项目根目录下
IOException - 如果在下载过程中发生I/O错误InterruptedException - 如果在下载过程中线程被中断public static RevisionInfo downloadBrowser(FetcherOptions options) throws IOException, InterruptedException
根据提供的选项下载浏览器此方法首先检查选项中提供的安装路径是否为空如果为空, 则将其默认设置为当前用户目录然后,创建一个BrowserFetcher对象并使用指定的路径和选项 开始下载过程最后,返回下载的浏览器信息
options - FetcherOptions对象,包含浏览器下载的配置选项IOException - 如果在下载过程中发生I/O错误InterruptedException - 如果在下载过程中线程被中断public static RevisionInfo downloadBrowser(String version) throws IOException, InterruptedException
本方法用于下载指定版本的浏览器它首先验证版本号是否有效,然后使用 FetcherOptions 配置下载过程, 最后通过 BrowserFetcher 执行实际的下载操作
version - 要下载的浏览器版本号版本号不能为空IOException - 如果在下载过程中发生 I/O 错误InterruptedException - 如果在下载过程中线程被中断public String getCacheDir()
public void setCacheDir(String cacheDir)
public Product getProduct()
public void setProduct(Product product)
Copyright © 2020–2025. All rights reserved.