I'm currently facing an issue with my Selenium JavaScript Webdriver test. Everything seems to be working fine, no errors are being thrown. The only problem is related to a Chrome Extension that is supposed to change the title of the page and then retrieve a cookie, but it's not functioning as expected. Interestingly, when I manually run the extension on a test page, it works perfectly. This leads me to believe that the issue lies in how I am calling the extension.
My main confusion arises from the "binary" chromeOption. After reviewing the documentation, it appears that this should point to the folder containing the extension. However, in the same docs, the "extensions" in chromeOption seem to reference a file within the same folder. Could anyone clarify what exactly should be placed under "binary"?
Here is a snippet of the code:
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();
}