Last active
April 26, 2024 23:16
-
-
Save ckzgraphics/3a2077575522ad00dbb23b16026bb685 to your computer and use it in GitHub Desktop.
Add Chrome extension to the Chrome browser in NodeJS + Selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webdriver = require('selenium-webdriver'); | |
var chrome = require("selenium-webdriver/chrome"); | |
var fs = require('fs'); | |
let file_path = '/Users/test/Downloads/Page Ruler.crx'; | |
let buff = new Buffer.from(fs.readFileSync(file_path)); | |
let base64data = buff.toString('base64'); | |
var capabilities = { | |
'project' : 'Test Run', | |
'build' : 'Build v1', | |
'name' : 'Chrome Extensions', | |
'browserName' : 'Chrome', | |
'os' : 'Windows', | |
'os_version' : '10', | |
'browserstack.debug' : 'true', | |
'browserstack.user' : '<BROWSERSTACK_USERNAME>', | |
'browserstack.key' : '<BROWSERSTACK_ACCESS_KEY>', | |
'chromeOptions': { | |
'extensions' : [ base64data ] | |
} | |
} | |
var driver = new webdriver.Builder(). | |
usingServer('http://hub-usw.browserstack.com/wd/hub'). | |
withCapabilities(capabilities). | |
build(); | |
driver.get('https://the-internet.herokuapp.com/login').then(function(){ | |
driver.findElement(webdriver.By.xpath('.//button[@type="submit"]')).click().then(function(){ | |
driver.getTitle().then(function(title) { | |
console.log(title); | |
driver.quit(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment