我正在尝试在Selenium脚本中集成灯塔
基本上,每当我的脚本出现在新页面上时,我应该点击灯塔扩展并生成一个报告。
我所能达到的目标是:(最后是示例工作代码)设置所需的功能,通过添加灯塔扩展启动Chrome
我不能做的是:我想使用添加的
样本工作代码:
System.setProperty("webdriver.chrome.driver","C:\\Users\\v744536\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addExtensions(new File("C:\\Users\\v744536\\eclipse-workspace\\AccessibilityProject\\LH.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(ChromeOptions.CAPABILITY, opt);
@SuppressWarnings("deprecation")
ChromeDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com");发布于 2022-03-22 04:07:56
我应该告诉您,灯塔浏览器扩展只是调用PSI,它是免费的,而且很容易直接使用:https://developers.google.com/speed/docs/insights/v5/get-started
扩展将指向一个页面,该页面将使用PSI。如果您不想直接使用PSI API,另一种选择是使用所需的url打开灯塔查看器:
https://googlechrome.github.io/lighthouse/viewer/?psiurl=https://www.example.com
这就是引擎盖下的延伸部分。这将比通过脚本用户交互简单得多。
资料来源:我在灯塔工作。
https://stackoverflow.com/questions/71454824
复制相似问题