Tried Karma with karma-webdriver-launcher && karma-selenium-grid-launcher to launch chrome/firefox to execute tests but not able to open browser
Can someone please share working code for e2e test using selenium webdriver and karma, searched on google but not able to find complete code only snippets are there.
My karma config file ::
module.exports = function (config) {
var webdriverConfig = {
hostname: 'localhost',
port: 4444,
}
let customLaunchers = {
firefoxCustom: {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'firefox',
version:'ANY',
platform:'ANY'
},
};
config.set({
basePath: './',
frameworks: ["mocha"],
reporters: ['progress'],
plugins: [
'karma-webdriver-launcher',
'karma-selenium-grid-launcher',
'karma-mocha',
'selenium-webdriver'
],
customLaunchers: customLaunchers,
browsers: [ 'firefoxCustom'],
files: [
"tests/*.spec.js"
],
singleRun: true
});
}
test file ::
const {Builder, By, until} = require('selenium-webdriver');
(async function example() {
const driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('https://www.google.com');
await driver.findElement(By.name('q')).sendKeys('hello');
await driver.findElement(By.id('tsf')).submit();
}catch(err)
{
console.log(err)
}
finally {
await driver.quit();
}
})();
package.json
{
"name": "karmatest2",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": ""
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"chai": "^4.2.0",
"chromedriver": "^77.0.0",
"geckodriver": "^1.19.0",
"karma": "^4.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^2.0.1",
"karma-mocha": "^1.3.0",
"karma-selenium-grid-launcher": "^0.3.0",
"karma-webdriver-launcher": "^1.0.7",
"mocha": "^6.2.2",
"require": "^2.4.20",
"selenium-webdriver": "^3.6.0",
"wd": "^1.11.4"
}
}
getting error :
21 10 2019 11:53:49.329:INFO [karma-server]: Karma v4.4.1 server started at
http://0.0.0.0:9876/
21 10 2019 11:53:49.332:INFO [launcher]: Launching browsers firefoxCustom with concurrency
unlimited
21 10 2019 11:53:49.335:INFO [launcher]: Starting browser firefox via Remote WebDriver
21 10 2019 11:53:49.374:ERROR [WebDriver]: WebDriver command failed {
spec: {
platform: 'ANY',
testName: 'Karma test',
tags: [],
version: 'ANY',
base: 'WebDriver',
browserName: 'firefox'
},
error: Error: [get("http://localhost:9876/?id=18408460")] Error response status: 6 Selenium
error: No active session with ID url