mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
8f40cd8438
Update `selenium-webdriver` to v4.0.0-alpha.5. Despite the fact that this version has "alpha" in the name, the maintainer of `selenium-webdriver` has described this release as stable [1]. A few APIs were removed or changed in v4, which required changes to our Firefox webdriver. The port used for webdriver communication can now be specified manually. This was required to ensure the threebox tests kept working, because they used two different driver instances. This new version of `selenium-webdriver` now uses the same port for each instance of the webdriver (unlike the old version, which generated a new port for each one), so it was necessary to manually specify the port to prevent the same port from being used for both instances. `chromedriver` required an update, as the version we were using was not compatible with the new W3C WebDriver protocol. I've updated `geckodriver` as well, just to bring it in line with the version of Firefox we are using. [1]: https://github.com/SeleniumHQ/selenium/issues/5617#issuecomment-373446249
69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
const { Builder } = require('selenium-webdriver')
|
|
const chrome = require('selenium-webdriver/chrome')
|
|
|
|
/**
|
|
* A wrapper around a {@code WebDriver} instance exposing Chrome-specific functionality
|
|
*/
|
|
class ChromeDriver {
|
|
static async build ({ extensionPath, responsive, port }) {
|
|
const args = [
|
|
`load-extension=${extensionPath}`,
|
|
]
|
|
if (responsive) {
|
|
args.push('--auto-open-devtools-for-tabs')
|
|
}
|
|
const options = new chrome.Options()
|
|
.addArguments(args)
|
|
const builder = new Builder()
|
|
.forBrowser('chrome')
|
|
.setChromeOptions(options)
|
|
if (port) {
|
|
const service = new chrome.ServiceBuilder()
|
|
.setPort(port)
|
|
builder.setChromeService(service)
|
|
}
|
|
const driver = builder.build()
|
|
const chromeDriver = new ChromeDriver(driver)
|
|
const extensionId = await chromeDriver.getExtensionIdByName('MetaMask')
|
|
|
|
return {
|
|
driver,
|
|
extensionUrl: `chrome-extension://${extensionId}/home.html`,
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @constructor
|
|
* @param {!ThenableWebDriver} driver a {@code WebDriver} instance
|
|
*/
|
|
constructor (driver) {
|
|
this._driver = driver
|
|
}
|
|
|
|
/**
|
|
* Returns the extension ID for the given extension name
|
|
* @param {string} extensionName the extension name
|
|
* @return {Promise<string|undefined>} the extension ID
|
|
*/
|
|
async getExtensionIdByName (extensionName) {
|
|
await this._driver.get('chrome://extensions')
|
|
return await this._driver.executeScript(`
|
|
const extensions = document.querySelector("extensions-manager").shadowRoot
|
|
.querySelector("extensions-item-list").shadowRoot
|
|
.querySelectorAll("extensions-item")
|
|
|
|
for (let i = 0; i < extensions.length; i++) {
|
|
const extension = extensions[i].shadowRoot
|
|
const name = extension.querySelector('#name').textContent
|
|
if (name === "${extensionName}") {
|
|
return extensions[i].getAttribute("id")
|
|
}
|
|
}
|
|
|
|
return undefined
|
|
`)
|
|
}
|
|
}
|
|
|
|
module.exports = ChromeDriver
|