Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use chromedriver v2.36 as minimal version for appium:chromedriverExecutableDir usage #591

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/appium-tizen-tv-driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<device-host>:<sdb-port>`, 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. |
Expand Down
50 changes: 50 additions & 0 deletions packages/appium-tizen-tv-driver/lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TizenTVDriverCaps, 'appLaunchCooldown' | 'rcMode'>} */
const DEFAULT_CAPS = {
appLaunchCooldown: DEFAULT_APP_LAUNCH_COOLDOWN,
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
47 changes: 44 additions & 3 deletions packages/appium-tizen-tv-driver/test/unit/driver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ describe('TizenTVDriver', function () {
});

describe('instance method', function () {
/** @type {InstanceType<TizenTVDriver>} */
let driver;

describe('setValue()', function () {
describe('when configured to use the RC', function () {
/** @type {InstanceType<TizenTVDriver>} */
let driver;

beforeEach(async function () {
driver = new TizenTVDriver();
await driver.createSession({
Expand Down Expand Up @@ -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
);
});
});
});
});