diff --git a/packages/appium-tizen-tv-driver/README.md b/packages/appium-tizen-tv-driver/README.md index 306dde19..6edf9aac 100644 --- a/packages/appium-tizen-tv-driver/README.md +++ b/packages/appium-tizen-tv-driver/README.md @@ -54,7 +54,7 @@ package in your `package.json`) | `appium:automationName` | _[Required]_ Must be `TizenTV` | | `appium:deviceName` | _[Required]_ This capability can technically be any string, but if you set it to `:`, then you don't need to include the `appium:udid` or `appium:deviceAddress` capabilities. E.g.: `127.0.0.1:26101`| | `appium:chromedriverExecutable` | _[Required*]_ Most Tizen TVs run a very old version of Chrome. Because this driver uses Chromedriver under the hood, you'll need to have a very old version of Chromedriver handy that works with the version of Chrome backing the apps on your TV. In our testing, we've found Chromedriver 2.36 to work with most TVs. You need to tell the driver where you've installed this version of Chromedriver using the `appium:chromedriverExecutable` capability, passing in an absolute path to the Chromedriver binary. | -| `appium:chromedriverExecutableDir` | _[Required*]_ Full path to the folder where chromedriver executables are located. This folder is used then to store the downloaded chromedriver executables if automatic download is enabled with `chromedriver_autodownload` security flag. Please read [Automatic Discovery of Compatible Chromedriver in appium-uiautomator2-driver](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#automatic-discovery-of-compatible-chromedriver) for more details. | +| `appium:chromedriverExecutableDir` | _[Required*]_ Full path to the folder where chromedriver executables are located. This folder is used then to store the downloaded chromedriver executables if automatic download is enabled with `chromedriver_autodownload` security flag. Please read [Automatic Discovery of Compatible Chromedriver in appium-uiautomator2-driver](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#automatic-discovery-of-compatible-chromedriver) for more details. If the chrome version on the TV is lower than v63 major version, the using chrome version will be `Chrome/63.0.3239.0` forcefully to use chromedriver 2.36 for the session. Lower chromedriver could raise `cannot find Chrome binary` error, which prevent starting chromedriver session. | | `appium:deviceAddress` | The IP address on the local network of the TV you want to automate. This capability is required if the equivalent information is not found in `appium:deviceName`| | `appium:udid` | The device ID as returned by `sdb devices`. This capability is required if the equivalent information is not found in `appium:deviceName`| | `appium:app` | An absolute path to your `.wgt` app file, if you want Appium to install the app. | diff --git a/packages/appium-tizen-tv-driver/lib/driver.js b/packages/appium-tizen-tv-driver/lib/driver.js index 778bcf4f..1a2a5b2b 100644 --- a/packages/appium-tizen-tv-driver/lib/driver.js +++ b/packages/appium-tizen-tv-driver/lib/driver.js @@ -29,6 +29,19 @@ const DEFAULT_APP_LAUNCH_CANDIDATES = [ const DEFAULT_APP_LAUNCH_COOLDOWN = 3000; +/** + * To get chrome version from the browser info. + */ +const VERSION_PATTERN = /([\d.]+)/; + +/** + * Minimal chrome browser for autodownload. + * Chromedriver for older than this chrome version could have an issue + * to raise no chrome binary error. + */ +const MIN_CHROME_MAJOR_VERSION = 63; +const MIN_CHROME_VERSION = 'Chrome/63.0.3239.0'; + /** @type {Pick} */ const DEFAULT_CAPS = { appLaunchCooldown: DEFAULT_APP_LAUNCH_COOLDOWN, @@ -421,6 +434,42 @@ class TizenTVDriver extends BaseDriver { return localDebugPort; } + /** + * @typedef BrowserVersionInfo + * @property {string} Browser + * @property {string} Protocol-Version + * @property {string} User-Agent + * @property {string} WebKit-Version + * @property {string} [V8-Version] + * @property {string} [webSocketDebuggerUrl] + */ + + /** + * Set chrome version v63.0.3239.0 as the minimal version + * for autodownload to use proper chromedriver version. + * Older than the chromedriver version could raise no Chrome binary found error, + * which no makes sense for TV automation usage. + * + * @param {BrowserVersionInfo} browserVersionInfo + * @return {BrowserVersionInfo} + */ + fixChromeVersionForAutodownload(browserVersionInfo) { + const chromeVersion = VERSION_PATTERN.exec(browserVersionInfo.Browser ?? ''); + if (!chromeVersion) { + return browserVersionInfo; + } + + const majorV = chromeVersion[1].split('.')[0]; + if (_.toInteger(majorV) < MIN_CHROME_MAJOR_VERSION) { + log.info(`The device chrome version is ${chromeVersion[1]}, ` + + `which could cause an issue for the matched chromedriver version. ` + + `Setting ${MIN_CHROME_VERSION} as browser forcefully`); + browserVersionInfo.Browser = MIN_CHROME_VERSION; + } + + return browserVersionInfo; + } + /** * * @param {StartChromedriverOptions} opts @@ -435,6 +484,7 @@ class TizenTVDriver extends BaseDriver { try { result = await got.get(`http://${debuggerAddress}/json/version`).json(); log.info(`The response of http://${debuggerAddress}/json/version was ${JSON.stringify(result)}`); + result = this.fixChromeVersionForAutodownload(result); // To respect the executableDir. executable = undefined; } catch (err) { diff --git a/packages/appium-tizen-tv-driver/test/unit/driver.spec.js b/packages/appium-tizen-tv-driver/test/unit/driver.spec.js index 3d4222d4..5b05841e 100644 --- a/packages/appium-tizen-tv-driver/test/unit/driver.spec.js +++ b/packages/appium-tizen-tv-driver/test/unit/driver.spec.js @@ -46,11 +46,11 @@ describe('TizenTVDriver', function () { }); describe('instance method', function () { + /** @type {InstanceType} */ + let driver; + describe('setValue()', function () { describe('when configured to use the RC', function () { - /** @type {InstanceType} */ - let driver; - beforeEach(async function () { driver = new TizenTVDriver(); await driver.createSession({ @@ -82,5 +82,46 @@ describe('TizenTVDriver', function () { }); }); }); + + describe('fixChromeVersionForAutodownload', function () { + beforeEach(async function () { + driver = new TizenTVDriver(); + }); + + it('Set minimal chrome version', function () { + const browserInfo = { + 'Browser': 'Chrome/56.0.2924.0', + 'Protocol-Version': '1.2', + 'User-Agent': 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 4.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 TV Safari/537.36', + 'WebKit-Version': '537.36 (@24d4006dbb9188e920764a35a60873d6a0157c12)' + }; + expect( + driver.fixChromeVersionForAutodownload(browserInfo), + 'to equal', + { + 'Browser': 'Chrome/63.0.3239.0', + 'Protocol-Version': '1.2', + 'User-Agent': 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 4.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 TV Safari/537.36', + 'WebKit-Version': '537.36 (@24d4006dbb9188e920764a35a60873d6a0157c12)' + } + ); + }); + + it('Use the given chrome version', function () { + const browserInfo = { + 'Browser': 'Chrome/63.0.3239.0', + 'Protocol-Version': '1.2', + 'User-Agent': 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/5.0 TV Safari/537.36', + 'V8-Version': '6.3.294', + 'WebKit-Version': '537.36 (@0ced44f6f658d59a57d436f1a95308d722d235e9)', + 'webSocketDebuggerUrl': 'ws://127.0.0.1:35645/devtools/browser/7381318c-0c82-4453-a0e9-a0ecbf486254' + }; + expect( + driver.fixChromeVersionForAutodownload(browserInfo), + 'to equal', + browserInfo + ); + }); + }); }); });