Reputation: 1967
I have a Selenium JavaScript Webdriver test that is working as expected, giving no errors, except that a Chrome Extension that should change the title of the page, then get a cookie is not working. When I have run the extension manually on a test page it works as expected, so I am pretty sure the problem is how I'm calling the extension.
I do have one question about the "binary" chromeOption, from the docs I looked at it looked like it was just the folder that held the extension, but then those same docs had their "extensions" in chromeOption pointing at a file in the same folder. What exactly am I supposed to put in "binary"?
Code snippet:
const path = require('path');
const chromePath = require('chromedriver').path;
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const until = webdriver.until;
var chromeOptions = webdriver.Capabilities.chrome();
var service = new chrome.ServiceBuilder(chromePath).build();
chrome.setDefaultService(service);
var builder = new webdriver.Builder();
var options = new chrome.Options();
var preferences = new webdriver.logging.Preferences();
var driver;
preferences.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
options.setLoggingPrefs(preferences);
var extensionArray = [""];
async function AppTest() {
let driver = builder
.forBrowser('chrome')
.withCapabilities({
'browserName': 'chrome',
'chromeOptions':
{
binary:
// Folder containing a copy of the extension
'/Users/MyUserName/Desktop/Testing/chrome-extensions',
args: [],
// Local copy of the extension in the same folder as the test
extensions: ['./chrome-extension/extension-demo.crx']
}
})
.setChromeOptions(options)
.build();
// Tests
await driver.get('https://testURL.com');
await driver.manage().getCookie("test").then(function(cookie){
console.log("test", cookie);
});
await driver.quit();
}
Upvotes: 0
Views: 1068