更新WebDriver后Katalon报错:DriverFactory无chromeDriverPath属性
问题描述
本人是Katalon、Groovy新手,Java基础十分薄弱。更新WebDriver后持续遇到如下错误,想咨询:
- 为何会出现该错误?
- 如何修复?
错误信息:
Reason: groovy.lang.MissingPropertyException: No such property: chromeDriverPath for class: com.kms.katalon.core.webui.driver.DriverFactory at utils.Browser.setPreferences(Browser.groovy:107) at utils.Browser.openBrowser(Browser.groovy:39)
相关代码:
public class Browser { private static CommonObjects.NavigationBar NAVIGATION_BAR_OBJECTS = new CommonObjects.NavigationBar() public static void openBrowser(String url) { new Browser().setPreferences() deleteAllCookies() goTo(url) maximizeWindow() delay(3) String pageTitle = getWindowTitle().trim() logInfo("Navigated to [" + pageTitle + "].") delay(2) } public static void setPreferences() { String downloadPath = ReviewConstants.FolderDirectories.DOWNLOAD KeywordUtil.logInfo("The download path is [" + downloadPath + "].") // The necessary preferences to set. Map<Object, String> prefs = new HashMap<Object, String>() prefs.put("download.default_dictionary", downloadPath) prefs.put("download.direcory_update", true) prefs.put("download.prompt_for_download", false) prefs.put("browser.download.dir", downloadPath) prefs.put("download.default_directory", downloadPath) prefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1) // Allow multiple downloads without prompt KeywordUtil.logInfo("The browser is [" + DriverFactory.getExecutedBrowser().getName() + "].") switch (DriverFactory.getExecutedBrowser().getName()) { case "CHROME_DRIVER" : System.setProperty('webdriver.chrome.driver', DriverFactory.chromeDriverPath) ChromeOptions chromeOptions = new ChromeOptions() chromeOptions.setExperimentalOption("prefs", prefs) DriverFactory.changeWebDriver(new ChromeDriver(chromeOptions)) break default: throw new Exception("Failed to set the preferences. Browser may be incompatible.") } } }
操作背景:已更新WebDriver。
问题解答
1. 错误原因
DriverFactory.chromeDriverPath这个属性在你更新后的Katalon版本中已被移除或更名。Katalon的DriverFactory类会随版本迭代调整API,旧版本对外暴露的该公共属性不再可用,直接访问就会触发“找不到属性”的错误。另外,更新WebDriver后,Katalon自带的驱动管理逻辑已优化,无需手动设置webdriver.chrome.driver系统属性。
2. 修复方法
删掉手动设置系统属性的代码,改用Katalon提供的API初始化带配置的Chrome驱动,同时修正代码里的拼写错误(会导致下载路径配置失效)。修改后的setPreferences方法如下:
public static void setPreferences() { String downloadPath = ReviewConstants.FolderDirectories.DOWNLOAD KeywordUtil.logInfo("The download path is [" + downloadPath + "].") // The necessary preferences to set. Map<Object, String> prefs = new HashMap<Object, String>() // 修正拼写错误:default_dictionary → default_directory prefs.put("download.default_directory", downloadPath) // 修正拼写错误:direcory_update → directory_upgrade prefs.put("download.directory_upgrade", true) prefs.put("download.prompt_for_download", false) prefs.put("browser.download.dir", downloadPath) prefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1) // Allow multiple downloads without prompt KeywordUtil.logInfo("The browser is [" + DriverFactory.getExecutedBrowser().getName() + "].") switch (DriverFactory.getExecutedBrowser().getName()) { case "CHROME_DRIVER" : ChromeOptions chromeOptions = new ChromeOptions() chromeOptions.setExperimentalOption("prefs", prefs) // 用Katalon API创建驱动,自动管理驱动路径 WebDriver driver = DriverFactory.createWebDriver(chromeOptions) DriverFactory.changeWebDriver(driver) break default: throw new Exception("Failed to set the preferences. Browser may be incompatible.") } }
内容的提问来源于stack exchange,提问作者ign.noobshit
相关产品推荐
相关产品推荐

