Skip to content

Commit 33b72aa

Browse files
authored
fix: Use chromedriver v2.36 as minimal version for appium:chromedriverExecutableDir usage (#56)
* fix: Use chromedriver v2.36 as minimal version for appium:chromedriverExecutableDir usage * docs: update readme
1 parent 3123820 commit 33b72aa

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ package in your `package.json`)
3737
|`appium:app`|[Optional] An absolute path to your `.ipk` app file, if you want Appium to install the app.|
3838
|`appium:debuggerPort`|[Optional; default `9998`] The port on the device exposed for remote Chromium debugging.|
3939
|`appium:chromedriverExecutable`(*)|[Optional] Most LG 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.|
40-
| `appium:chromedriverExecutableDir`(*) | [Optional] 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. |
40+
| `appium:chromedriverExecutableDir`(*) | [Optional] 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. |
4141
|`appium:websocketPort`|[Optional; default `3000`] The websocket port on the device exposed for remote control|
4242
|`appium:websocketPortSecure`|[Optional; default `3001`] The secure websocket port on the device exposed for remote control|
4343
|`appium:useSecureWebsocket`|[Optional; default `false`] Flag that enables use of `websocketPortSecure` port, also starts WebSocket over https instead. **DISCLAIMER** Enabling this flag, it is required to set environment variable `export NODE_TLS_REJECT_UNAUTHORIZED=0`, which can be a potential security risk. A new session request might get `unable to get local issuer certificate` error message.|

lib/driver.js

+42-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ const CHROMEDRIVER_AUTODOWNLOAD_FEATURE = 'chromedriver_autodownload';
3737
*/
3838
const REGEXP_CHROME_VERSION_IN_UA = new RegExp('Chrome\\/(\\S+)');
3939

40+
/**
41+
* To get chrome version from the browser info.
42+
*/
43+
const VERSION_PATTERN = /([\d.]+)/;
44+
45+
/**
46+
* Minimal chrome browser for autodownload.
47+
* Chromedriver for older than this chrome version could have an issue
48+
* to raise no chrome binary error.
49+
*/
50+
const MIN_CHROME_MAJOR_VERSION = 63;
51+
const MIN_CHROME_VERSION = 'Chrome/63.0.3239.0';
52+
4053
// don't proxy any 'appium' routes
4154
/** @type {RouteMatcher[]} */
4255
const NO_PROXY = [
@@ -206,9 +219,9 @@ export class WebOSDriver extends BaseDriver {
206219
* @property {string} Browser
207220
* @property {string} Protocol-Version
208221
* @property {string} User-Agent
209-
* @property {string} V8-Version
222+
* @property {string} [V8-Version]
210223
* @property {string} WebKit-Version
211-
* @property {string} webSocketDebuggerUrl
224+
* @property {string} [webSocketDebuggerUrl]
212225
*/
213226

214227
/**
@@ -238,6 +251,32 @@ export class WebOSDriver extends BaseDriver {
238251
return browserVersionInfo;
239252
}
240253

254+
/**
255+
* Set chrome version v63.0.3239.0 as the minimal version
256+
* for autodownload to use proper chromedriver version.
257+
* Older than the chromedriver version could raise no Chrome binary found error,
258+
* which no makes sense for TV automation usage.
259+
*
260+
* @param {BrowserVersionInfo} browserVersionInfo
261+
* @return {BrowserVersionInfo}
262+
*/
263+
fixChromeVersionForAutodownload(browserVersionInfo) {
264+
const chromeVersion = VERSION_PATTERN.exec(browserVersionInfo.Browser ?? '');
265+
if (!chromeVersion) {
266+
return browserVersionInfo;
267+
}
268+
269+
const majorV = chromeVersion[1].split('.')[0];
270+
if (_.toInteger(majorV) < MIN_CHROME_MAJOR_VERSION) {
271+
log.info(`The device chrome version is ${chromeVersion[1]}, ` +
272+
`which could cause an issue for the matched chromedriver version. ` +
273+
`Setting ${MIN_CHROME_VERSION} as browser forcefully`);
274+
browserVersionInfo.Browser = MIN_CHROME_VERSION;
275+
}
276+
277+
return browserVersionInfo;
278+
}
279+
241280
/**
242281
* Returns whether the session can enable autodownloadd feature.
243282
* @returns {boolean}
@@ -267,6 +306,7 @@ export class WebOSDriver extends BaseDriver {
267306
result = await got.get(`http://${debuggerAddress}/json/version`).json();
268307
log.info(`The response of http://${debuggerAddress}/json/version was ${JSON.stringify(result)}`);
269308
result = this.useUAForBrowserIfNotPresent(result);
309+
result = this.fixChromeVersionForAutodownload(result);
270310

271311
// To respect the executableDir.
272312
executable = undefined;

test/unit/driver.spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,50 @@ describe('WebOSDriver', function () {
115115
});
116116
});
117117
});
118+
119+
describe('fixChromeVersionForAutodownload', function () {
120+
it('Set minimal chrome version', function () {
121+
const driver = new WebOSDriver();
122+
const browserInfo = {
123+
'Browser': 'Chrome/62.0.4280.88',
124+
'Protocol-Version': '1.3',
125+
'User-Agent': 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.4280.88 Safari/537.36',
126+
'WebKit-Version': '537.36 (@cec52f3dd4465dd7389298b97ab723856c556bd)',
127+
};
128+
driver.fixChromeVersionForAutodownload(browserInfo).should.eql(
129+
{
130+
'Browser': 'Chrome/63.0.3239.0',
131+
'Protocol-Version': '1.3',
132+
'User-Agent': 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.4280.88 Safari/537.36',
133+
'WebKit-Version': '537.36 (@cec52f3dd4465dd7389298b97ab723856c556bd)',
134+
}
135+
);
136+
});
137+
138+
it('Do nothing if the given browser was empty', function () {
139+
const driver = new WebOSDriver();
140+
const browserInfo = {
141+
'Browser': '',
142+
'Protocol-Version': '1.3',
143+
'User-Agent': 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
144+
'V8-Version': '8.7.220.(29*1000 + 2)',
145+
'WebKit-Version': '537.36 (@cec52f3dd4465dd7389298b97ab723856c556bd)',
146+
'webSocketDebuggerUrl': 'ws://192.168.0.1:9998/devtools/browser/a4b3786c-2d2f-4751-9e05-aee2023bc226'
147+
};
148+
driver.fixChromeVersionForAutodownload(browserInfo).should.eql(browserInfo);
149+
});
150+
151+
it('Use the given chrome version', function () {
152+
const driver = new WebOSDriver();
153+
const browserInfo = {
154+
'Browser': 'Chrome/87.0.4280.88',
155+
'Protocol-Version': '1.3',
156+
'User-Agent': 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
157+
'V8-Version': '8.7.220.(29*1000 + 2)',
158+
'WebKit-Version': '537.36 (@cec52f3dd4465dd7389298b97ab723856c556bd)',
159+
'webSocketDebuggerUrl': 'ws://192.168.0.1:9998/devtools/browser/a4b3786c-2d2f-4751-9e05-aee2023bc226'
160+
};
161+
driver.fixChromeVersionForAutodownload(browserInfo).should.eql(browserInfo);
162+
});
163+
});
118164
});

0 commit comments

Comments
 (0)